seagrid.sources.families#

Intermediate source classes for each kind of data provider.

Class

Used for

OBPGSource

NASA OB.DAAC L3 mapped ocean colour (MODIS, VIIRS, SeaWiFS, OLCI), downloaded with Earthdata login

CopernicusSource

Copernicus Marine original files (OSTIA, SMOC, …)

OpendapSource

THREDDS/Hyrax OPeNDAP datasets cached locally

HTTPSource

Plain HTTP(S) servers with URL templates

EarthdataSource

NASA Earthdata archives (PO.DAAC) with URL templates

LocalSource

Files on a local or mounted disk (no download)

Functions

date_fields(dtm)

Return the fields available to URL and file-name templates.

template_fields(dtm, *[, data_var, timetype])

Return the fields of URL, directory and file-name templates.

Classes

CopernicusSource([variant])

Copernicus Marine products, as original files or as subsets.

EarthdataSource([variant])

Files in a NASA Earthdata archive (PO.DAAC, ...), located by templates.

HTTPSource([variant])

Files on a plain HTTP(S) server, located by URL templates.

LocalSource([variant])

Files on a local or mounted disk, located by templates; no download.

OBPGSource([variant])

NASA OB.DAAC Level-3 mapped products, one variable per file.

OpendapSource([variant])

Datasets read over OPeNDAP and cached locally as netCDF or Zarr.

class seagrid.sources.families.CopernicusSource(variant=None, **overrides)[source]#

Bases: DataSource

Copernicus Marine products, as original files or as subsets.

Settings:

dataset_id, dataset_version (optional)

The dataset.

filestamp

Local file-name template with {dtm}.

filestamp_format

strftime() format for {dtm}, default %Y%m%d.

file_filter

strftime format of the server-side file filter, default filestamp_format. It may contain wildcards, e.g. "SMOC_%Y%m%d_R*" for files whose names include a run date; the matching server file is then stored under the filestamp name.

method

"files" (the default: download original files) or "subset" (write one Zarr store per time step with seagrid.download.copernicus.subset(), using data_vars and depth_bounds).

username, password

Optional, in .secrets.toml; default the copernicusmarine login credentials.

Any of dataset_id, dataset_version, filestamp_format and file_filter may be a table keyed by time type, for products with a separate dataset per time type:

dataset_id = { daily = "..._P1D-m", monthly = "..._P1M-m" }
Parameters:
  • variant (str | None)

  • overrides (Any)

class seagrid.sources.families.EarthdataSource(variant=None, **overrides)[source]#

Bases: HTTPSource

Files in a NASA Earthdata archive (PO.DAAC, …), located by templates.

As HTTPSource, but downloads with an Earthdata login (~/.netrc or EARTHDATA_USERNAME/EARTHDATA_PASSWORD) and checks availability in CMR. Extra setting: short_name, the CMR collection (e.g. "MUR25-JPL-L4-GLOB-v04.2").

Parameters:
  • variant (str | None)

  • overrides (Any)

class seagrid.sources.families.HTTPSource(variant=None, **overrides)[source]#

Bases: DataSource

Files on a plain HTTP(S) server, located by URL templates.

Settings: host, remotedir and filename, formatted with template_fields() (e.g. "/sst/{year}/{day_of_year:03}").

If archive is set, the server has a ZIP archive of that name (also a template) in remotedir; it is downloaded, extracted into the data directory and removed, and filename names the extracted member to open (e.g. one month of a climatology).

Parameters:
  • variant (str | None)

  • overrides (Any)

class seagrid.sources.families.OBPGSource(variant=None, **overrides)[source]#

Bases: DataSource

NASA OB.DAAC Level-3 mapped products, one variable per file.

Files are named by seagrid.download.obpg.filename() and downloaded from the OB.DAAC getfile service with an Earthdata login. Each resolution is kept in its own sub-directory of datadir.

Settings: sensor, resolutions, timetypes, data_vars, clim_years (for climatologies), nrt.

Parameters:
  • variant (str | None)

  • overrides (Any)

datadir(timetype=None, resolution=None)[source]#

Return datadir/<resolution> (the 2.x layout), not created.

Parameters:
  • timetype (str | None)

  • resolution (str | None)

Return type:

Path

class seagrid.sources.families.LocalSource(variant=None, **overrides)[source]#

Bases: DataSource

Files on a local or mounted disk, located by templates; no download.

Settings: datadir and filename, formatted with template_fields() ({year}, {month:02}, {timetype}, {data_var}, …). filename may contain * and ? wildcards; exactly one file must match. check_remote() reports whether the file exists, and a missing file raises FileNotFoundError naming the path.

Parameters:
  • variant (str | None)

  • overrides (Any)

local_path(dtm=None, data_var=None, *, timetype=None, resolution=None)[source]#

Return the path of the file of one time step (templated datadir).

Parameters:
Return type:

Path

datadir(timetype=None, resolution=None)[source]#

Return the fixed part of datadir (before the first template field).

Parameters:
  • timetype (str | None)

  • resolution (str | None)

Return type:

Path

geodir()[source]#

Return <basedatadir>/geo/<source>: the data disk may be read-only.

Return type:

Path

download(dtm=None, data_var=None, *, timetype=None, resolution=None, force=False)[source]#

Return the local file; local sources have nothing to download.

Raises:

FileNotFoundError – If the file is not there.

Parameters:
Return type:

Path

class seagrid.sources.families.OpendapSource(variant=None, **overrides)[source]#

Bases: DataSource

Datasets read over OPeNDAP and cached locally as netCDF or Zarr.

Subclasses implement _remote_url(). Settings: opendap_engine ("netcdf4", the default, or "pydap").

Parameters:
  • variant (str | None)

  • overrides (Any)

seagrid.sources.families.date_fields(dtm)[source]#

Return the fields available to URL and file-name templates.

Parameters:

dtm (pandas.Timestamp) – The time step.

Returns:

dict – dtm (the timestamp, usable as {dtm:%Y%m%d}), year, month, day, hour, day_of_year (ints) and yyyymmdd.

Return type:

dict[str, Any]

Examples

>>> "{year}/{day_of_year:03}".format(**date_fields(pd.Timestamp("2020-02-01")))
'2020/032'
seagrid.sources.families.template_fields(dtm, *, data_var=None, timetype=None)[source]#

Return the fields of URL, directory and file-name templates.

Parameters:
Returns:

dict – The date_fields() plus data_var and timetype (empty strings when not given).

Return type:

dict[str, Any]

Examples

>>> f = template_fields(pd.Timestamp("2020-02-01"), timetype="monthly")
>>> "{timetype}/{year}{month:02}".format(**f)
'monthly/202002'