{ "cells": [ { "cell_type": "markdown", "id": "91090a6b-bdfb-462b-8e87-179c4d4b9206", "metadata": {}, "source": [ "## Categorical gridded data" ] }, { "cell_type": "markdown", "id": "28a7ed3b-a0fe-4652-aa0b-69f7fa99c640", "metadata": {}, "source": [ "In this example, we will visualise \"type of vegetation\" data from the [ERA5 reanalysis dataset](https://cds.climate.copernicus.eu/datasets/reanalysis-era5-single-levels-monthly-means) in the C3S Climate Data Store." ] }, { "cell_type": "code", "execution_count": 1, "id": "18b514ba-73bc-46ec-b857-2c8bca3dc1c5", "metadata": {}, "outputs": [], "source": [ "import earthkit.data\n", "import earthkit.plots" ] }, { "cell_type": "markdown", "id": "013febb8-8af8-49ba-9347-aba81953ba59", "metadata": {}, "source": [ "To retrieve data from the CDS, we use the `\"cds\"` source type with `earthkit.data.from_source`. For more information, see the earthkit-data documentation page on [retrieving data from the CDS](https://earthkit-data.readthedocs.io/en/latest/examples/cds.html)." ] }, { "cell_type": "code", "execution_count": 2, "id": "575663e8-928a-40a3-ba3f-9254519b0f9f", "metadata": {}, "outputs": [], "source": [ "data = earthkit.data.from_source(\n", " \"cds\",\n", " \"reanalysis-era5-single-levels-monthly-means\",\n", " {\n", " \"product_type\": \"monthly_averaged_reanalysis\",\n", " \"year\": \"2018\",\n", " \"month\": \"05\",\n", " \"time\": \"00:00\",\n", " \"data_format\": \"grib\",\n", " \"download_format\": \"unarchived\",\n", " \"variable\": \"type_of_high_vegetation\",\n", " },\n", ")" ] }, { "cell_type": "markdown", "id": "eb9d3e8c-f3ce-4496-b3d1-9f2fee11fa0c", "metadata": {}, "source": [ "We can take a look at xarray's representation of the data to quickly see that the categorical `tvh` variable (type of high vegetation) has numerical floating point values." ] }, { "cell_type": "code", "execution_count": 3, "id": "fe6d8805-98fe-4e1e-81ba-eb988ded8d27", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset> Size: 4MB\n",
"Dimensions: (number: 1, time: 1, step: 1, surface: 1, latitude: 721,\n",
" longitude: 1440)\n",
"Coordinates:\n",
" * number (number) int64 8B 0\n",
" * time (time) datetime64[ns] 8B 2018-05-01\n",
" * step (step) timedelta64[ns] 8B 00:00:00\n",
" * surface (surface) float64 8B 0.0\n",
" * latitude (latitude) float64 6kB 90.0 89.75 89.5 ... -89.5 -89.75 -90.0\n",
" * longitude (longitude) float64 12kB 0.0 0.25 0.5 0.75 ... 359.2 359.5 359.8\n",
" valid_time (time, step) datetime64[ns] 8B ...\n",
"Data variables:\n",
" tvh (number, time, step, surface, latitude, longitude) float32 4MB ...\n",
"Attributes:\n",
" GRIB_edition: 1\n",
" GRIB_centre: ecmf\n",
" GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts\n",
" GRIB_subCentre: 0\n",
" Conventions: CF-1.7\n",
" institution: European Centre for Medium-Range Weather Forecasts\n",
" history: 2025-02-03T09:13 GRIB to CDM+CF via cfgrib-0.9.1...