From 60555f1bccb141b2901304d0962f45e256b1d87d Mon Sep 17 00:00:00 2001 From: Krasen Samardzhiev Date: Mon, 22 Sep 2025 17:24:57 +0100 Subject: [PATCH 1/3] careheat prr generation --- PRR/careheat.ipynb | 1215 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1215 insertions(+) create mode 100644 PRR/careheat.ipynb diff --git a/PRR/careheat.ipynb b/PRR/careheat.ipynb new file mode 100644 index 00000000..a1f7f193 --- /dev/null +++ b/PRR/careheat.ipynb @@ -0,0 +1,1215 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "1f92ff5a", + "metadata": {}, + "source": [ + "# ESA Project Results Repository: Generating STAC collections with zarr files\n", + "\n", + "This notebook shows how to generate a valid STAC collection, which is a requirement to upload research outcomes to the [ESA Project Results Repository (PRR)](https://eoresults.esa.int/). The code below demonstrates how to perform the necessary steps using real data from the ESA project **deteCtion and threAts of maRinE HEAT waves (CAREHeat)**. The focus of CAREHeat is to improve existing extreme marine heatwave(MHW) detection algorithms, contributing to a better understanding of their impacts.\n", + "\n", + "\n", + "Check the [EarthCODE documentation](https://earthcode.esa.int/), and [PRR STAC introduction example](https://esa-earthcode.github.io/examples/prr-stac-introduction) for a more general introduction to STAC and the ESA PRR.\n", + "\n", + "\n", + "\n", + "🔗 Check the project website: [deteCtion and threAts of maRinE HEAT waves (CAREHeat) – Website](https://https://careheat.org/)\n", + "🔗 Check the eo4society page: [deteCtion and threAts of maRinE HEAT waves (CAREHeat) – eo4society](https://eo4society.esa.int/projects/careheat/)\n", + "\n", + "#### Acknowledgment \n", + "We gratefully acknowledge the **deteCtion and threAts of maRinE HEAT waves (CAREHeat)** for providing access to the data used in this example, as well as support in creating it." + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "3333ec9c", + "metadata": {}, + "outputs": [], + "source": [ + "# import libraries\n", + "import xarray as xr\n", + "from pystac import Item, Collection\n", + "import pystac\n", + "from datetime import datetime\n", + "from shapely.geometry import box, mapping\n", + "from xstac import xarray_to_stac\n", + "import glob\n", + "import json\n", + "import shapely\n", + "import numpy as np\n", + "import geopandas as gpd\n", + "import pandas as pd" + ] + }, + { + "cell_type": "markdown", + "id": "6161e2c3", + "metadata": {}, + "source": [ + "## 1. Generate the parent collection\n", + "\n", + "The root STAC Collection provides a general description of all project outputs which will be stored on the PRR.\n", + "The PRR STAC Collection template enforces some required fields that you need to provide in order to build its valid description. Most of these metadata fields should already be available and can be extracted from your data.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "869e46f3", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "
\n", + "
\n", + "
    \n", + " \n", + " \n", + " \n", + "
  • \n", + " type\n", + " \"Collection\"\n", + "
  • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
  • \n", + " id\n", + " \"careheat-marine-heatwaves-cold-spells\"\n", + "
  • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
  • \n", + " stac_version\n", + " \"1.1.0\"\n", + "
  • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
  • \n", + " description\n", + " \"Marine heatwaves (MHWs) and cold spells (MCSs) prepared by the National Research Council - Institute of Marine Sciences (CNR-ISMAR, Italy) within the ESA-funded CAREHeat project. The catalogues are based on the ESA-CCI sea surface temperature (SST) dataset (available from https://doi.org/10.24381/cds.cf608234) for the period 1982-2022, on a regular 1°x1° longitude-latitude grid.\"\n", + "
  • \n", + " \n", + " \n", + " \n", + " \n", + "
  • \n", + " links[] 0 items\n", + " \n", + "
  • \n", + " \n", + " \n", + " \n", + " \n", + "
  • \n", + " title\n", + " \"Marine heatwaves and cold spells events based on ESA-CCI SSTs\"\n", + "
  • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
  • \n", + " extent\n", + "
      \n", + " \n", + " \n", + " \n", + "
    • \n", + " spatial\n", + "
        \n", + " \n", + " \n", + "
      • \n", + " bbox[] 1 items\n", + " \n", + "
          \n", + " \n", + " \n", + "
        • \n", + " 0[] 4 items\n", + " \n", + "
            \n", + " \n", + " \n", + " \n", + "
          • \n", + " 0\n", + " -180\n", + "
          • \n", + " \n", + " \n", + " \n", + "
          \n", + " \n", + "
            \n", + " \n", + " \n", + " \n", + "
          • \n", + " 1\n", + " -90\n", + "
          • \n", + " \n", + " \n", + " \n", + "
          \n", + " \n", + "
            \n", + " \n", + " \n", + " \n", + "
          • \n", + " 2\n", + " 180\n", + "
          • \n", + " \n", + " \n", + " \n", + "
          \n", + " \n", + "
            \n", + " \n", + " \n", + " \n", + "
          • \n", + " 3\n", + " 90\n", + "
          • \n", + " \n", + " \n", + " \n", + "
          \n", + " \n", + "
        • \n", + " \n", + " \n", + "
        \n", + " \n", + "
      • \n", + " \n", + " \n", + "
      \n", + "
    • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
    • \n", + " temporal\n", + "
        \n", + " \n", + " \n", + "
      • \n", + " interval[] 1 items\n", + " \n", + "
          \n", + " \n", + " \n", + "
        • \n", + " 0[] 2 items\n", + " \n", + "
            \n", + " \n", + " \n", + " \n", + "
          • \n", + " 0\n", + " \"1982-01-01T00:00:00Z\"\n", + "
          • \n", + " \n", + " \n", + " \n", + "
          \n", + " \n", + "
            \n", + " \n", + " \n", + " \n", + "
          • \n", + " 1\n", + " \"2022-12-31T23:59:59Z\"\n", + "
          • \n", + " \n", + " \n", + " \n", + "
          \n", + " \n", + "
        • \n", + " \n", + " \n", + "
        \n", + " \n", + "
      • \n", + " \n", + " \n", + "
      \n", + "
    • \n", + " \n", + " \n", + " \n", + "
    \n", + "
  • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
  • \n", + " license\n", + " \"CC-BY-4.0\"\n", + "
  • \n", + " \n", + " \n", + " \n", + "
\n", + "
\n", + "
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# create the parent collection\n", + "collectionid = \"careheat-marine-heatwaves-cold-spells\"\n", + "\n", + "\n", + "collection = Collection.from_dict(\n", + " \n", + "{\n", + " \"type\": \"Collection\",\n", + " \"id\": collectionid,\n", + " \"stac_version\": \"1.1.0\",\n", + " \"title\": \"Marine heatwaves and cold spells events based on ESA-CCI SSTs\",\n", + " \"description\": \"Marine heatwaves (MHWs) and cold spells (MCSs) prepared by the National Research Council - Institute of Marine Sciences (CNR-ISMAR, Italy) within the ESA-funded CAREHeat project. The catalogues are based on the ESA-CCI sea surface temperature (SST) dataset (available from https://doi.org/10.24381/cds.cf608234) for the period 1982-2022, on a regular 1°x1° longitude-latitude grid.\",\n", + " \"extent\": {\n", + " \"spatial\": {\n", + " \"bbox\": [\n", + " [-180, -90, 180, 90]\n", + " ]\n", + " },\n", + " \"temporal\": {\n", + " \"interval\": [\n", + " [\n", + " \"1982-01-01T00:00:00Z\",\n", + " \"2022-12-31T23:59:59Z\"\n", + " ]\n", + " ]\n", + " }\n", + " },\n", + " \"license\": \"CC-BY-4.0\",\n", + " \"links\": []\n", + "\n", + "}\n", + "\n", + ")\n", + "\n", + "collection # visualise the metadata of your collection " + ] + }, + { + "cell_type": "markdown", + "id": "2ab07efc", + "metadata": {}, + "source": [ + "## 2. Create STAC Items and STAC Assets from original dataset \n", + "\n", + "The second step is to describe the different files as STAC Items and Assets. Take your time to decide how your data should be categorised to improve usability of the data, and ensure intuitive navigation through different items in the collections. There are multiple strategies for doing this and this tutorial demonstrate one of the possible ways of doing that. Examples of how other ESA projects are doing this are available in the [EarthCODE documentation](https://esa-earthcode.github.io/examples/prr-stac-introduction) ." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "79d59caa", + "metadata": {}, + "outputs": [], + "source": [ + "baseurl = '../../data/careheat-marine-heatwaves-cold-spells/'" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "2d611f80", + "metadata": {}, + "outputs": [], + "source": [ + "bbox = [-180, -90, 180, 90]\n", + "geometry = json.loads(json.dumps(shapely.box(*bbox).__geo_interface__))" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "b69d9dc2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['../../data/careheat-marine-heatwaves-cold-spells/CCI2D_1x1_ssa_MCS_categories_glo_1982-2022.nc',\n", + " '../../data/careheat-marine-heatwaves-cold-spells/CCI2D_1x1_ssa_MCS_metrics_glo_1982-2022.nc',\n", + " '../../data/careheat-marine-heatwaves-cold-spells/CCI2D_1x1_ssa_MHW_metrics_glo_1982-2022.nc',\n", + " '../../data/careheat-marine-heatwaves-cold-spells/CCI2D_1x1_ssa_MHW_categories_glo_1982-2022.nc',\n", + " '../../data/careheat-marine-heatwaves-cold-spells/CCI2D_1x1_MHW_categories_glo_1982-2022.nc',\n", + " '../../data/careheat-marine-heatwaves-cold-spells/CCI2D_1x1_MHW_metrics_glo_1982-2022.nc',\n", + " '../../data/careheat-marine-heatwaves-cold-spells/CCI2D_1x1_MCS_metrics_glo_1982-2022.nc',\n", + " '../../data/careheat-marine-heatwaves-cold-spells/CCI2D_1x1_MCS_categories_glo_1982-2022.nc']" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "files = glob.glob(baseurl + '*')\n", + "files" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ee61a0f7", + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "for file in files:\n", + "\n", + " # open the dataset and read metadata + convert to STAC\n", + " ds = xr.open_dataset(file)\n", + " detrended = 'Detrended (SSA) ' if '_ssa_' in file else ''\n", + " \n", + " template = {\n", + "\n", + " \"id\": f\"{collectionid}-{file.split('/')[-1][:-3].lower()}\",\n", + " \"type\": \"Feature\",\n", + " \"stac_version\": \"1.0.0\",\n", + " \"properties\": {\n", + " \"title\": detrended + ds.attrs['product'],\n", + " \"description\": detrended + ds.attrs['description'],\n", + " \"start_datetime\": pd.to_datetime(ds.attrs['climatologyPeriod'][0], format='%Y').strftime(\"%Y-%m-%dT%H:%M:%SZ\"),\n", + " \"end_datetime\": pd.to_datetime(ds.attrs['climatologyPeriod'][-1], format='%Y').strftime(\"%Y-%m-%dT%H:%M:%SZ\"),\n", + " \"license\": \"CC-BY-4.0\",\n", + " \"created\": pd.to_datetime(ds.attrs['date'], format='%Y-%m').strftime(\"%Y-%m-%dT%H:%M:%SZ\"),\n", + " \"git_information\": ds.attrs['git_information'],\n", + " \"website\": ds.attrs['website'],\n", + " \"version\": ds.attrs['version'],\n", + " \"changelog\": ds.attrs['changelog'],\n", + " \"institution\": ds.attrs['institution'],\n", + " \"author\": ds.attrs['author'],\n", + " \"contact\": ds.attrs['contact'],\n", + " },\n", + " \"geometry\": geometry,\n", + " \"bbox\": bbox,\n", + " \"assets\": {\n", + " \"data\": {\n", + " \"href\": f\"./{collectionid}/{file.split('/')[-1]}\", # or local path\n", + " \"type\": \"application/x-netcdf\",\n", + " \"roles\": [\"data\"],\n", + " \"title\": detrended + ds.attrs['product']\n", + " }\n", + " }\n", + " }\n", + " # 3. Generate the STAC Item\n", + " item = xarray_to_stac(\n", + " ds,\n", + " template,\n", + " temporal_dimension=\"time\" if 'time' in ds.coords else False,\n", + " x_dimension=False,\n", + " y_dimension=False\n", + " )\n", + "\n", + " # validate and add the STAC Item to the collection\n", + " item.validate()\n", + " collection.add_item(item)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "93172305", + "metadata": {}, + "outputs": [], + "source": [ + "# save the full self-contained collection\n", + "collection.normalize_and_save(\n", + " root_href=f'../../prr_preview/{collectionid}/',\n", + " catalog_type=pystac.CatalogType.SELF_CONTAINED\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "181da674", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "
\n", + "
\n", + "
    \n", + " \n", + " \n", + " \n", + "
  • \n", + " type\n", + " \"Collection\"\n", + "
  • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
  • \n", + " id\n", + " \"careheat-marine-heatwaves-cold-spells\"\n", + "
  • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
  • \n", + " stac_version\n", + " \"1.1.0\"\n", + "
  • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
  • \n", + " description\n", + " \"Marine heatwaves (MHWs) and cold spells (MCSs) prepared by the National Research Council - Institute of Marine Sciences (CNR-ISMAR, Italy) within the ESA-funded CAREHeat project. The catalogues are based on the ESA-CCI sea surface temperature (SST) dataset (available from https://doi.org/10.24381/cds.cf608234) for the period 1982-2022, on a regular 1°x1° longitude-latitude grid.\"\n", + "
  • \n", + " \n", + " \n", + " \n", + " \n", + "
  • \n", + " links[] 10 items\n", + " \n", + "
      \n", + " \n", + " \n", + " \n", + "
    • \n", + " 0\n", + "
        \n", + " \n", + " \n", + " \n", + "
      • \n", + " rel\n", + " \"root\"\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " href\n", + " \"/home/krasen/prr_preview/careheat-marine-heatwaves-cold-spells/collection.json\"\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " type\n", + " \"application/json\"\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " title\n", + " \"Marine heatwaves and cold spells events based on ESA-CCI SSTs\"\n", + "
      • \n", + " \n", + " \n", + " \n", + "
      \n", + "
    • \n", + " \n", + " \n", + " \n", + "
    \n", + " \n", + "
      \n", + " \n", + " \n", + " \n", + "
    • \n", + " 1\n", + "
        \n", + " \n", + " \n", + " \n", + "
      • \n", + " rel\n", + " \"item\"\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " href\n", + " \"/home/krasen/prr_preview/careheat-marine-heatwaves-cold-spells/careheat-marine-heatwaves-cold-spells-cci2d_1x1_ssa_mcs_categories_glo_1982-2022/careheat-marine-heatwaves-cold-spells-cci2d_1x1_ssa_mcs_categories_glo_1982-2022.json\"\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " type\n", + " \"application/geo+json\"\n", + "
      • \n", + " \n", + " \n", + " \n", + "
      \n", + "
    • \n", + " \n", + " \n", + " \n", + "
    \n", + " \n", + "
      \n", + " \n", + " \n", + " \n", + "
    • \n", + " 2\n", + "
        \n", + " \n", + " \n", + " \n", + "
      • \n", + " rel\n", + " \"item\"\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " href\n", + " \"/home/krasen/prr_preview/careheat-marine-heatwaves-cold-spells/careheat-marine-heatwaves-cold-spells-cci2d_1x1_ssa_mcs_metrics_glo_1982-2022/careheat-marine-heatwaves-cold-spells-cci2d_1x1_ssa_mcs_metrics_glo_1982-2022.json\"\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " type\n", + " \"application/geo+json\"\n", + "
      • \n", + " \n", + " \n", + " \n", + "
      \n", + "
    • \n", + " \n", + " \n", + " \n", + "
    \n", + " \n", + "
      \n", + " \n", + " \n", + " \n", + "
    • \n", + " 3\n", + "
        \n", + " \n", + " \n", + " \n", + "
      • \n", + " rel\n", + " \"item\"\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " href\n", + " \"/home/krasen/prr_preview/careheat-marine-heatwaves-cold-spells/careheat-marine-heatwaves-cold-spells-cci2d_1x1_ssa_mhw_metrics_glo_1982-2022/careheat-marine-heatwaves-cold-spells-cci2d_1x1_ssa_mhw_metrics_glo_1982-2022.json\"\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " type\n", + " \"application/geo+json\"\n", + "
      • \n", + " \n", + " \n", + " \n", + "
      \n", + "
    • \n", + " \n", + " \n", + " \n", + "
    \n", + " \n", + "
      \n", + " \n", + " \n", + " \n", + "
    • \n", + " 4\n", + "
        \n", + " \n", + " \n", + " \n", + "
      • \n", + " rel\n", + " \"item\"\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " href\n", + " \"/home/krasen/prr_preview/careheat-marine-heatwaves-cold-spells/careheat-marine-heatwaves-cold-spells-cci2d_1x1_ssa_mhw_categories_glo_1982-2022/careheat-marine-heatwaves-cold-spells-cci2d_1x1_ssa_mhw_categories_glo_1982-2022.json\"\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " type\n", + " \"application/geo+json\"\n", + "
      • \n", + " \n", + " \n", + " \n", + "
      \n", + "
    • \n", + " \n", + " \n", + " \n", + "
    \n", + " \n", + "
      \n", + " \n", + " \n", + " \n", + "
    • \n", + " 5\n", + "
        \n", + " \n", + " \n", + " \n", + "
      • \n", + " rel\n", + " \"item\"\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " href\n", + " \"/home/krasen/prr_preview/careheat-marine-heatwaves-cold-spells/careheat-marine-heatwaves-cold-spells-cci2d_1x1_mhw_categories_glo_1982-2022/careheat-marine-heatwaves-cold-spells-cci2d_1x1_mhw_categories_glo_1982-2022.json\"\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " type\n", + " \"application/geo+json\"\n", + "
      • \n", + " \n", + " \n", + " \n", + "
      \n", + "
    • \n", + " \n", + " \n", + " \n", + "
    \n", + " \n", + "
      \n", + " \n", + " \n", + " \n", + "
    • \n", + " 6\n", + "
        \n", + " \n", + " \n", + " \n", + "
      • \n", + " rel\n", + " \"item\"\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " href\n", + " \"/home/krasen/prr_preview/careheat-marine-heatwaves-cold-spells/careheat-marine-heatwaves-cold-spells-cci2d_1x1_mhw_metrics_glo_1982-2022/careheat-marine-heatwaves-cold-spells-cci2d_1x1_mhw_metrics_glo_1982-2022.json\"\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " type\n", + " \"application/geo+json\"\n", + "
      • \n", + " \n", + " \n", + " \n", + "
      \n", + "
    • \n", + " \n", + " \n", + " \n", + "
    \n", + " \n", + "
      \n", + " \n", + " \n", + " \n", + "
    • \n", + " 7\n", + "
        \n", + " \n", + " \n", + " \n", + "
      • \n", + " rel\n", + " \"item\"\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " href\n", + " \"/home/krasen/prr_preview/careheat-marine-heatwaves-cold-spells/careheat-marine-heatwaves-cold-spells-cci2d_1x1_mcs_metrics_glo_1982-2022/careheat-marine-heatwaves-cold-spells-cci2d_1x1_mcs_metrics_glo_1982-2022.json\"\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " type\n", + " \"application/geo+json\"\n", + "
      • \n", + " \n", + " \n", + " \n", + "
      \n", + "
    • \n", + " \n", + " \n", + " \n", + "
    \n", + " \n", + "
      \n", + " \n", + " \n", + " \n", + "
    • \n", + " 8\n", + "
        \n", + " \n", + " \n", + " \n", + "
      • \n", + " rel\n", + " \"item\"\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " href\n", + " \"/home/krasen/prr_preview/careheat-marine-heatwaves-cold-spells/careheat-marine-heatwaves-cold-spells-cci2d_1x1_mcs_categories_glo_1982-2022/careheat-marine-heatwaves-cold-spells-cci2d_1x1_mcs_categories_glo_1982-2022.json\"\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " type\n", + " \"application/geo+json\"\n", + "
      • \n", + " \n", + " \n", + " \n", + "
      \n", + "
    • \n", + " \n", + " \n", + " \n", + "
    \n", + " \n", + "
      \n", + " \n", + " \n", + " \n", + "
    • \n", + " 9\n", + "
        \n", + " \n", + " \n", + " \n", + "
      • \n", + " rel\n", + " \"self\"\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " href\n", + " \"/home/krasen/prr_preview/careheat-marine-heatwaves-cold-spells/collection.json\"\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " type\n", + " \"application/json\"\n", + "
      • \n", + " \n", + " \n", + " \n", + "
      \n", + "
    • \n", + " \n", + " \n", + " \n", + "
    \n", + " \n", + "
  • \n", + " \n", + " \n", + " \n", + " \n", + "
  • \n", + " title\n", + " \"Marine heatwaves and cold spells events based on ESA-CCI SSTs\"\n", + "
  • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
  • \n", + " extent\n", + "
      \n", + " \n", + " \n", + " \n", + "
    • \n", + " spatial\n", + "
        \n", + " \n", + " \n", + "
      • \n", + " bbox[] 1 items\n", + " \n", + "
          \n", + " \n", + " \n", + "
        • \n", + " 0[] 4 items\n", + " \n", + "
            \n", + " \n", + " \n", + " \n", + "
          • \n", + " 0\n", + " -180\n", + "
          • \n", + " \n", + " \n", + " \n", + "
          \n", + " \n", + "
            \n", + " \n", + " \n", + " \n", + "
          • \n", + " 1\n", + " -90\n", + "
          • \n", + " \n", + " \n", + " \n", + "
          \n", + " \n", + "
            \n", + " \n", + " \n", + " \n", + "
          • \n", + " 2\n", + " 180\n", + "
          • \n", + " \n", + " \n", + " \n", + "
          \n", + " \n", + "
            \n", + " \n", + " \n", + " \n", + "
          • \n", + " 3\n", + " 90\n", + "
          • \n", + " \n", + " \n", + " \n", + "
          \n", + " \n", + "
        • \n", + " \n", + " \n", + "
        \n", + " \n", + "
      • \n", + " \n", + " \n", + "
      \n", + "
    • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
    • \n", + " temporal\n", + "
        \n", + " \n", + " \n", + "
      • \n", + " interval[] 1 items\n", + " \n", + "
          \n", + " \n", + " \n", + "
        • \n", + " 0[] 2 items\n", + " \n", + "
            \n", + " \n", + " \n", + " \n", + "
          • \n", + " 0\n", + " \"1982-01-01T00:00:00Z\"\n", + "
          • \n", + " \n", + " \n", + " \n", + "
          \n", + " \n", + "
            \n", + " \n", + " \n", + " \n", + "
          • \n", + " 1\n", + " \"2022-12-31T23:59:59Z\"\n", + "
          • \n", + " \n", + " \n", + " \n", + "
          \n", + " \n", + "
        • \n", + " \n", + " \n", + "
        \n", + " \n", + "
      • \n", + " \n", + " \n", + "
      \n", + "
    • \n", + " \n", + " \n", + " \n", + "
    \n", + "
  • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
  • \n", + " license\n", + " \"CC-BY-4.0\"\n", + "
  • \n", + " \n", + " \n", + " \n", + "
\n", + "
\n", + "
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "collection" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "pangeo", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.13.3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} From db0806215ae9f8909e8333db6fdbfd356dbe75c3 Mon Sep 17 00:00:00 2001 From: Krasen Samardzhiev Date: Tue, 23 Sep 2025 16:15:18 +0100 Subject: [PATCH 2/3] update to careheat --- PRR/{careheat.ipynb => CareHeat_v2.ipynb} | 674 +++++++++++++++++++++- 1 file changed, 642 insertions(+), 32 deletions(-) rename PRR/{careheat.ipynb => CareHeat_v2.ipynb} (65%) diff --git a/PRR/careheat.ipynb b/PRR/CareHeat_v2.ipynb similarity index 65% rename from PRR/careheat.ipynb rename to PRR/CareHeat_v2.ipynb index a1f7f193..af2c8e86 100644 --- a/PRR/careheat.ipynb +++ b/PRR/CareHeat_v2.ipynb @@ -14,7 +14,7 @@ "\n", "\n", "\n", - "🔗 Check the project website: [deteCtion and threAts of maRinE HEAT waves (CAREHeat) – Website](https://https://careheat.org/)\n", + "🔗 Check the project website: [deteCtion and threAts of maRinE HEAT waves (CAREHeat) – Website](https://https://careheat.org/)
\n", "🔗 Check the eo4society page: [deteCtion and threAts of maRinE HEAT waves (CAREHeat) – eo4society](https://eo4society.esa.int/projects/careheat/)\n", "\n", "#### Acknowledgment \n", @@ -23,7 +23,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 1, "id": "3333ec9c", "metadata": {}, "outputs": [], @@ -40,7 +40,8 @@ "import shapely\n", "import numpy as np\n", "import geopandas as gpd\n", - "import pandas as pd" + "import pandas as pd\n", + "import os" ] }, { @@ -56,8 +57,8 @@ }, { "cell_type": "code", - "execution_count": 13, - "id": "869e46f3", + "execution_count": 2, + "id": "4029fcb4-4298-4236-8413-923d6bf64c11", "metadata": {}, "outputs": [ { @@ -315,7 +316,7 @@ "" ] }, - "execution_count": 13, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } @@ -371,17 +372,17 @@ { "cell_type": "code", "execution_count": 3, - "id": "79d59caa", + "id": "cf71e971-4b50-41ae-b70d-9ea8e15f92db", "metadata": {}, "outputs": [], "source": [ - "baseurl = '../../data/careheat-marine-heatwaves-cold-spells/'" + "baseurl = './data/careheat-marine-heatwaves-cold-spells/'" ] }, { "cell_type": "code", "execution_count": 4, - "id": "2d611f80", + "id": "f3030914-50f9-493e-abfd-4f7cca4fb1ab", "metadata": {}, "outputs": [], "source": [ @@ -392,41 +393,44 @@ { "cell_type": "code", "execution_count": 5, - "id": "b69d9dc2", + "id": "d13ee652-2b76-44f6-b7d1-1eaf69748a2e", "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "['../../data/careheat-marine-heatwaves-cold-spells/CCI2D_1x1_ssa_MCS_categories_glo_1982-2022.nc',\n", - " '../../data/careheat-marine-heatwaves-cold-spells/CCI2D_1x1_ssa_MCS_metrics_glo_1982-2022.nc',\n", - " '../../data/careheat-marine-heatwaves-cold-spells/CCI2D_1x1_ssa_MHW_metrics_glo_1982-2022.nc',\n", - " '../../data/careheat-marine-heatwaves-cold-spells/CCI2D_1x1_ssa_MHW_categories_glo_1982-2022.nc',\n", - " '../../data/careheat-marine-heatwaves-cold-spells/CCI2D_1x1_MHW_categories_glo_1982-2022.nc',\n", - " '../../data/careheat-marine-heatwaves-cold-spells/CCI2D_1x1_MHW_metrics_glo_1982-2022.nc',\n", - " '../../data/careheat-marine-heatwaves-cold-spells/CCI2D_1x1_MCS_metrics_glo_1982-2022.nc',\n", - " '../../data/careheat-marine-heatwaves-cold-spells/CCI2D_1x1_MCS_categories_glo_1982-2022.nc']" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "../../data/careheat-marine-heatwaves-cold-spells/CCI2D_1x1_ssa_MCS_categories_glo_1982-2022.nc\n", + "../../data/careheat-marine-heatwaves-cold-spells/CCI2D_1x1_ssa_MCS_metrics_glo_1982-2022.nc\n", + "../../data/careheat-marine-heatwaves-cold-spells/CCI2D_1x1_ssa_MHW_metrics_glo_1982-2022.nc\n", + "../../data/careheat-marine-heatwaves-cold-spells/CCI2D_1x1_ssa_MHW_categories_glo_1982-2022.nc\n", + "../../data/careheat-marine-heatwaves-cold-spells/CCI2D_1x1_MHW_categories_glo_1982-2022.nc\n", + "../../data/careheat-marine-heatwaves-cold-spells/CCI2D_1x1_MHW_metrics_glo_1982-2022.nc\n", + "../../data/careheat-marine-heatwaves-cold-spells/CCI2D_1x1_MCS_metrics_glo_1982-2022.nc\n", + "../../data/careheat-marine-heatwaves-cold-spells/CCI2D_1x1_MCS_categories_glo_1982-2022.nc\n" + ] } ], "source": [ - "files = glob.glob(baseurl + '*')\n", - "files" + "from pathlib import Path\n", + "baseurl = Path('../../data/careheat-marine-heatwaves-cold-spells/')\n", + "files = list(baseurl.glob(\"*.nc\"))\n", + "\n", + "# Convert to POSIX-style strings\n", + "file_paths = [f.as_posix() for f in files]\n", + "\n", + "for file in file_paths:\n", + " print(file)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "id": "ee61a0f7", "metadata": {}, "outputs": [], "source": [ - "\n", - "for file in files:\n", + "for file in file_paths:\n", "\n", " # open the dataset and read metadata + convert to STAC\n", " ds = xr.open_dataset(file)\n", @@ -477,6 +481,612 @@ " collection.add_item(item)" ] }, + { + "cell_type": "code", + "execution_count": 7, + "id": "2c2ee4de-afd1-41fb-9afd-73ccbfe8ef98", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "
\n", + "
\n", + "
    \n", + " \n", + " \n", + " \n", + "
  • \n", + " type\n", + " \"Collection\"\n", + "
  • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
  • \n", + " id\n", + " \"careheat-marine-heatwaves-cold-spells\"\n", + "
  • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
  • \n", + " stac_version\n", + " \"1.1.0\"\n", + "
  • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
  • \n", + " description\n", + " \"Marine heatwaves (MHWs) and cold spells (MCSs) prepared by the National Research Council - Institute of Marine Sciences (CNR-ISMAR, Italy) within the ESA-funded CAREHeat project. The catalogues are based on the ESA-CCI sea surface temperature (SST) dataset (available from https://doi.org/10.24381/cds.cf608234) for the period 1982-2022, on a regular 1°x1° longitude-latitude grid.\"\n", + "
  • \n", + " \n", + " \n", + " \n", + " \n", + "
  • \n", + " links[] 8 items\n", + " \n", + "
      \n", + " \n", + " \n", + " \n", + "
    • \n", + " 0\n", + "
        \n", + " \n", + " \n", + " \n", + "
      • \n", + " rel\n", + " \"item\"\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " href\n", + " None\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " type\n", + " \"application/geo+json\"\n", + "
      • \n", + " \n", + " \n", + " \n", + "
      \n", + "
    • \n", + " \n", + " \n", + " \n", + "
    \n", + " \n", + "
      \n", + " \n", + " \n", + " \n", + "
    • \n", + " 1\n", + "
        \n", + " \n", + " \n", + " \n", + "
      • \n", + " rel\n", + " \"item\"\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " href\n", + " None\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " type\n", + " \"application/geo+json\"\n", + "
      • \n", + " \n", + " \n", + " \n", + "
      \n", + "
    • \n", + " \n", + " \n", + " \n", + "
    \n", + " \n", + "
      \n", + " \n", + " \n", + " \n", + "
    • \n", + " 2\n", + "
        \n", + " \n", + " \n", + " \n", + "
      • \n", + " rel\n", + " \"item\"\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " href\n", + " None\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " type\n", + " \"application/geo+json\"\n", + "
      • \n", + " \n", + " \n", + " \n", + "
      \n", + "
    • \n", + " \n", + " \n", + " \n", + "
    \n", + " \n", + "
      \n", + " \n", + " \n", + " \n", + "
    • \n", + " 3\n", + "
        \n", + " \n", + " \n", + " \n", + "
      • \n", + " rel\n", + " \"item\"\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " href\n", + " None\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " type\n", + " \"application/geo+json\"\n", + "
      • \n", + " \n", + " \n", + " \n", + "
      \n", + "
    • \n", + " \n", + " \n", + " \n", + "
    \n", + " \n", + "
      \n", + " \n", + " \n", + " \n", + "
    • \n", + " 4\n", + "
        \n", + " \n", + " \n", + " \n", + "
      • \n", + " rel\n", + " \"item\"\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " href\n", + " None\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " type\n", + " \"application/geo+json\"\n", + "
      • \n", + " \n", + " \n", + " \n", + "
      \n", + "
    • \n", + " \n", + " \n", + " \n", + "
    \n", + " \n", + "
      \n", + " \n", + " \n", + " \n", + "
    • \n", + " 5\n", + "
        \n", + " \n", + " \n", + " \n", + "
      • \n", + " rel\n", + " \"item\"\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " href\n", + " None\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " type\n", + " \"application/geo+json\"\n", + "
      • \n", + " \n", + " \n", + " \n", + "
      \n", + "
    • \n", + " \n", + " \n", + " \n", + "
    \n", + " \n", + "
      \n", + " \n", + " \n", + " \n", + "
    • \n", + " 6\n", + "
        \n", + " \n", + " \n", + " \n", + "
      • \n", + " rel\n", + " \"item\"\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " href\n", + " None\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " type\n", + " \"application/geo+json\"\n", + "
      • \n", + " \n", + " \n", + " \n", + "
      \n", + "
    • \n", + " \n", + " \n", + " \n", + "
    \n", + " \n", + "
      \n", + " \n", + " \n", + " \n", + "
    • \n", + " 7\n", + "
        \n", + " \n", + " \n", + " \n", + "
      • \n", + " rel\n", + " \"item\"\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " href\n", + " None\n", + "
      • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
      • \n", + " type\n", + " \"application/geo+json\"\n", + "
      • \n", + " \n", + " \n", + " \n", + "
      \n", + "
    • \n", + " \n", + " \n", + " \n", + "
    \n", + " \n", + "
  • \n", + " \n", + " \n", + " \n", + " \n", + "
  • \n", + " title\n", + " \"Marine heatwaves and cold spells events based on ESA-CCI SSTs\"\n", + "
  • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
  • \n", + " extent\n", + "
      \n", + " \n", + " \n", + " \n", + "
    • \n", + " spatial\n", + "
        \n", + " \n", + " \n", + "
      • \n", + " bbox[] 1 items\n", + " \n", + "
          \n", + " \n", + " \n", + "
        • \n", + " 0[] 4 items\n", + " \n", + "
            \n", + " \n", + " \n", + " \n", + "
          • \n", + " 0\n", + " -180\n", + "
          • \n", + " \n", + " \n", + " \n", + "
          \n", + " \n", + "
            \n", + " \n", + " \n", + " \n", + "
          • \n", + " 1\n", + " -90\n", + "
          • \n", + " \n", + " \n", + " \n", + "
          \n", + " \n", + "
            \n", + " \n", + " \n", + " \n", + "
          • \n", + " 2\n", + " 180\n", + "
          • \n", + " \n", + " \n", + " \n", + "
          \n", + " \n", + "
            \n", + " \n", + " \n", + " \n", + "
          • \n", + " 3\n", + " 90\n", + "
          • \n", + " \n", + " \n", + " \n", + "
          \n", + " \n", + "
        • \n", + " \n", + " \n", + "
        \n", + " \n", + "
      • \n", + " \n", + " \n", + "
      \n", + "
    • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
    • \n", + " temporal\n", + "
        \n", + " \n", + " \n", + "
      • \n", + " interval[] 1 items\n", + " \n", + "
          \n", + " \n", + " \n", + "
        • \n", + " 0[] 2 items\n", + " \n", + "
            \n", + " \n", + " \n", + " \n", + "
          • \n", + " 0\n", + " \"1982-01-01T00:00:00Z\"\n", + "
          • \n", + " \n", + " \n", + " \n", + "
          \n", + " \n", + "
            \n", + " \n", + " \n", + " \n", + "
          • \n", + " 1\n", + " \"2022-12-31T23:59:59Z\"\n", + "
          • \n", + " \n", + " \n", + " \n", + "
          \n", + " \n", + "
        • \n", + " \n", + " \n", + "
        \n", + " \n", + "
      • \n", + " \n", + " \n", + "
      \n", + "
    • \n", + " \n", + " \n", + " \n", + "
    \n", + "
  • \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
  • \n", + " license\n", + " \"CC-BY-4.0\"\n", + "
  • \n", + " \n", + " \n", + " \n", + "
\n", + "
\n", + "
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "collection" + ] + }, { "cell_type": "code", "execution_count": 10, @@ -486,7 +1096,7 @@ "source": [ "# save the full self-contained collection\n", "collection.normalize_and_save(\n", - " root_href=f'../../prr_preview/{collectionid}/',\n", + " root_href=f'../../prr_preview/{collectionid}',\n", " catalog_type=pystac.CatalogType.SELF_CONTAINED\n", ")" ] @@ -494,7 +1104,7 @@ { "cell_type": "code", "execution_count": 11, - "id": "181da674", + "id": "6114f728-d75a-4447-87a9-673bf7b219ef", "metadata": {}, "outputs": [ { From ffca7d91ca49a9d2a2cd5ba5be5c7a160f2951cf Mon Sep 17 00:00:00 2001 From: Krasen Samardzhiev Date: Tue, 23 Sep 2025 16:35:29 +0100 Subject: [PATCH 3/3] added dimensions --- PRR/CareHeat_v2.ipynb | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/PRR/CareHeat_v2.ipynb b/PRR/CareHeat_v2.ipynb index af2c8e86..6b39a7c5 100644 --- a/PRR/CareHeat_v2.ipynb +++ b/PRR/CareHeat_v2.ipynb @@ -425,7 +425,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "id": "ee61a0f7", "metadata": {}, "outputs": [], @@ -472,8 +472,9 @@ " ds,\n", " template,\n", " temporal_dimension=\"time\" if 'time' in ds.coords else False,\n", - " x_dimension=False,\n", - " y_dimension=False\n", + " x_dimension='lon',\n", + " y_dimension='lat',\n", + " reference_system=False\n", " )\n", "\n", " # validate and add the STAC Item to the collection\n", @@ -483,7 +484,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "id": "2c2ee4de-afd1-41fb-9afd-73ccbfe8ef98", "metadata": {}, "outputs": [ @@ -1078,7 +1079,7 @@ "" ] }, - "execution_count": 7, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -1089,7 +1090,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 13, "id": "93172305", "metadata": {}, "outputs": [], @@ -1103,7 +1104,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 12, "id": "6114f728-d75a-4447-87a9-673bf7b219ef", "metadata": {}, "outputs": [ @@ -1791,7 +1792,7 @@ "" ] }, - "execution_count": 11, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -1799,6 +1800,14 @@ "source": [ "collection" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5b716252", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": {