| Title: | Search Download and Handle Data from Copernicus Marine Service Information |
|---|---|
| Description: | Subset and download data from EU Copernicus Marine Service Information: <https://data.marine.copernicus.eu>. Import data on the oceans physical and biogeochemical state from Copernicus into R without the need of external software. |
| Authors: | Pepijn de Vries [aut, cre, dtc] (0000-0002-7961-6646) |
| Maintainer: | Pepijn de Vries <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.4.6.0002 |
| Built: | 2026-06-05 06:18:37 UTC |
| Source: | https://github.com/pepijn-devries/CopernicusMarine |
Get details for properly citing a Copernicus product.
cms_cite_product(product)cms_cite_product(product)
product |
An identifier (type |
Returns a vector of character strings. The first element is always the product title, id and doi. Remaining elements are other associated references. Note that the remaining references are returned as listed at Copernicus. Note that the citing formatting does not appear to be standardised.
Pepijn de Vries
Other product-functions:
cms_product_details(),
cms_product_services(),
cms_products_list()
cms_cite_product("SST_MED_PHY_SUBSKIN_L4_NRT_010_036")cms_cite_product("SST_MED_PHY_SUBSKIN_L4_NRT_010_036")
Full marine data sets can be downloaded using the functions
documented here. Use
cms_list_native_files() to list available files, and
cms_download_native() to download specific files. Files are usually organised per product,
layer, year, month and day.
cms_download_native( destination, product, layer, pattern, prefix, progress = TRUE, ..., username = cms_get_username(), password = cms_get_password() ) cms_list_native_files(product, layer, pattern, prefix, max = Inf, ...)cms_download_native( destination, product, layer, pattern, prefix, progress = TRUE, ..., username = cms_get_username(), password = cms_get_password() ) cms_list_native_files(product, layer, pattern, prefix, max = Inf, ...)
destination |
Path where to store the downloaded file(s). |
product |
An identifier (type |
layer |
The name of a desired layer within a product (type |
pattern |
A regular expression (regex)
pattern. Only paths that match the pattern will be returned. It can be used
to select specific files. For instance if |
prefix |
A |
progress |
A |
... |
Ignored |
username |
Your Copernicus marine user name. Can be provided with
|
password |
Your Copernicus marine password. Can be provided as
|
max |
A maximum number of records to be returned. |
Returns NULL invisibly.
Pepijn de Vries
if (interactive()) { cms_list_native_files( product = "GLOBAL_ANALYSISFORECAST_PHY_001_024", layer = "cmems_mod_glo_phy_anfc_0.083deg_PT1H-m", prefix = "2022/06/" ) ## If you omit the prefix, you may want to limit the ## number of results by setting `max` cms_list_native_files( product = "GLOBAL_ANALYSISFORECAST_PHY_001_024", layer = "cmems_mod_glo_phy_anfc_0.083deg_PT1H-m", max = 10 ) ## Prefix can be omitted when not relevant: cms_list_native_files(product = "SEALEVEL_GLO_PHY_MDT_008_063") ## Use 'pattern' to download a file for a specific day: cms_download_native( destination = tempdir(), product = "GLOBAL_ANALYSISFORECAST_PHY_001_024", layer = "cmems_mod_glo_phy_anfc_0.083deg_PT1H-m", prefix = "2022/06/", pattern = "m_20220630" ) }if (interactive()) { cms_list_native_files( product = "GLOBAL_ANALYSISFORECAST_PHY_001_024", layer = "cmems_mod_glo_phy_anfc_0.083deg_PT1H-m", prefix = "2022/06/" ) ## If you omit the prefix, you may want to limit the ## number of results by setting `max` cms_list_native_files( product = "GLOBAL_ANALYSISFORECAST_PHY_001_024", layer = "cmems_mod_glo_phy_anfc_0.083deg_PT1H-m", max = 10 ) ## Prefix can be omitted when not relevant: cms_list_native_files(product = "SEALEVEL_GLO_PHY_MDT_008_063") ## Use 'pattern' to download a file for a specific day: cms_download_native( destination = tempdir(), product = "GLOBAL_ANALYSISFORECAST_PHY_001_024", layer = "cmems_mod_glo_phy_anfc_0.083deg_PT1H-m", prefix = "2022/06/", pattern = "m_20220630" ) }
Subset and download a specific marine product
from Copernicus.
cms_download_subset( product, layer, variable, region, timerange, verticalrange, progress = TRUE, asset, ..., username = cms_get_username(), password = cms_get_password() )cms_download_subset( product, layer, variable, region, timerange, verticalrange, progress = TRUE, asset, ..., username = cms_get_username(), password = cms_get_password() )
product |
An identifier (type |
layer |
The name of a desired layer within a product (type |
variable |
The name of a desired variable in a specific layer of a product (type |
region |
Specification of the bounding box as a |
timerange |
A |
verticalrange |
A |
progress |
A logical value. When |
asset |
Type of asset to be used when subsetting data. Should be one
of |
... |
Ignored (reserved for future features). |
username |
Your Copernicus marine user name. Can be provided with
|
password |
Your Copernicus marine password. Can be provided as
|
Returns a stars::st_as_stars() object.
Pepijn de Vries
if (interactive()) { mydata <- cms_download_subset( product = "GLOBAL_ANALYSISFORECAST_PHY_001_024", layer = "cmems_mod_glo_phy-cur_anfc_0.083deg_P1D-m", variable = c("uo", "vo"), region = c(-1, 50, 10, 55), timerange = c("2025-01-01 UTC", "2025-01-02 UTC"), verticalrange = c(0, -2) ) plot(mydata["vo"]) } else { message("Make sure to run this in an interactive environment") }if (interactive()) { mydata <- cms_download_subset( product = "GLOBAL_ANALYSISFORECAST_PHY_001_024", layer = "cmems_mod_glo_phy-cur_anfc_0.083deg_P1D-m", variable = c("uo", "vo"), region = c(-1, 50, 10, 55), timerange = c("2025-01-01 UTC", "2025-01-02 UTC"), verticalrange = c(0, -2) ) plot(mydata["vo"]) } else { message("Make sure to run this in an interactive environment") }
This function retrieves the client information
from the Copernicus Marine Service.
Among others, it lists where to find the catalogues required by this package
cms_get_client_info(...)cms_get_client_info(...)
... |
Ignored |
In case of success it returns a named list with information about the available
Copernicus Marine clients.
Pepijn de Vries
if (interactive()) { cms_get_client_info() }if (interactive()) { cms_get_client_info() }
Set or get username and password throughout an R session.
This can be used to obscure your account details in an R script and
store them as either an R option or system environment variable.
cms_get_username() cms_get_password() cms_set_username(username, method = c("option", "sysenv")) cms_set_password(password, method = c("option", "sysenv"))cms_get_username() cms_get_password() cms_set_username(username, method = c("option", "sysenv")) cms_set_password(password, method = c("option", "sysenv"))
username |
Your Copernicus Marine username |
method |
Either |
password |
Your Copernicus Marine password |
Returns your account details for the get variant or nothing in case
of the set variant.
Pepijn de Vries
if (interactive()) { ## Returns your account details only if they have been set for your session cms_get_username() cms_get_password() }if (interactive()) { ## Returns your account details only if they have been set for your session cms_get_username() cms_get_password() }
Function that returns a data.frame with a glossary of terminology
used by the Copernicus Marine Data Service. It is the same data.frame
that is used to render vignette("glossary").
cms_glossary(search, match_fun = agrep, ...)cms_glossary(search, match_fun = agrep, ...)
search |
Search terms to look for in the glossary |
match_fun |
Function used to filter the |
... |
Arguments passed to |
Returns a data.frame with glossary info.
cms_glossary("variable", ignore.case = TRUE)cms_glossary("variable", ignore.case = TRUE)
Contact Copernicus Marine login page
and check if login is successful.
cms_login(username = cms_get_username(), password = cms_get_password())cms_login(username = cms_get_username(), password = cms_get_password())
username |
Your Copernicus marine user name. Can be provided with
|
password |
Your Copernicus marine password. Can be provided as
|
This function will return your account details if successful.
Returns a named list with your account details if successful,
returns NULL otherwise.
Pepijn de Vries
if (interactive()) { cms_login() }if (interactive()) { cms_login() }
The advantage of
stars_proxy objects,
is that they do not contain any data. They are therefore fast to handle
and consume only limited memory. You can still manipulate the object
lazily (like selecting slices). These operation are only executed when
calling stars::st_as_stars() or plot() on the object.
cms_native_proxy( product, layer, pattern, prefix, variable, ..., username = cms_get_username(), password = cms_get_password() )cms_native_proxy( product, layer, pattern, prefix, variable, ..., username = cms_get_username(), password = cms_get_password() )
product |
An identifier (type |
layer |
The name of a desired layer within a product (type |
pattern |
A regular expression (regex)
pattern. Only paths that match the pattern will be returned. It can be used
to select specific files. For instance if |
prefix |
A |
variable |
The variable name for which to create the |
... |
Ignored |
username |
Your Copernicus marine user name. Can be provided with
|
password |
Your Copernicus marine password. Can be provided as
|
For more details see vignette("proxy").
Pepijn de Vries
if (interactive()) { native_proxy <- cms_native_proxy( product = "GLOBAL_ANALYSISFORECAST_PHY_001_024", layer = "cmems_mod_glo_phy_anfc_0.083deg_PT1H-m", prefix = "2022/06/", pattern = "20220621" ) plot(native_proxy["zos", 1:1000, 1:500, 1, 1], axes = TRUE) }if (interactive()) { native_proxy <- cms_native_proxy( product = "GLOBAL_ANALYSISFORECAST_PHY_001_024", layer = "cmems_mod_glo_phy_anfc_0.083deg_PT1H-m", prefix = "2022/06/", pattern = "20220621" ) plot(native_proxy["zos", 1:1000, 1:500, 1, 1], axes = TRUE) }
Obtain details for a specific Copernicus marine product.
cms_product_details(product, ...)cms_product_details(product, ...)
product |
An identifier (type |
... |
Ignored |
See vignette("product-info") for more details.
Returns a named list with product details.
Pepijn de Vries
Other product-functions:
cms_cite_product(),
cms_product_services(),
cms_products_list()
if (interactive()) { cms_product_details("GLOBAL_ANALYSISFORECAST_PHY_001_024") }if (interactive()) { cms_product_details("GLOBAL_ANALYSISFORECAST_PHY_001_024") }
Obtain product meta data such as spatio-temporal bounds
of the data.
cms_product_metadata(product, ...)cms_product_metadata(product, ...)
product |
An identifier (type |
... |
Ignored |
See vignette("product-info") for more details.
Returns a data.frame/tibble with the metadata. Each row in the data.frame
represents a layer available for the product.
Pepijn de Vries
if (interactive()) { cms_product_metadata("GLOBAL_ANALYSISFORECAST_PHY_001_024") }if (interactive()) { cms_product_metadata("GLOBAL_ANALYSISFORECAST_PHY_001_024") }
Obtain an overview of services provided by Copernicus
for a specific marine product.
cms_product_services(product, ...)cms_product_services(product, ...)
product |
An identifier (type |
... |
Ignored. |
See vignette("product-info") for more details.
Returns a tibble with a list of available services for a
Copernicus marine product.
Pepijn de Vries
Other product-functions:
cms_cite_product(),
cms_product_details(),
cms_products_list()
if (interactive()) { cms_product_services("GLOBAL_ANALYSISFORECAST_PHY_001_024") }if (interactive()) { cms_product_services("GLOBAL_ANALYSISFORECAST_PHY_001_024") }
Collect a list of products and some brief
descriptions for marine products available from Copernicus.
cms_products_list()
does not use a formal API, but provides a more detailed list. cms_products_list2()
Does use the formal API, but provides less details.
cms_products_list(..., info_type = c("list", "meta")) cms_products_list2(...)cms_products_list(..., info_type = c("list", "meta")) cms_products_list2(...)
... |
Allows you to pass (search) query parameters to apply to the list. When omitted, the full list of products is returned. |
info_type |
One of |
See vignette("product-info") for more details.
Returns a tibble of products available from https://data.marine.copernicus.eu or
a named list when info_type = "meta". Returns NULL in case on-line services are
unavailable.
Pepijn de Vries
Other product-functions:
cms_cite_product(),
cms_product_details(),
cms_product_services()
cms_products_list() ## Query a specific product: cms_products_list(freeText = "GLOBAL_ANALYSISFORECAST_PHY_001_024")cms_products_list() ## Query a specific product: cms_products_list(freeText = "GLOBAL_ANALYSISFORECAST_PHY_001_024")
Use the Copernicus Marine Service
website to navigate datasets
https://data.marine.copernicus.eu/products. You can specify
a query using the website's download form, and copy it's automation
download code (either command line or Python) to the system's clipboard.
You can then use this function to translate this code to a named list.
The list can be used in combination with
cms_download_subset() to
download data. See vignette("translate") for more details.
cms_translate(text, ...)cms_translate(text, ...)
text |
The query code as copied from the Copernicus Marine Service website. Both Python and command line code are accepted. When this argument is omitted, the function will look for a query on the system clipboard. |
... |
Ignored |
Returns a named list with arguments for cms_download_subset()
python_code <- "import copernicusmarine copernicusmarine.subset( dataset_id=\"cmems_mod_glo_phy_anfc_0.083deg_PT1H-m\", variables=[\"uo\",\"vo\"], minimum_longitude=-2, maximum_longitude=8, minimum_latitude=52, maximum_latitude=59, start_datetime=\"2025-01-01T00:00:00\", end_datetime=\"2025-01-01T23:00:00\", minimum_depth=0.49402499198913574, maximum_depth=0.49402499198913574, )" cli_code <- "copernicusmarine subset --dataset-id cmems_mod_glo_phy_anfc_0.083deg_PT1H-m --variable uo --variable vo --start-datetime 2025-01-01T00:00:00 --end-datetime 2025-01-01T23:00:00 --minimum-longitude -2 --maximum-longitude 8 --minimum-latitude 52 --maximum-latitude 59 --minimum-depth 0.49402499198913574 --maximum-depth 0.49402499198913574" if (interactive()) { cms_translate(python_code) cms_translate(cli_code) translated <- cms_translate(cli_code) do.call(cms_download_subset, translated) }python_code <- "import copernicusmarine copernicusmarine.subset( dataset_id=\"cmems_mod_glo_phy_anfc_0.083deg_PT1H-m\", variables=[\"uo\",\"vo\"], minimum_longitude=-2, maximum_longitude=8, minimum_latitude=52, maximum_latitude=59, start_datetime=\"2025-01-01T00:00:00\", end_datetime=\"2025-01-01T23:00:00\", minimum_depth=0.49402499198913574, maximum_depth=0.49402499198913574, )" cli_code <- "copernicusmarine subset --dataset-id cmems_mod_glo_phy_anfc_0.083deg_PT1H-m --variable uo --variable vo --start-datetime 2025-01-01T00:00:00 --end-datetime 2025-01-01T23:00:00 --minimum-longitude -2 --maximum-longitude 8 --minimum-latitude 52 --maximum-latitude 59 --minimum-depth 0.49402499198913574 --maximum-depth 0.49402499198913574" if (interactive()) { cms_translate(python_code) cms_translate(cli_code) translated <- cms_translate(cli_code) do.call(cms_download_subset, translated) }
Functions for retrieving Web Map Tile Services information for
specific products, layers and variables and add them to a
leaflet map.
cms_wmts_details(product, layer, variable) addCmsWMTSTiles( map, product, layer, variable, tilematrixset = "EPSG:3857", time, elevation, options = leaflet::WMSTileOptions(format = "image/png", transparent = TRUE), ... ) cms_wmts_get_capabilities( product, layer, variable, type = c("data.frame", "xml") )cms_wmts_details(product, layer, variable) addCmsWMTSTiles( map, product, layer, variable, tilematrixset = "EPSG:3857", time, elevation, options = leaflet::WMSTileOptions(format = "image/png", transparent = TRUE), ... ) cms_wmts_get_capabilities( product, layer, variable, type = c("data.frame", "xml") )
product |
An identifier (type |
layer |
The name of a desired layer within a product (type |
variable |
The name of a desired variable in a specific layer of a product (type |
map |
A map widget object created from |
tilematrixset |
A |
elevation, time
|
Elevation or time dimension value for which to add
the tiles to the map. When missing; or not matching exactly with the values
specified by |
options |
Passed on to |
... |
Passed on to |
type |
A |
cms_wmts_details returns a tibble with details on the WMTS service.
cms_wmts_get_capabilities returns either a data.frame or xml_document depending on the value
of type. AddCmsWMTSTiles returns a leaflet map updated with the requested tiles.
Pepijn de Vries
if (interactive()) { wmts_details <- cms_wmts_details( product = "GLOBAL_ANALYSISFORECAST_PHY_001_024", layer = "cmems_mod_glo_phy-thetao_anfc_0.083deg_P1D-m", variable = "thetao" ) capabilities <- cms_wmts_get_capabilities("GLOBAL_ANALYSISFORECAST_PHY_001_024") if (nrow(wmts_details) > 0) { leaflet::leaflet() |> leaflet::setView(lng = 3, lat = 54, zoom = 4) |> leaflet::addProviderTiles("Esri.WorldImagery") |> addCmsWMTSTiles( product = "GLOBAL_ANALYSISFORECAST_PHY_001_024", layer = "cmems_mod_glo_phy-thetao_anfc_0.083deg_P1D-m", variable = "thetao") } }if (interactive()) { wmts_details <- cms_wmts_details( product = "GLOBAL_ANALYSISFORECAST_PHY_001_024", layer = "cmems_mod_glo_phy-thetao_anfc_0.083deg_P1D-m", variable = "thetao" ) capabilities <- cms_wmts_get_capabilities("GLOBAL_ANALYSISFORECAST_PHY_001_024") if (nrow(wmts_details) > 0) { leaflet::leaflet() |> leaflet::setView(lng = 3, lat = 54, zoom = 4) |> leaflet::addProviderTiles("Esri.WorldImagery") |> addCmsWMTSTiles( product = "GLOBAL_ANALYSISFORECAST_PHY_001_024", layer = "cmems_mod_glo_phy-thetao_anfc_0.083deg_P1D-m", variable = "thetao") } }
The advantage of
stars_proxy objects,
is that they do not contain any data. They are therefore fast to handle
and consume only limited memory. You can still manipulate the object
lazily (like selecting slices). These operation are only executed when
calling stars::st_as_stars() or plot() on the object.
cms_zarr_proxy( product, layer, variable, asset, ..., username = cms_get_username(), password = cms_get_password() )cms_zarr_proxy( product, layer, variable, asset, ..., username = cms_get_username(), password = cms_get_password() )
product |
An identifier (type |
layer |
The name of a desired layer within a product (type |
variable |
The name of a desired variable in a specific layer of a product (type |
asset |
An asset that is available for the |
... |
Ignored (reserved for future features). |
username |
Your Copernicus marine user name. Can be provided with
|
password |
Your Copernicus marine password. Can be provided as
|
For more details see vignette("proxy").
Pepijn de Vries
if (interactive()) { myproxy <- cms_zarr_proxy( product = "GLOBAL_ANALYSISFORECAST_PHY_001_024", layer = "cmems_mod_glo_phy-cur_anfc_0.083deg_P1D-m", variable = c("uo", "vo"), asset = "timeChunked") plot(myproxy["uo",1:200,1:100,50,1], axes = TRUE) }if (interactive()) { myproxy <- cms_zarr_proxy( product = "GLOBAL_ANALYSISFORECAST_PHY_001_024", layer = "cmems_mod_glo_phy-cur_anfc_0.083deg_P1D-m", variable = c("uo", "vo"), asset = "timeChunked") plot(myproxy["uo",1:200,1:100,50,1], axes = TRUE) }