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
|
Return the Copernicus Marine credentials to use. |
|
Return True if a dataset has files matching a filter (no download). |
|
Download the file of one date, as configured in a source's settings. |
|
Download the original files of a dataset that match a filter. |
|
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.
- 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 inget_files().regex (
str, optional) – File-name pattern, as inget_files().dataset_version (
str, optional) – Dataset version.username (
str, optional) – Credentials.password (
str, optional) – Credentials.
- Returns:
- Raises:
DownloadError – If the catalogue cannot be queried.
- Return type:
- 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 (
strordatetime-like) – Date of the file.settings (
mapping) – Source settings withdataset_id,datadirandfile_filter(astrftime()format), and optionallyusername/password.**kw – Overrides for any of these keys.
- Returns:
listofpathlib.Path– The downloaded files.- Raises:
DownloadError – If no file was found on the server.
- Return type:
- 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 (
stroros.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; seecredentials().password (
str, optional) – Credentials; seecredentials().force (
bool, optional) – Download again files that already exist. Default False.progress (
bool, optional) – Show the copernicusmarine progress bar. Default False.
- Returns:
listofpathlib.Path– The local files, including ones that were already present.- Raises:
DownloadError – If no file matches, or the request fails.
- Return type:
- 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>.partialand moved to dest when complete.- Parameters:
dataset_id (
str) – Copernicus Marine dataset ID.dest (
stroros.PathLike) – Output file. A.zarrsuffix writes a Zarr store, anything else netCDF.variables (
sequenceofstr, optional) – Variables to include. Default: all.start (
str,pandas.Timestamp,numpy.datetime64ordatetime, optional) – Time range. Default end: start.end (
str,pandas.Timestamp,numpy.datetime64ordatetime, 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) – Seecopernicusmarine.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: