ESA Mediterranean Data Cubes

The ESA Mediterranean Datacube brings together Earth observation and ocean science datasets for the Mediterranean Sea as part of EarthCODE’s work to make data easier to access and analyse. Drawing on ESA Ocean Science Cluster activities and complementary research products, it covers ocean circulation, physical and biogeochemical conditions, marine productivity, carbon exchange and marine heatwaves.

The datasets share a common 1/24° latitude-longitude grid in EPSG:4326 and are organised in analysis-ready GeoZarr format, with separate stores for monthly variables, daily surface and depth-resolved fields, and hourly currents.

Visit the ocean hackathon website to explore the data and accompanying examples, or browse the notebooks on GitHub.

Example variables from the ESA Mediterranean Datacube.

The Data

The collection covers the Mediterranean Sea, approximately 6°W-36°E and 30°N-46°N. The daily and monthly grids cover 2016-2022, with depth-resolved data through July 2022; hourly currents cover late 2014-2019. Availability varies by source dataset and variable.

Daily Surface Variables

The daily surface datasets we have processed are:

Monthly Ocean Variables

The monthly store includes:

Daily Depth-Resolved Variables

The depth-resolved store includes fields at 18 levels from 3 to 135 m:

Hourly Currents

Each source dataset retains its own attribution, licence and scientific reference. See the dataset overview and access examples for more information.

Access

Reading the Data

You can read the monthly GeoZarr store using Xarray, opening group 0 for the full-resolution grid:

import xarray as xr

ds = xr.open_zarr("https://s3.waw4-1.cloudferro.com/EarthCODE/OSCAssets/med_cubes/ocean-med-monthly-cube.zarr", group="0", chunks={})
ds

The store also provides groups 1 and 2 for coarser spatial levels. For example, you can open group 1 and select chlorophyll-a for July 2019:

coarse_ds = xr.open_zarr("https://s3.waw4-1.cloudferro.com/EarthCODE/OSCAssets/med_cubes/ocean-med-monthly-cube.zarr", group="1", chunks={})

chlorophyll = coarse_ds["chl_a"].sel(time="2019-07-01")
chlorophyll

The stores share a spatial grid, but their time coordinates and depth dimensions differ. Select the variables and align the time periods needed for your analysis when working across stores.

For tutorials and worked examples, visit the Mediterranean Datacube getting-started notebook or GitHub repository.

To suggest a dataset, share a use case or help extend the collection, reply here or email earth-code@esa.int.

Hi,

I’ve been trying to integrate the datacubes into my R workflow instead of Python.
But I haven’t been succesfull so far, the ‘recommended’ package i found online to read zarr files (Rarr) is not (anymore) on CRAN.

Honestly out of my depth a bit… any help would be appreciated! :grinning:

1 Like

Hi Joran,

Can you try using stars and updating gdal to 3.13 or above ? I’ve not used stars directly, but as far as I understand its using gdal underneath to read the data.

stars : Reading Zarr files with R package stars

I can read some data with gdal 3.13 directly from the command line:

