Skip to main content

No project description provided

Project description

Copernicus Marine Service client (CLI & Python)

PyPI PyPI Supported Versions Supported Platforms

Copernicus Marine Service and Mercator Ocean international logos

Features

The copernicus-marine-client offers capabilities through both Command Line Interface (CLI) and Python API:

  • Metadata Information: List and retrieve metadata information on all variables, datasets, products, and their associated documentation.
  • Subset Datasets: Subset datasets to extract only the parts of interest, in preferred format, such as Analysis-Ready Cloud-Optimized (ARCO) Zarr or NetCDF file format.
  • Advanced Filters: Apply simple or advanced filters to get multiple files, in original formats like NetCDF/GeoTIFF, via direct Marine Data Store connections.
  • No Quotas: Enjoy no quotas, neither on volume size nor bandwidth.

Installation

For installation, multiple options are available depending on your setup:

Conda|Mamba

Though no conda package has been created yet, these steps cover the installation in a new isolated environment (safer). Replace conda by mamba if necessary.

  • Create the file copernicus-marine-client-env.yml that contains:
name: cmc
channels:
  - conda-forge
dependencies:
  - python>=3.9,<3.12
  - pip
  - pip:
    - copernicus-marine-client
  • Use the terminal or a [Conda|Mamba] Prompt to create the cmc environment from the yml file:
conda env create --file copernicus-marine-client-env.yml
  • Open the new cmc environment by running:
conda activate cmc
  • Verify that the new cmc environment was installed correctly:
conda env list

Pip

Otherwise, if you already have an environment (safer to clone it), the package can be installed using the pip command:

python -m pip install copernicus-marine-client

And to upgrade the package to the newest available version, run:

python -m pip install copernicus-marine-client --upgrade

User Guide

For more comprehensive details on how to use the copernicus-marine-client, please refer to our Help Center. It ensures a smooth migration for existing users of legacy services such as MOTU, OPeNDAP, and FTP.

General configuration

Cache Usage

Cachier library is used for caching part of the requests (as describe result or login). By default, the cache will be located in the home folder. If you need to change the location of the cache, you can set the environment variable COPERNICUS_MARINE_CLIENT_CACHE_DIRECTORY to point to the desired directory.

Command Line Interface (CLI)

The --help option

To discover commands and their available options, consider appending --help on any command line.

Example:

copernicus-marine --help

Returns:

Usage: copernicus-marine [OPTIONS] COMMAND [ARGS]...

Options:
  -V, --version  Show the version and exit.
  --help         Show this message and exit.

Commands:
  describe  Print Copernicus Marine catalog as JSON
  login     This command check the copernicus-marine credentials provided...
  get       Download originally produced data files
  subset    Downloads subsets of datasets as NetCDF files or Zarr stores

Command describe

Retrieve metadata information about all products/datasets and display as JSON output:

copernicus-marine describe --include-datasets

The JSON output can also be saved like follows:

copernicus-marine describe --include-datasets > all_datasets_copernicus-marine.json

Command login

Create a single configuration file .copernicus-marine-credentials allowing to access all Marine Data Store data services. By default, it saves file in user's home directory.

Example:

> copernicus-marine login
username : johndoe
password :
INFO - Configuration files stored in /Users/foo/.copernicus-marine-client

If .copernicus-marine-credentials already exists, the user is asked for confirmation to overwrite (--overwrite/--overwrite-configuration-file).

Access points migration and evolution

If you already have a configuration for current services (e.g. ~/motuclient/motuclient-python.ini, ~/.netrc or ~/_netrc) in your home directory, it will automatically be taken into account with commands get and subset without the need for running the login command. If the configuration files are already available in another directory, when running commands subset or get, you can use the --credentials-file option to point to the file.

Command subset

Remotely subset a dataset, based on variable names, geographical and temporal parameters.

Example:

copernicus-marine subset --dataset-id cmems_mod_ibi_phy_my_0.083deg-3D_P1Y-m --variable thetao --variable so --start-datetime 2021-01-01 --end-datetime 2021-01-03 --minimum-longitude 0.0 --maximum-longitude 0.1 --minimum-latitude 28.0 --maximum-latitude 28.1

Returns:

INFO     - Download through S3
<xarray.Dataset>
Dimensions:    (depth: 50, latitude: 2, longitude: 1, time: 1)
Coordinates:
  * depth      (depth) float32 0.5058 1.556 2.668 ... 5.292e+03 5.698e+03
  * latitude   (latitude) float32 28.0 28.08
  * longitude  (longitude) float32 0.08333
  * time       (time) datetime64[ns] 2021-01-01
Data variables:
    thetao     (time, depth, latitude, longitude) float32 dask.array<chunksize=(1, 50, 2, 1), meta=np.ndarray>
    so         (time, depth, latitude, longitude) float32 dask.array<chunksize=(1, 50, 2, 1), meta=np.ndarray>
Attributes: (12/19)
    Conventions:    CF-1.0
    bulletin_date:  2022-11-01
    ...             ...
    title:          CMEMS IBI REANALYSIS: YEARLY PHYSICAL PRODUCTS
