seagrid.download.earthdata#
NASA Earthdata access: login, CMR granule search and authenticated downloads.
Authentication is handled by earthaccess, which reads ~/.netrc
(machine urs.earthdata.nasa.gov login USER password PASS) or the
environment variables EARTHDATA_USERNAME and EARTHDATA_PASSWORD.
Downloads go through seagrid.download.http.fetch() with an
authenticated session.
The functions download(), retrieve_file(),
download_granule(), get_granules_list() and filename() are
the 2.x interface used by the ocean-colour sources.
Functions
|
Find an OB.DAAC L3 mapped file in CMR and download it to datadir. |
|
Download a granule from a direct URL. |
|
Return True if a granule called name is listed in CMR. |
|
Download url with an Earthdata-authenticated session. |
|
Return a standard OB.DAAC L3 mapped file name. |
|
Search NASA Earthdata for granules in a time range and bounding box. |
|
Authenticate with NASA Earthdata. |
|
Download a file by name from the OB.DAAC |
|
Search NASA CMR for granules of a collection. |
|
Return an HTTPS session authenticated with NASA Earthdata. |
- seagrid.download.earthdata.download(dtm='2010-01-01', timetype='mo', data_var='par', res='4km', download_timeout=30, datadir='./', sensor='MODIS', verbose=False)[source]#
Find an OB.DAAC L3 mapped file in CMR and download it to datadir.
Skips the download if the file already exists.
- Parameters:
dtm (
strordatetime-like) – Date of the file.timetype (
str) –"mo","DAY","8D", … (anyseagrid.timetypesalias).data_var (
str) – Variable name, e.g."par","chlor_a".res (
str) – Spatial resolution, e.g."4km".download_timeout (
float) – Unused; kept for compatibility.datadir (
stroros.PathLike) – Local directory for the downloaded file.sensor (
str) – Sensor name. Default"MODIS".verbose (
bool) – Print status information.
- Raises:
ValueError – If data_var or sensor has no known CMR collection.
FileNotFoundError – If no matching granule is found.
- Return type:
None
- seagrid.download.earthdata.download_granule(file_url, datadir='./', download_timeout=30, replace=False, verbose=False)[source]#
Download a granule from a direct URL.
- Parameters:
- Returns:
pathlib.Path– The local file.- Raises:
DownloadError – On a failed download.
- Return type:
- seagrid.download.earthdata.exists(short_name, name, start, end=None)[source]#
Return True if a granule called name is listed in CMR.
- Parameters:
short_name (
str) – CMR collection short name.name (
str) – File name of the granule.start (
str,pandas.Timestamp,numpy.datetime64ordatetime) – Temporal range to search.end (
str,pandas.Timestamp,numpy.datetime64ordatetime) – Temporal range to search.
- Returns:
- Return type:
- seagrid.download.earthdata.fetch(url, dest, **kwargs)[source]#
Download url with an Earthdata-authenticated session.
- Parameters:
url (
str) – URL of the file.dest (
stroros.PathLike) – Target file or directory (seeseagrid.download.http.fetch()).**kwargs – Passed to
seagrid.download.http.fetch().
- Returns:
pathlib.Path– The downloaded file.- Return type:
- seagrid.download.earthdata.filename(dtm='2001-01-01', timetype='DAY', data_var='chlor_a', res='4km', sensor='MODIS')[source]#
Return a standard OB.DAAC L3 mapped file name.
- seagrid.download.earthdata.get_granules_list(short_name='MODISA_L2_SST', dtm1='2020-01-01', dtm2='2020-12-31', lat1=-10, lat2=10, lon1=-10, lon2=10, fileurl=True, **params_kw)[source]#
Search NASA Earthdata for granules in a time range and bounding box.
- Parameters:
short_name (
str) – CMR collection short name.dtm1 (
strordatetime-like) – Start and end dates.dtm2 (
strordatetime-like) – Start and end dates.lat1 (
float) – Southern and northern latitude of the bounding box.lat2 (
float) – Southern and northern latitude of the bounding box.lon1 (
float) – Western and eastern longitude of the bounding box.lon2 (
float) – Western and eastern longitude of the bounding box.fileurl (
bool) – Return download URLs when True, file names when False.**params_kw – Passed to
earthaccess.search_data().
- Returns:
- Return type:
- seagrid.download.earthdata.login(**kwargs)[source]#
Authenticate with NASA Earthdata.
Tries
~/.netrcfirst, then environment variables, then an interactive prompt. Calling this is optional: the download functions log in when needed.
- seagrid.download.earthdata.retrieve_file(filename, datadir='./', download_timeout=30, verbose=False)[source]#
Download a file by name from the OB.DAAC
getfileservice.- Parameters:
filename (
str) – Name of the remote file.datadir (
stroros.PathLike) – Local directory for the downloaded file.download_timeout (
float) – Seconds to wait for the server.verbose (
bool) – Print the URL.
- Returns:
pathlib.Path– The downloaded file.- Raises:
DownloadError – On a failed download.
- Return type:
- seagrid.download.earthdata.search(short_name, start, end=None, *, bbox=None, **params)[source]#
Search NASA CMR for granules of a collection.
- Parameters:
short_name (
str) – CMR collection short name, e.g."MODISA_L3m_CHL".start (
str,pandas.Timestamp,numpy.datetime64ordatetime) – Temporal range (inclusive). Default end: start.end (
str,pandas.Timestamp,numpy.datetime64ordatetime) – Temporal range (inclusive). Default end: start.bbox (
(west,south,east,north), optional) – Spatial filter in degrees.**params – Passed to
earthaccess.search_data()(e.g.count).
- Returns:
listofearthaccess.DataGranule- Return type:
- seagrid.download.earthdata.session()[source]#
Return an HTTPS session authenticated with NASA Earthdata.
- Returns:
requests.Session- Raises:
AuthenticationError – If no Earthdata credentials are available.
- Return type:
Session