pixi run gdalinfo -stats ‘ZARR:“/vsicurl/https://s3.waw4-1.cloudferro.com/EarthCODE/OSCAssets/med_cubes/ocean-med-daily-surface-cube.zarr”:/0/sos:0’
ERROR 1: Codec sharding_indexed: sharding not supported for scalar array
ERROR 1: Codec sharding_indexed: sharding not supported for scalar array
ERROR 1: Codec sharding_indexed: sharding not supported for scalar array
Driver: Zarr/Zarr
Files: /vsicurl/https://s3.waw4-1.cloudferro.com/EarthCODE/OSCAssets/med_cubes/ocean-med-daily-surface-cube.zarr/0/sos/zarr.json
Size is 1012, 378
Coordinate System is:
GEOGCRS[“WGS 84”,
ENSEMBLE[“World Geodetic System 1984 ensemble”,
MEMBER[“World Geodetic System 1984 (Transit)”],
MEMBER[“World Geodetic System 1984 (G730)”],
MEMBER[“World Geodetic System 1984 (G873)”],
MEMBER[“World Geodetic System 1984 (G1150)”],
MEMBER[“World Geodetic System 1984 (G1674)”],
MEMBER[“World Geodetic System 1984 (G1762)”],
MEMBER[“World Geodetic System 1984 (G2139)”],
MEMBER[“World Geodetic System 1984 (G2296)”],
ELLIPSOID[“WGS 84”,6378137,298.257223563,
LENGTHUNIT[“metre”,1]],
ENSEMBLEACCURACY[2.0]],
PRIMEM[“Greenwich”,0,
ANGLEUNIT[“degree”,0.0174532925199433]],
CS[ellipsoidal,2],
AXIS[“geodetic latitude (Lat)”,north,
ORDER[1],
ANGLEUNIT[“degree”,0.0174532925199433]],
AXIS[“geodetic longitude (Lon)”,east,
ORDER[2],
ANGLEUNIT[“degree”,0.0174532925199433]],
USAGE[
SCOPE[“Horizontal component of 3D system.”],
AREA[“World.”],
BBOX[-90,-180,90,180]],
ID[“EPSG”,4326]]
Data axis to CRS axis mapping: 2,1
Origin = (-6.083331427243676,30.250000634091965)
Pixel Size = (0.041666669184619,0.041666670048490)
Metadata:
aggregation_method=mean
data_meaning=continuous
description=N/A
file_type=area
grid_mapping=spatial_ref
is_mask=false
long_name=sea surface salinity
original_spatial_resolution={0.041666984558105469,0.041667938232421875}
original_temporal_resolution=1 day; nominally 12:00 UTC, 00:00 UTC in December 2020
processing_steps={ “regrid_func”: “regrid_kdtree_pyresample”, “roi_m”: 4000, “epsilon”: 0 }
reference=ESA 4DMED-SEA - Mediterranean Multivariate Optimal Interpolated Salinity and Density fields | Zenodo
source=https://esa-earthcode.github.io/open-science-catalog-metadata/products/4dmed-2d-sss/collection
standard_name=sea_surface_salinity
valid_range={0,40}
visualization_range={36.440073242187502,39.414380035400391}
Corner Coordinates:
Upper Left ( -6.0833314, 30.2500006) ( 6d 4’59.99"W, 30d15’ 0.00"N)
Lower Left ( -6.0833314, 46.0000019) ( 6d 4’59.99"W, 46d 0’ 0.01"N)
Upper Right ( 36.0833378, 30.2500006) ( 36d 5’ 0.02"E, 30d15’ 0.00"N)
Lower Right ( 36.0833378, 46.0000019) ( 36d 5’ 0.02"E, 46d 0’ 0.01"N)
Center ( 15.0000032, 38.1250013) ( 15d 0’ 0.01"E, 38d 7’30.00"N)
Band 1 Block=506x189 Type=Float64, ColorInterp=Undefined
Minimum=9.414, Maximum=39.322, Mean=38.306, StdDev=0.678
NoData Value=nan
Unit Type: .0001
Metadata:
STATISTICS_MINIMUM=9.4141149520874
STATISTICS_MAXIMUM=39.321662902832
STATISTICS_MEAN=38.306405851651
STATISTICS_STDDEV=0.67784879118194
STATISTICS_VALID_PERCENT=36.97

Hi Joran! Can you try using r-stars? You also will need a later version of gdal that supports zarr-v3. The below seems to work. I’m definitely not a R user though! :smiley: So I’m not entirely sure how to install/update gdal in RStudio.

The below is ran from my local JupyterLab.

# install conda and run this either in the terminal or notebook
!micromamba create -y  -n rzarr   -c conda-forge   "gdal>=3.13,<3.14"   r-base   r-stars   r-irkernel   jupyterlab

library(stars)

url <- paste0(
  "https://s3.waw4-1.cloudferro.com/EarthCODE/",
  "OSCAssets/med_cubes/ocean-med-daily-surface-cube.zarr"
)

dsn <- sprintf('ZARR:"/vsicurl/%s":/0/sos:0', url)

salinity <- read_stars(dsn, proxy = FALSE)

