{ "cells": [ { "cell_type": "markdown", "id": "0", "metadata": {}, "source": [ "# ClimateDT → EOPF HEALPix Converter\n", "\n", "Packages ClimateDT IFS-NEMO output (natively HEALPix level 7) into EOPF-compliant zarr.\n", "Data is retrieved via Polytope — no regridding needed.\n", "\n", "**Pipeline**: download GRIB via Polytope → direct zarr packaging → inject STAC" ] }, { "cell_type": "code", "execution_count": null, "id": "1", "metadata": {}, "outputs": [], "source": [ "import logging\n", "from pathlib import Path\n", "\n", "from healpix_convert.converters.climatedt import ClimateDTConverter\n", "\n", "logging.basicConfig(level=logging.INFO, format=\"%(asctime)s %(levelname)s %(message)s\")" ] }, { "cell_type": "markdown", "id": "2", "metadata": {}, "source": [ "## Configuration — Surface fields" ] }, { "cell_type": "code", "execution_count": null, "id": "3", "metadata": {}, "outputs": [], "source": [ "DATE = \"20200102\"\n", "TIME = \"0100\"\n", "LOCAL_DIR = Path(\".\")\n", "OUTPUT = LOCAL_DIR / f\"S00__ADF_CLMDT_{DATE}T{TIME}.zarr\"\n", "\n", "converter = ClimateDTConverter(\n", " date=DATE,\n", " time=TIME,\n", " params=\"134/165/166/167/168\", # sp, u10, v10, t2m, d2m\n", " levtype=\"sfc\",\n", " local_dir=LOCAL_DIR,\n", ")" ] }, { "cell_type": "markdown", "id": "4", "metadata": {}, "source": [ "## Step 1 — Prepare (download via Polytope)" ] }, { "cell_type": "code", "execution_count": null, "id": "5", "metadata": {}, "outputs": [], "source": [ "result = converter.prepare(output_path=str(OUTPUT))\n", "print(f\"Chunks: {result.n_chunks} | Timesteps: {result.n_times}\")" ] }, { "cell_type": "markdown", "id": "6", "metadata": {}, "source": [ "## Step 2 — Convert (all spatial chunks)" ] }, { "cell_type": "code", "execution_count": null, "id": "7", "metadata": {}, "outputs": [], "source": [ "for i in range(result.n_chunks):\n", " converter.convert_group(i)\n", " if (i + 1) % 20 == 0:\n", " print(f\" {i+1}/{result.n_chunks}\")" ] }, { "cell_type": "markdown", "id": "8", "metadata": {}, "source": [ "## Step 3 — Consolidate" ] }, { "cell_type": "code", "execution_count": null, "id": "9", "metadata": {}, "outputs": [], "source": [ "converter.consolidate()\n", "print(f\"Done: {OUTPUT}\")" ] }, { "cell_type": "markdown", "id": "10", "metadata": {}, "source": [ "## Ocean 3D (optional)\n", "\n", "Uncomment to also retrieve NEMO ocean temperature on 5 depth levels." ] }, { "cell_type": "code", "execution_count": null, "id": "11", "metadata": {}, "outputs": [], "source": [ "# converter_ocean = ClimateDTConverter(\n", "# date = DATE,\n", "# time = \"0000\",\n", "# params = \"263501\", # avg_thetao\n", "# levtype = \"o3d\",\n", "# levelist = \"1/2/3/4/5\",\n", "# local_dir = LOCAL_DIR,\n", "# )\n", "# result_ocean = converter_ocean.prepare(output_path=str(LOCAL_DIR / \"S00__ADF_CLDTO_ocean.zarr\"))\n", "# for i in range(result_ocean.n_chunks):\n", "# converter_ocean.convert_group(i)\n", "# converter_ocean.consolidate()" ] }, { "cell_type": "markdown", "id": "12", "metadata": {}, "source": [ "## Validation" ] }, { "cell_type": "code", "execution_count": null, "id": "13", "metadata": {}, "outputs": [], "source": [ "import healpy as hp\n", "import matplotlib.pyplot as plt\n", "import xarray as xr\n", "\n", "ds = xr.open_zarr(str(OUTPUT), consolidated=True)\n", "print(ds)\n", "\n", "data = ds[\"t2m\"].isel(time=0).values\n", "hp.mollview(\n", " hp.reorder(data - 273.15, n2r=True),\n", " flip=\"geo\",\n", " nest=False,\n", " cmap=\"RdBu_r\",\n", " min=-50,\n", " max=50,\n", " unit=\"°C\",\n", " title=\"ClimateDT T2m — HEALPix level 7\",\n", ")\n", "plt.show()" ] } ], "metadata": { "language_info": { "name": "python", "pygments_lexer": "ipython3" } }, "nbformat": 4, "nbformat_minor": 5 }