Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Build a sample datacube from two datasets

ESA

Explore Data

This notebooks shows how to regrid and combine two datasets from different sources and with different resolutions. The first one is the 4DMED-SEA sea-surface salinity and the second one Careheat.

The code specifies a day, resamples the datasets to a 1/12° grid, applies the WorldCover water retention mask, saves the results as Zarr v3, and plots the result.

The datacubes were created following a similar procedure. The overview describes the original cube workflows.

1. Open the Source Dataset

Open the 4DMED-SEA salinity dataset. The data remain lazy until the selected region is written below.

2. Select a date and resample both datasets

Create the new grid, select surface salinity (depth=0) and the careheat category data for the same day, for the whole of the Med and copy the nearest source value to each target cell.

Loading...
<Figure size 1000x500 with 4 Axes>

3. Apply the WorldCover Water Retention Mask

Read the roughly 320 m overviews of the ESA WorldCover 2021 tiles covering this region. Classes 0 (unmapped) and 80 (permanent water) are retained. Minimum resampling excludes a target cell if it contains mapped land; areas outside the mosaic remain retained. Unmapped areas are not confirmed water.

Apply the spatial mask to salinity across time and keep water_mask in the output (1 retained, 0 excluded).

<Figure size 640x480 with 2 Axes>

4. Save the Local Cube

Record the coordinate system, grid spacing, and source, then write the masked salinity and water_mask to downloaded_data/alboran_daily_demo_cube.zarr.

mode="w-" keeps an existing result from being overwritten. Choose a new output filename to run the write again.

[################                        ] | 41% Completed | 100.65 ms
/home/krasen/hackathon_websites/ocean_hackathon/.pixi/envs/default/lib/python3.13/site-packages/zarr/api/asynchronous.py:231: ZarrUserWarning: Consolidated metadata is currently not part in the Zarr format 3 specification. It may not be supported by other zarr implementations and may change in the future.
  warnings.warn(
[########################################] | 100% Completed | 1.51 sms

5. Open and Plot the Result

Read the local cube and plot sea-surface salinity for the selected day.

<Figure size 1600x600 with 4 Axes>