seagrid.download.copernicus#

Copernicus Marine Data Store access through copernicusmarine.

Two ways to get data:

  • get_files() downloads original files whose names match a filter (copernicusmarine.get), e.g. one OSTIA file per day.

  • subset() downloads a spatial/temporal/variable subset of a dataset to one netCDF file or Zarr store (copernicusmarine.subset).

Credentials come from the username/password arguments, then a source’s settings (from a .secrets.toml), and finally the login that copernicusmarine login stores or the COPERNICUSMARINE_SERVICE_USERNAME and COPERNICUSMARINE_SERVICE_PASSWORD environment variables.

Functions

credentials([settings, username, password])

Return the Copernicus Marine credentials to use.

exists(dataset_id, *[, filter, regex, ...])

Return True if a dataset has files matching a filter (no download).

get(dtm, settings, **kw)

Download the file of one date, as configured in a source's settings.

get_files(dataset_id, dest_dir, *[, filter, ...])

Download the original files of a dataset that match a filter.

subset(dataset_id, dest, *[, variables, ...])

Download a subset of a dataset to one netCDF file or Zarr store.

seagrid.download.copernicus.credentials(settings=None, username=None, password=None)[source]#

Return the Copernicus Marine credentials to use.

Parameters:
  • settings (mapping, optional) – A source’s settings; its username/password keys are used when the arguments are not given.

  • username (str, optional) – Explicit credentials.

  • password (str, optional) – Explicit credentials.

Returns:

username, password (str or None) – None lets copernicusmarine use its own stored login.

Return type:

tuple[str | None, str | None]

seagrid.download.copernicus.exists(dataset_id, *, filter=None, regex=None, dataset_version=None, username=None, password=None)[source]#

Return True if a dataset has files matching a filter (no download).

Parameters:
  • dataset_id (str) – Copernicus Marine dataset ID.

  • filter (str, optional) – File-name pattern, as in get_files().

  • regex (str, optional) – File-name pattern, as in get_files().

  • dataset_version (str, optional) – Dataset version.

  • username (str, optional) – Credentials.

  • password (str, optional) – Credentials.

Returns:

bool

Raises:

DownloadError – If the catalogue cannot be queried.

Return type:

bool

seagrid.download.copernicus.get(dtm, settings, **kw)[source]#

Download the file of one date, as configured in a source’s settings.

This is the 2.x interface used by the OSTIA, SMOC and CMEMS sources.

Parameters:
  • dtm (str or datetime-like) – Date of the file.

  • settings (mapping) – Source settings with dataset_id, datadir and file_filter (a strftime() format), and optionally username/password.

  • **kw – Overrides for any of these keys.

Returns:

list of pathlib.Path – The downloaded files.

Raises:

DownloadError – If no file was found on the server.

Return type:

list[Path]

seagrid.download.copernicus.get_files(dataset_id, dest_dir, *, filter=None, regex=None, dataset_version=None, username=None, password=None, force=False, progress=False)[source]#

Download the original files of a dataset that match a filter.

Parameters:
  • dataset_id (str) – Copernicus Marine dataset ID.

  • dest_dir (str or os.PathLike) – Directory to save the files in (flat, without the server’s sub-directories). Created if missing.

  • filter (str, optional) – Glob pattern on the file names, e.g. "*20100101*".

  • regex (str, optional) – Regular expression on the file names.

  • dataset_version (str, optional) – Dataset version. Default: the latest.

  • username (str, optional) – Credentials; see credentials().

  • password (str, optional) – Credentials; see credentials().

  • force (bool, optional) – Download again files that already exist. Default False.

  • progress (bool, optional) – Show the copernicusmarine progress bar. Default False.

Returns:

list of pathlib.Path – The local files, including ones that were already present.

Raises:

DownloadError – If no file matches, or the request fails.

Return type:

list[Path]

seagrid.download.copernicus.subset(dataset_id, dest, *, variables=None, start=None, end=None, lat_bounds=None, lon_bounds=None, depth_bounds=None, dataset_version=None, coordinates_selection_method='inside', username=None, password=None, force=False, progress=False)[source]#

Download a subset of a dataset to one netCDF file or Zarr store.

The output is written to <dest>.partial and moved to dest when complete.

Parameters:
  • dataset_id (str) – Copernicus Marine dataset ID.

  • dest (str or os.PathLike) – Output file. A .zarr suffix writes a Zarr store, anything else netCDF.

  • variables (sequence of str, optional) – Variables to include. Default: all.

  • start (str, pandas.Timestamp, numpy.datetime64 or datetime, optional) – Time range. Default end: start.

  • end (str, pandas.Timestamp, numpy.datetime64 or datetime, optional) – Time range. Default end: start.

  • lat_bounds ((float, float), optional) – Spatial ranges. Default: the whole dataset.

  • lon_bounds ((float, float), optional) – Spatial ranges. Default: the whole dataset.

  • depth_bounds ((float, float), optional) – Spatial ranges. Default: the whole dataset.

  • dataset_version (str, optional) – Dataset version.

  • coordinates_selection_method (str, optional) – See copernicusmarine.subset(). Default "inside".

  • username (str, optional) – Credentials.

  • password (str, optional) – Credentials.

  • force (bool, optional) – Download even if dest is complete. Default False.

  • progress (bool, optional) – Show the copernicusmarine progress bar.

Returns:

pathlib.Path – dest.

Raises:

DownloadError – If the request fails or writes nothing.

Return type:

Path