print(salinity)

plot(salinity, main = "Sea-surface salinity - first day")


Would be great to have an R example of accessing the data if you can get it working in RStudio!

Hi!

Thanks for the advice the both of you! After some tweaking I managed to get it to work using the stars package. Slight problem is that the GDAL in the sf package is an older version so it does not ‘directly’ work.

Instead I had to embed a python session in my r session using the reticulate package. Like this I managed to get it to work.


system("where python")
Sys.glob("C:/Users/Blueseeds/AppData/Local/Programs/Python/*/python.exe")
Sys.glob("C:/Program Files/Python*/python.exe")
# ---- 0. Setup ---------------------------------------------------------------
py_path <- Sys.glob("C:/Users/Blueseeds/AppData/Local/Python/pythoncore-*/python.exe")[1]
if (is.na(py_path)) py_path <- "C:/Users/Blueseeds/AppData/Local/Python/bin/python.exe"
Sys.setenv(RETICULATE_PYTHON = py_path)   # must run before library(reticulate)

library(reticulate)
library(stars)

xr   <- import("xarray")
bi   <- import_builtins()
base <- "https://s3.waw4-1.cloudferro.com/EarthCODE/OSCAssets/med_cubes"

# ---- 1. Helpers -------------------------------------------------------------
open_cube <- function(name, level = "2") {
  xr$open_zarr(paste0(base, "/", name), group = level,
               chunks = py_eval("{}"), consolidated = TRUE, decode_coords = "all")
}

getvar <- function(ds, v) py_get_item(ds, v)

np1 <- function(x) {
  if (inherits(x, "python.builtin.object")) x <- x$tolist()
  as.numeric(unlist(x))
}

np2 <- function(x) {
  if (inherits(x, "python.builtin.object")) {
    x <- do.call(rbind, lapply(x$tolist(), as.numeric))
  }
  unname(as.matrix(x))
}

# 2D xarray DataArray (lat, lon) -> stars object, north up
da_to_stars <- function(da, name) {
  m   <- np2(da$values)
  lon <- np1(da$lon$values)
  lat <- np1(da$lat$values)
  if (lat[1] < lat[2]) { m <- m[nrow(m):1, , drop = FALSE]; lat <- rev(lat) }

  dx <- (lon[length(lon)] - lon[1]) / (length(lon) - 1)
  dy <- (lat[length(lat)] - lat[1]) / (length(lat) - 1)   # negative

  s <- st_as_stars(t(m))
  s <- st_set_dimensions(s, 1, offset = lon[1] - dx/2, delta = dx, names = "x")
  s <- st_set_dimensions(s, 2, offset = lat[1] - dy/2, delta = dy, names = "y")
  st_crs(s) <- 4326
  setNames(s, name)
}

# ---- 2. Open cube and select region ----------------------------------------
level <- "2"                       # "0" full res, "1" 1/6 deg, "2" 1/3 deg
daily <- open_cube("ocean-med-daily-surface-cube.zarr", level)

region <- daily$sel(lon = bi$slice(-6, 0),      # Alboran Sea
                    lat = bi$slice(34, 38.5))
day <- region$sel(time = "2019-06-01")$compute()

# ---- 3. Plot 1: salinity and density ---------------------------------------
sos <- da_to_stars(getvar(day, "sos"), "sos")
dos <- da_to_stars(getvar(day, "dos"), "dos")

plot(sos, axes = TRUE, main = "Sea-surface salinity 2019-06-01")
plot(dos, axes = TRUE, main = "Sea-surface density 2019-06-01")

# ---- 4. Plot 2: sea level and geostrophic currents -------------------------
adt <- da_to_stars(getvar(day, "adt_4dvarnet"), "adt")

lon <- np1(day$lon$values)
lat <- np1(day$lat$values)                       # ascending, matches rows of u and v
u   <- np2(getvar(day, "ugos_4dvarnet")$values)  # [lat, lon]
v   <- np2(getvar(day, "vgos_4dvarnet")$values)

plot(adt, axes = TRUE, reset = FALSE, main = "4DVarNet ADT
2 Likes