Do you want to proceed with download? [Y/n]:

By default, after the display of the summary of the dataset subset, a download confirmation is asked. To skip this user's action, call option --force-download.

Note about longitude range

Options --minimum-longitude and --maximum-longitude work as follows:

  • If the result of the substraction ( --maximum-longitude minus --minimum-longitude ) is superior or equal to 360, then return the full dataset.
  • If the requested longitude range:
    • does not cross the antemeridian, then return the dataset between range -180° and 180°.
    • does cross the antemeridian, then return the dataset between range 0° and 360°.

Note that you can request any longitudes you want. A modulus is applied to bring the result between -180° and 360°. For example, if you request [530°, 560°], the result dataset will be in [170°, 200°].

Access point migration and evolution

The copernicus marine client will download the data in the most efficient way according to your request:

  • if the target dataset is available in ARCO version, then files are downloaded in a fresh new folder in the current working directory.
  • if the target dataset is not yet available in ARCO version, then a file is downloaded in the current working directory.

NOTE: The filename will be with the following format dataset_id-longitude_range-latitude_range-depth_range-date_range.[nc|zarr]

However, the output directory and filename can be specified using -o/--output-directory and -f/--output-filename respectively. If the later ends with .nc, it will be written as a NetCDF file.

You can force the use of a specific data access service with option --force-service.

Command get

Download the dataset file(s) as originally produced, based on the datasetID or the path to files.

Example:

copernicus-marine get --dataset-url ftp://my.cmems-du.eu/Core/IBI_MULTIYEAR_PHY_005_002/cmems_mod_ibi_phy_my_0.083deg-3D_P1Y-m --force-service original-files

Returns:

INFO     - You forced selection of service: original-files
INFO     - Downloading using service original-files...
INFO     - You requested the download of the following files:
s3://mdl-native/native/IBI_MULTIYEAR_PHY_005_002/cmems_mod_ibi_phy_my_0.083deg-3D_P1Y-m_202211/CMEMS_v5r1_IBI_PHY_MY_NL_01yav_19930101_19931231_R20221101_RE01.nc - 8.83 MB
[... truncated for brevity..]
s3://mdl-native/native/IBI_MULTIYEAR_PHY_005_002/cmems_mod_ibi_phy_my_0.083deg-3D_P1Y-m_202211/CMEMS_v5r1_IBI_PHY_MY_NL_01yav_20120101_20121231_R20221101_RE01.nc - 8.62 MB
Printed 20 out of 29 files

Total size of the download: 252.94 MB

Do you want to proceed with download? [Y/n]

You can force the use of a specific data access service with option --force-service.

By default:

  • after the header displays a summary of the request, a download confirmation is asked. To skip this user's action, add option --force-download.
  • files are downloaded to the current directory applying the original folder structure. To avoid this behavior, add --no-directories and specify a destination with the --output-directory option.

Option --show-outputnames displays the full paths of the output files, if required.

Note about sync option

Option --sync allows to download original files only if not exist and not up to date. The toolbox checks the destination folder against the source folder. It can be combined with filters. Note that if set with --overwrite-output-data, the latter will be ignored. The logic is largely inspired from s5mp package sync command Limitations:

  • is not compatible with --no-directories.
  • will NOT delete the files that are in the destination folder but not in the source folder.

Note about filtering options

Option --filter allows to specify a Unix shell-style wildcard pattern (see fnmatch — Unix filename pattern matching) and select specific files:

copernicus-marine get --dataset-id cmems_mod_ibi_phy_my_0.083deg-3D_P1Y-m --filter "*01yav_200[0-2]*"

Returns:

INFO     - Downloading using service files...
INFO     - You requested the download of the following files:
s3://mdl-native/native/IBI_MULTIYEAR_PHY_005_002/cmems_mod_ibi_phy_my_0.083deg-3D_P1Y-m_202211/CMEMS_v5r1_IBI_PHY_MY_NL_01yav_20000101_20001231_R20221101_RE01.nc - 8.93 MB
s3://mdl-native/native/IBI_MULTIYEAR_PHY_005_002/cmems_mod_ibi_phy_my_0.083deg-3D_P1Y-m_202211/CMEMS_v5r1_IBI_PHY_MY_NL_01yav_20010101_20011231_R20221101_RE01.nc - 8.91 MB
s3://mdl-native/native/IBI_MULTIYEAR_PHY_005_002/cmems_mod_ibi_phy_my_0.083deg-3D_P1Y-m_202211/CMEMS_v5r1_IBI_PHY_MY_NL_01yav_20020101_20021231_R20221101_RE01.nc - 8.75 MB

Total size of the download: 26.59 MB
Do you want to proceed with download? [Y/n]:

Option --regex allows to specify a regular expression for more advanced files selection:

copernicus-marine get -i cmems_mod_ibi_phy_my_0.083deg-3D_P1Y-m --regex ".*01yav_20(00|01|02).*.nc"

Returns:

