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

download([dtm, timetype, data_var, res, ...])

Find an OB.DAAC L3 mapped file in CMR and download it to datadir.

download_granule(file_url[, datadir, ...])

Download a granule from a direct URL.

exists(short_name, name, start[, end])

Return True if a granule called name is listed in CMR.

fetch(url, dest, **kwargs)

Download url with an Earthdata-authenticated session.

filename([dtm, timetype, data_var, res, sensor])

Return a standard OB.DAAC L3 mapped file name.

get_granules_list([short_name, dtm1, dtm2, ...])

Search NASA Earthdata for granules in a time range and bounding box.

login(**kwargs)

Authenticate with NASA Earthdata.

retrieve_file(filename[, datadir, ...])

Download a file by name from the OB.DAAC getfile service.

search(short_name, start[, end, bbox])

Search NASA CMR for granules of a collection.

session()

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 (str or datetime-like) – Date of the file.

  • timetype (str) – "mo", "DAY", "8D", … (any seagrid.timetypes alias).

  • 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 (str or os.PathLike) – Local directory for the downloaded file.

  • sensor (str) – Sensor name. Default "MODIS".

  • verbose (bool) – Print status information.

Raises:
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:
  • file_url (str) – URL of the granule.

  • datadir (str or os.PathLike) – Local directory for the downloaded file.

  • download_timeout (float) – Seconds to wait for the server.

  • replace (bool) – Download even if the local file exists.

  • verbose (bool) – Print the file name.

Returns:

pathlib.Path – The local file.

Raises:

DownloadError – On a failed download.

Return type:

Path

seagrid.download.earthdata.exists(short_name, name, start, end=None)[source]#

Return True if a granule called name is listed in CMR.

Parameters:
Returns:

bool

Return type:

bool

seagrid.download.earthdata.fetch(url, dest, **kwargs)[source]#

Download url with an Earthdata-authenticated session.

Parameters:
Returns:

pathlib.Path – The downloaded file.

Return type:

Path

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.

See seagrid.download.obpg.filename().

Parameters:
  • dtm (str or datetime-like) – Date in the period.

  • timetype (str) – "DAY", "8D", "mo", … (any seagrid.timetypes alias).

  • data_var (str) – Variable name.

  • res (str) – Spatial resolution, e.g. "4km".

  • sensor (str) – Sensor name, e.g. "MODIS".

Returns:

str

Return type:

str

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 (str or datetime-like) – Start and end dates.

  • dtm2 (str or datetime-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:

list of str

Return type:

Sequence[str]

seagrid.download.earthdata.login(**kwargs)[source]#

Authenticate with NASA Earthdata.

Tries ~/.netrc first, then environment variables, then an interactive prompt. Calling this is optional: the download functions log in when needed.

Parameters:

**kwargs (Any) – Passed to earthaccess.login().

Returns:

earthaccess.Auth

Return type:

Any

seagrid.download.earthdata.retrieve_file(filename, datadir='./', download_timeout=30, verbose=False)[source]#

Download a file by name from the OB.DAAC getfile service.

Parameters:
  • filename (str) – Name of the remote file.

  • datadir (str or os.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:

Path

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.datetime64 or datetime) – Temporal range (inclusive). Default end: start.

  • end (str, pandas.Timestamp, numpy.datetime64 or datetime) – 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:

list of earthaccess.DataGranule

Return type:

list[Any]

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