This article talks about how to download ocean data from NASA using wget.
The contents mainly refer to NASA’s official website here: https://disc.gsfc.nasa.gov/data-access.
First, please refer to the official website to apply an Earthdata account. Here I describe an example to download multiple ocean data only.
Second, configure wget following instructions provided by formal website as well. Here is a short summary (for Linux/Mac only):
- Create a
.netrc file in your home directory with following contents:
machine urs.earthdata.nasa.gov login <uid> password <password>(without <>)
- Give permission to this file:
chmod 0600 .netrc
- Create a blank cookie file in home directory named
Third, taking downloading “Aquarius Official Release Level 3 Rain-flagged Sea Surface Salinity Standard Mapped Image Descending Daily Data V5.0” data for the whole 2012 for example.
To start, find the “Data Access” section and go to ‘OPENDAP’ method to reach the data location. Select ‘2012’ and further go to ‘001’ directory, we’ll see several different files that in this folder, actually they are different data but have the same logical data structure, so they are arranged in the same directory. What we are looking for is “RAIN_MASK_SSS” data, so we click the corresponding link and reach the location of this file.
Just copy the content in DATA URL line and we will obtain the url for this file.
You can of course download this file directly via clicking “Get as NetCDF-4” button, but you can also use a cooler method to download it using this url in a command terminal by typing:
wget --load-cookies ~/.urs_cookies --save-cookies ~/.urs_cookies --auth-no-challenge=on --keep-session-cookies --content-disposition https://podaac-opendap.jpl.nasa.gov:443/opendap/allData/aquarius/L3/mapped/V5/daily/SCID/2012/001/Q2012001.L3m_DAY_SCID_V5.0.RAIN_MASK_SSS_1deg.bz2
This cooler method makes it possible for us to download multiple files at once.
So the next question is how to obtain the multiple url for files we’re interested in. By observing the naming rules of the file, we can use a MATLAB script to make it. Here is a sample MATLAB script to make it.
% this file is to generate a file that contains all url for the data downloading
% using following command to download all files listed in the url list:
year = '2012';
date = 1:1:366;
% Descending files
prefix_name = 'https://podaac-opendap.jpl.nasa.gov:443/opendap/allData/aquarius/L3/mapped/V5/daily/SCID/';
suffix_name = '.L3m_DAY_SCID_V5.0.RAIN_MASK_SSS_1deg.bz2';
fi = fopen(['Descending_sss_url_',year,'.txt'],'w');
for i = 1:length(date)
day = num2str(date(i),'%03d');
url = [prefix_name,year,'/',day,'/Q',year,day,suffix_name];
Finally, it cannot be easier for us any more, just type following command in the terminal in your preferred directory:
wget --load-cookies ~/.urs_cookies --save-cookies ~/.urs_cookies --auth-no-challenge=on --keep-session-cookies --content-disposition -i Descending_sss_url_2012.txt