INFO     - Downloading using service files...
INFO     - You requested the download of the following files:
s3://mdl-native/native/IBI_MULTIYEAR_PHY_005_002/cmems_mod_ibi_phy_my_0.083deg-3D_P1Y-m_202211/CMEMS_v5r1_IBI_PHY_MY_NL_01yav_20000101_20001231_R20221101_RE01.nc - 8.93 MB
s3://mdl-native/native/IBI_MULTIYEAR_PHY_005_002/cmems_mod_ibi_phy_my_0.083deg-3D_P1Y-m_202211/CMEMS_v5r1_IBI_PHY_MY_NL_01yav_20010101_20011231_R20221101_RE01.nc - 8.91 MB
s3://mdl-native/native/IBI_MULTIYEAR_PHY_005_002/cmems_mod_ibi_phy_my_0.083deg-3D_P1Y-m_202211/CMEMS_v5r1_IBI_PHY_MY_NL_01yav_20020101_20021231_R20221101_RE01.nc - 8.75 MB

Total size of the download: 26.59 MB
Do you want to proceed with download? [Y/n]:

Shared options

Both subset and get commands provide these options:

Option --overwrite-output-data

When specified, the existing files will be overwritten. Otherwise, if the files already exist on destination, new ones with a unique index will be created once the download has been accepted (or once --force-download is provided).

Option --request-file

This option allows to specify CLI options but in a provided JSON file, useful for batch processing.

  • Template for subset data request:
{
	"dataset_id": "cmems_mod_glo_phy-thetao_anfc_0.083deg_P1D-m",
	"start_datetime": "2022-04-11",
	"end_datetime": "2023-08-11",
	"minimum_longitude": -182.79,
	"maximum_longitude": -179.69,
	"minimum_latitude": -40,
	"maximum_latitude": -36,
	"minimum_depth": 0,
	"maximum_depth": 0,
	"variables": ["thetao"],
	"output_directory": "./data/",
	"output_filename": "temperature_small_pacific_2022208-202308.zarr",
	"force_download": false
}

Example:

copernicus-marine subset --request-file template_subset_data_request.json
  • Template for get data request:
{
    "dataset_id": "cmems_mod_ibi_phy_my_0.083deg-3D_P1Y-m",
    "filter": "*01yav_200[0-2]*",
    "force_download": false,
    "force_service": "files",
    "log_level": "INFO",
    "no_directories": false,
    "no_metadata_cache": false,
    "output_directory": "./data/",
    "overwrite_output_data": false,
    "overwrite_metadata_cache": false,
    "show_outputnames": true
}

Example:

copernicus-marine get --request-file template_get_data_request.json

Option --credentials-file

You can use the --credentials-file option to point to a credentials file. The file can be either .copernicus-marine-credentials, motuclient-python.ini, .netrc or _netrc.

Option --force-dataset-version

You can use the --force-dataset-version option to fetch a specific dataset version.

Option --dataset-part

You can use the --dataset-part option to fecth a specific part for the chosen dataset version.

Python package (API)

The copernicus-marine-client exposes a Python interface to allow you to call commands as functions.

Documentation

See the Help Center. A detailed standalone API documentation is under construction and will come at a later stage.

Contribution

We welcome contributions from the community to enhance this package. If you find any issues or have suggestions for improvements, please check out our Report Template.

Future improvements & Roadmap

  • Make available the currently not managed Analysis-Ready Cloud-Optimized (ARCO) versions of Ocean Monitoring Indicator (OMI), in situ and static datasets.
  • Allow to specify the compression level when downloading your subset as NetCDF file.
  • Allow to subset variables using their standard_name(s) and not only their name(s).

To keep up to date with the most recent and planned advancements, including revisions, corrections, and feature requests generated from users' feedback, please refer to our Roadmap.

Join the community

Get in touch!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

copernicus_marine_client-0.10.4.tar.gz (60.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

copernicus_marine_client-0.10.4-py3-none-any.whl (79.0 kB view details)

Uploaded Python 3

File details

Details for the file copernicus_marine_client-0.10.4.tar.gz.

File metadata

  • Download URL: copernicus_marine_client-0.10.4.tar.gz
  • Upload date:
  • Size: 60.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.9.0 Linux/5.10.0-27-amd64

File hashes

Hashes for copernicus_marine_client-0.10.4.tar.gz
Algorithm Hash digest
SHA256 8151873fcd381beb746d25fa901752ac5ba7574c6aebf6e557bb051f38339dee
MD5 ccbc5d1f401d27e659267b0614338dcc
BLAKE2b-256 57a3661406ecd1f23efc41307fce8a107329bb7cdc61616a5849743020683f90

See more details on using hashes here.

File details

Details for the file copernicus_marine_client-0.10.4-py3-none-any.whl.

File metadata

File hashes

Hashes for copernicus_marine_client-0.10.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1f3d7ddda373d984abdaa6f02eb00aaa5423eb8910ec9c1a63f107e26309c9f8
MD5 b49a869656ca0cd9b5708fb118fba9c5
BLAKE2b-256 3e0f17a0ab2148af4aa466c958fbc56e52406187bf1208fb4eab05bddc2087c6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page