Generate CMEMS cubes
Generate CMEMS data cubes¶
A DeepESDL example notebook¶
This notebook demonstrates how to access CMEMS data via the dedicated xcube store, which provides dynamic data cube views into each gridded data set. More information on the data sets offered can be found in the Copernicus Marine Data Store.
Please, also refer to the DeepESDL documentation and visit the platform's website for further information!
Brockmann Consult, 2025
This notebook runs with the python environment users-deepesdl-xcube-1.9.1
, please checkout the documentation for help on changing the environment.
If you do not have cmems user yet, you can register for an account. For DeepESDL Basic Jupyter Profile default credentials are configured, but due to bandwith limitation by CMEMS they might not be performant when used by several people simultanously.
import os
## replace with your user name and pwd
# os.environ["CMEMS_USERNAME"] = "<your-username>"
# os.environ["CMEMS_PASSWORD"] = "<your-pwd>"
Check whether the CMEMS
store is among the available stores, if not please follow the installation information from the top of this notebook.
JSON({e.name: e.metadata for e in find_data_store_extensions()})
<IPython.core.display.JSON object>
Usually we need more information to get the actual data store object. Which data store parameters are available for cmems
?
get_data_store_params_schema("cmems")
<xcube.util.jsonschema.JsonObjectSchema at 0x7fa781c211f0>
Import the xcube CMEMS store and create store instance¶
If you do not have cmems user yet, you can register for an account. For DeepESDL Basic Jupyter Profile default credentials are configured, but due to bandwith limitation by CMEMS they might not be performant when used by several people simultanously.
# cmems_store = new_data_store('cmems', cmems_username=os.environ["CMEMS_USERNAME"], cmems_password = os.environ["CMEMS_PASSWORD"])
cmems_store = new_data_store("cmems")
Get all dataset_ids for CMEMS API and let store describe data set¶
#cmems_store.list_data_ids()
data_des = cmems_store.describe_data("cmems_mod_bal_wav_my_PT1H-i")
INFO - 2025-06-10T09:28:41Z - Selected dataset version: "202411" INFO - 2025-06-10T09:28:41Z - Selected dataset part: "default" /home/conda/users/635b18b7-1749540690-47-deepesdl-xcube-1.9.1/lib/python3.12/site-packages/xcube/core/store/descriptor.py:247: FutureWarning: The return type of `Dataset.dims` will be changed to return a set of dimension names in future, in order to be more consistent with `DataArray.dims`. To access a mapping from dimension names to lengths, please use `Dataset.sizes`. self.dims = dict(dims) if dims else None
data_des.time_range
('1980-01-01', '2025-03-01')
data_des.bbox
(9, 53, 30.221627251342774, 65.91610912890626)
Open a dataset without cube parameters¶
ds = cmems_store.open_data("cmems_mod_bal_wav_my_PT1H-i")
ds
INFO - 2025-06-10T09:28:50Z - Selected dataset version: "202411" INFO - 2025-06-10T09:28:50Z - Selected dataset part: "default"
<xarray.Dataset> Size: 18TB Dimensions: (time: 395904, latitude: 775, longitude: 764) Coordinates: * latitude (latitude) float32 3kB 53.01 53.02 53.04 ... 65.87 65.89 65.91 * longitude (longitude) float32 3kB 9.014 9.042 9.069 ... 30.15 30.18 30.21 * time (time) datetime64[ns] 3MB 1980-01-01T01:00:00 ... 2025-03-01 Data variables: (12/19) VCMX (time, latitude, longitude) float32 938GB dask.array<chunksize=(2, 775, 764), meta=np.ndarray> VHM0 (time, latitude, longitude) float32 938GB dask.array<chunksize=(2, 775, 764), meta=np.ndarray> VHM0_SW1 (time, latitude, longitude) float32 938GB dask.array<chunksize=(2, 775, 764), meta=np.ndarray> VHM0_SW2 (time, latitude, longitude) float32 938GB dask.array<chunksize=(2, 775, 764), meta=np.ndarray> VHM0_WW (time, latitude, longitude) float32 938GB dask.array<chunksize=(2, 775, 764), meta=np.ndarray> VMDR (time, latitude, longitude) float32 938GB dask.array<chunksize=(2, 775, 764), meta=np.ndarray> ... ... VTM01_SW1 (time, latitude, longitude) float32 938GB dask.array<chunksize=(2, 775, 764), meta=np.ndarray> VTM01_SW2 (time, latitude, longitude) float32 938GB dask.array<chunksize=(2, 775, 764), meta=np.ndarray> VTM01_WW (time, latitude, longitude) float32 938GB dask.array<chunksize=(2, 775, 764), meta=np.ndarray> VTM02 (time, latitude, longitude) float32 938GB dask.array<chunksize=(2, 775, 764), meta=np.ndarray> VTM10 (time, latitude, longitude) float32 938GB dask.array<chunksize=(2, 775, 764), meta=np.ndarray> VTPK (time, latitude, longitude) float32 938GB dask.array<chunksize=(2, 775, 764), meta=np.ndarray> Attributes: institution: Baltic MFC, PU Finnish Meteorological Institute title: 2D - Hourly Instantaneous Conventions: CF-1.0 source: FMI-WAM_CMEMS
ds.VHM0
<xarray.DataArray 'VHM0' (time: 395904, latitude: 775, longitude: 764)> Size: 938GB dask.array<xarray-VHM0, shape=(395904, 775, 764), dtype=float32, chunksize=(2, 775, 764), chunktype=numpy.ndarray> Coordinates: * latitude (latitude) float32 3kB 53.01 53.02 53.04 ... 65.87 65.89 65.91 * longitude (longitude) float32 3kB 9.014 9.042 9.069 ... 30.15 30.18 30.21 * time (time) datetime64[ns] 3MB 1980-01-01T01:00:00 ... 2025-03-01 Attributes: cell_methods: time: mean long_name: Spectral significant wave height (Hm0) standard_name: sea_surface_wave_significant_height units: m valid_max: 20.0 valid_min: 0.0
ds.VHM0.isel(time=0).plot.imshow()
<matplotlib.image.AxesImage at 0x7fa733288320>
Open a dataset with cube parameters¶
cmems_store.get_open_data_params_schema(
"cmems_mod_bal_wav_my_PT1H-i"
)
<xcube.util.jsonschema.JsonObjectSchema at 0x7fa72fe22630>
ds = cmems_store.open_data(
"cmems_mod_bal_wav_my_PT1H-i",
variable_names=["VHM0"],
time_range=("2021-11-01", "2021-12-13"),
bbox=[10, 54, 20, 62]
)
ds
INFO - 2025-06-10T09:29:06Z - Selected dataset version: "202411" INFO - 2025-06-10T09:29:06Z - Selected dataset part: "default"
<xarray.Dataset> Size: 697MB Dimensions: (time: 1009, latitude: 480, longitude: 360) Coordinates: * latitude (latitude) float32 2kB 54.01 54.02 54.04 ... 61.96 61.97 61.99 * longitude (longitude) float32 1kB 10.01 10.04 10.07 ... 19.93 19.96 19.99 * time (time) datetime64[ns] 8kB 2021-11-01 ... 2021-12-13 Data variables: VHM0 (time, latitude, longitude) float32 697MB dask.array<chunksize=(2, 480, 360), meta=np.ndarray> Attributes: institution: Baltic MFC, PU Finnish Meteorological Institute title: 2D - Hourly Instantaneous Conventions: CF-1.0 source: FMI-WAM_CMEMS
ds.VHM0.sel(time="2021-12-13T12:12.00", method="nearest").plot.imshow()
<matplotlib.image.AxesImage at 0x7fa72c042600>