How to publish model outputs (netcdf/zarr) to the EDITO Data Catalog using Stacify?

EDITO has a Data API. The official platform documentation explains how to Interact with the Data API. Since the data publishing process involves a few steps that might not be obvious for some users, the EDITO-Model Lab team, more specifically DMI, created Stacify: a tool to create SpatioTemporal Asset Catalog (STAC) catalogs from directories of NetCDF/Zarr datasets. In this tutorial we will explain how to use it for your applicaiton.

How to prepare your netcdf/zarr model output for publishing?

<aside> 💡

Make your netCDF (or Zarr) CF convention compliant. Check your netCDF file in a CF Comliance Checker.

</aside>

Below are some (non-exhaustive) examples that could be improved in your netCDF using Python and xarray to make it CF compliant.

Spatial Coordinates

# rename coordinates
data.rename({"x": "lon", "y": "lat"})

# update coordinate attributes
data["lon"].attrs.update({
"standard_name": "longitude",
"long_name": "longitude",
"units": "degrees_east",
"axis": "X"
})
data["lat"].attrs.update({
"standard_name": "latitude",
"long_name": "latitude",
"units": "degrees_north",
"axis": "Y"
})

Update/enrich data variable attributes

data.attrs = {
"long_name": "Habitat Suitability Index for Zostera Marina",
"units": "1",
"description": "Habitat Suitability Index (HSI) for Zostera Marina in the Dutch Wadden Sea. Values range from 0 (unsuitable) to 1 (highly suitable), based on salinity, depth, and velocity thresholds. Created within the Horizon Europe EDITO-Model Lab project.",
"coordinates": "lon lat time",
"source": "Derived from habitat suitability modeling (Delft3D FM and D-Eco Impact).",
"institution": "Deltares",
"license": "CC-BY-4.0",
"date_created": datetime.now().strftime("%Y-%m-%d"),
"history": "Post-processed from model output using Python and xarray.",
"crs": "EPSG:4326"
}

Add global attributes

# Convert to dataset
ds = data.to_dataset(name="HSI_Zostera_Marina")
# Add global attributes
ds.attrs.update({
    "Conventions": "CF-1.8",
    "title": "Habitat Suitability Index (HSI) for Zostera marina in the Dutch Wadden Sea",
    "summary": "Gridded Habitat Suitability Index (HSI) for Zostera marina for 2017, based on ecological model outputs.",
    "institution": "Deltares",
    "source": "Habitat modeling using Delft3D FM and D-Eco Impact with ecological suitability thresholds.",
    "history": "Created " + datetime.now().strftime("%Y-%m-%d") + " using Python, xarray, and rioxarray.",
    "references": "<https://gitlab.mercator-ocean.fr/pub/edito-model-lab/tutorials/-/blob/master/sources/Habitat_Suitability_Mapping/tutorial.md>",
    "license": "CC-BY-4.0"
})

Time coordinate

ds["time"].attrs.update({
"standard_name": "time",
"long_name": "time",
"calendar": "standard"
})
ds["time"].encoding["calendar"] = ds["time"].attrs.pop("calendar")

CRS

ds["spatial_ref"].attrs.update({
"grid_mapping_name": "latitude_longitude",
"epsg_code": "EPSG:4326",
"semi_major_axis": 6378137.0,
"inverse_flattening": 298.257223563
})

Stacify workflow

image.png

Stacify Workflow Diagram illustrating the process of uploading netCDF/zarr model outputs to the EDITO Data Catalog.

<aside> 💡

Work in CMD or BASH Terminal (e.g. within VS Code Studio or Jupyter Notebook)

</aside>

Clone stacify and install its requirements