Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save j08lue/193291492504d61ad9f446e8459380ef to your computer and use it in GitHub Desktop.
Save j08lue/193291492504d61ad9f446e8459380ef to your computer and use it in GitHub Desktop.
Reformat OS-Climate Hazard model output from filename-based to multidimensional dataset
{
"cells": [
{
"cell_type": "markdown",
"id": "7019a57c-c539-42b3-a6a4-cc043e3548cc",
"metadata": {},
"source": [
"# Transforming OS-C Hazard Zarr output to a multidimensional datacube\n",
"\n",
"Sample conversion code with rudimentary metadata for two chronic heat indicators"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "a8d31efb-aff5-4589-9ff1-8d9b887c8a69",
"metadata": {},
"outputs": [],
"source": [
"import re\n",
"import json\n",
"import datetime\n",
"from pathlib import Path\n",
"\n",
"import zarr\n",
"import xarray as xr\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"import xstac\n",
"import pystac\n",
"import shapely.geometry\n",
"\n",
"from hazard.sources.osc_zarr import OscZarr"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "d5e37886-517f-45ed-9b06-6be918f42b01",
"metadata": {},
"outputs": [],
"source": [
"if True:\n",
" INDICATOR_NAME = \"days_tas_above\"\n",
" INDICATOR_ATTRS = {\n",
" \"long_name\": \"Days per year for which the average near-surface temperature 'tas' is above a threshold\",\n",
" \"units\": \"Days per year\"\n",
" }\n",
" COORD_ATTRS = {\n",
" \"temperature\": {\n",
" \"long_name\": \"Threshold temperature\",\n",
" \"units\": \"Degrees Celsius\"\n",
" },\n",
" \"time\": {\n",
" \"long_name\": \"Predicted year\"\n",
" }\n",
" }\n",
" PATH = \"./sample_data/uk_60km_dta/\"\n",
" \n",
"else:\n",
" INDICATOR_NAME = \"mean_degree_days_v2_above\"\n",
" INDICATOR_ATTRS = {\n",
" \"long_name\": \"Time integral of absolute difference in temperature of the medium over a reference temperature\",\n",
" \"units\": \"Days per year\"\n",
" }\n",
" COORD_ATTRS = {\n",
" \"temperature\": {\n",
" \"long_name\": \"Reference temperature\",\n",
" \"units\": \"Degrees Celsius\"\n",
" },\n",
" \"time\": {\n",
" \"long_name\": \"Predicted year\"\n",
" }\n",
" }\n",
" PATH = \"./sample_data/uk_60km_dd_28/\""
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "3539c1cb-031b-49ab-a341-0f5bb00b450a",
"metadata": {},
"outputs": [],
"source": [
"OUTPUT_DIR = Path(f\"./converted-{INDICATOR_NAME}\")\n",
"OUTPUT_DIR.mkdir(exist_ok=True, parents=True)\n",
"OUTPUT_PATH = OUTPUT_DIR / f\"{INDICATOR_NAME}.zarr\""
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "bba9512c",
"metadata": {},
"outputs": [],
"source": [
"store = zarr.DirectoryStore(PATH)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "331d0c40-9654-4a98-8a25-39fb799a6d91",
"metadata": {},
"outputs": [],
"source": [
"keys = [key for key in store.listdir(\"chronic_heat/osc/v2\") if re.match(\".*_\\d{4}$\", key) is not None]"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "b4342e40-2724-4be9-8520-fb4966538746",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['days_tas_above_20c_ukcp18_rcp85_2030',\n",
" 'days_tas_above_20c_ukcp18_rcp85_2040',\n",
" 'days_tas_above_20c_ukcp18_rcp85_2050',\n",
" 'days_tas_above_20c_ukcp18_rcp85_2060',\n",
" 'days_tas_above_20c_ukcp18_rcp85_2070',\n",
" 'days_tas_above_20c_ukcp18_rcp85_2080',\n",
" 'days_tas_above_20c_ukcp18_rcp85_2090',\n",
" 'days_tas_above_25c_ukcp18_rcp85_2030',\n",
" 'days_tas_above_25c_ukcp18_rcp85_2040',\n",
" 'days_tas_above_25c_ukcp18_rcp85_2050',\n",
" 'days_tas_above_25c_ukcp18_rcp85_2060',\n",
" 'days_tas_above_25c_ukcp18_rcp85_2070',\n",
" 'days_tas_above_25c_ukcp18_rcp85_2080',\n",
" 'days_tas_above_25c_ukcp18_rcp85_2090',\n",
" 'days_tas_above_28c_ukcp18_rcp85_2030',\n",
" 'days_tas_above_28c_ukcp18_rcp85_2040',\n",
" 'days_tas_above_28c_ukcp18_rcp85_2050',\n",
" 'days_tas_above_28c_ukcp18_rcp85_2060',\n",
" 'days_tas_above_28c_ukcp18_rcp85_2070',\n",
" 'days_tas_above_28c_ukcp18_rcp85_2080',\n",
" 'days_tas_above_28c_ukcp18_rcp85_2090',\n",
" 'days_tas_above_30c_ukcp18_rcp85_2030',\n",
" 'days_tas_above_30c_ukcp18_rcp85_2040',\n",
" 'days_tas_above_30c_ukcp18_rcp85_2050',\n",
" 'days_tas_above_30c_ukcp18_rcp85_2060',\n",
" 'days_tas_above_30c_ukcp18_rcp85_2070',\n",
" 'days_tas_above_30c_ukcp18_rcp85_2080',\n",
" 'days_tas_above_30c_ukcp18_rcp85_2090',\n",
" 'days_tas_above_32c_ukcp18_rcp85_2030',\n",
" 'days_tas_above_32c_ukcp18_rcp85_2040',\n",
" 'days_tas_above_32c_ukcp18_rcp85_2050',\n",
" 'days_tas_above_32c_ukcp18_rcp85_2060',\n",
" 'days_tas_above_32c_ukcp18_rcp85_2070',\n",
" 'days_tas_above_32c_ukcp18_rcp85_2080',\n",
" 'days_tas_above_32c_ukcp18_rcp85_2090',\n",
" 'days_tas_above_35c_ukcp18_rcp85_2030',\n",
" 'days_tas_above_35c_ukcp18_rcp85_2040',\n",
" 'days_tas_above_35c_ukcp18_rcp85_2050',\n",
" 'days_tas_above_35c_ukcp18_rcp85_2060',\n",
" 'days_tas_above_35c_ukcp18_rcp85_2070',\n",
" 'days_tas_above_35c_ukcp18_rcp85_2080',\n",
" 'days_tas_above_35c_ukcp18_rcp85_2090',\n",
" 'days_tas_above_40c_ukcp18_rcp85_2030',\n",
" 'days_tas_above_40c_ukcp18_rcp85_2040',\n",
" 'days_tas_above_40c_ukcp18_rcp85_2050',\n",
" 'days_tas_above_40c_ukcp18_rcp85_2060',\n",
" 'days_tas_above_40c_ukcp18_rcp85_2070',\n",
" 'days_tas_above_40c_ukcp18_rcp85_2080',\n",
" 'days_tas_above_40c_ukcp18_rcp85_2090',\n",
" 'days_tas_above_45c_ukcp18_rcp85_2030',\n",
" 'days_tas_above_45c_ukcp18_rcp85_2040',\n",
" 'days_tas_above_45c_ukcp18_rcp85_2050',\n",
" 'days_tas_above_45c_ukcp18_rcp85_2060',\n",
" 'days_tas_above_45c_ukcp18_rcp85_2070',\n",
" 'days_tas_above_45c_ukcp18_rcp85_2080',\n",
" 'days_tas_above_45c_ukcp18_rcp85_2090',\n",
" 'days_tas_above_50c_ukcp18_rcp85_2030',\n",
" 'days_tas_above_50c_ukcp18_rcp85_2040',\n",
" 'days_tas_above_50c_ukcp18_rcp85_2050',\n",
" 'days_tas_above_50c_ukcp18_rcp85_2060',\n",
" 'days_tas_above_50c_ukcp18_rcp85_2070',\n",
" 'days_tas_above_50c_ukcp18_rcp85_2080',\n",
" 'days_tas_above_50c_ukcp18_rcp85_2090',\n",
" 'days_tas_above_55c_ukcp18_rcp85_2030',\n",
" 'days_tas_above_55c_ukcp18_rcp85_2040',\n",
" 'days_tas_above_55c_ukcp18_rcp85_2050',\n",
" 'days_tas_above_55c_ukcp18_rcp85_2060',\n",
" 'days_tas_above_55c_ukcp18_rcp85_2070',\n",
" 'days_tas_above_55c_ukcp18_rcp85_2080',\n",
" 'days_tas_above_55c_ukcp18_rcp85_2090']"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"keys"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "dbc7d2db-8fda-4d4e-9f29-fb265de436dd",
"metadata": {},
"outputs": [],
"source": [
"def parse_path(key, indicator_name):\n",
" match = re.match(f\"{indicator_name}_([0-9]+)c_([a-zA-Z0-9]+)_([a-zA-Z0-9]+)_(\\d+)*\", key)\n",
" if match is None:\n",
" raise ValueError(f\"Unable to match string '{key}'\")\n",
" temperature, gcm, scenario, year = match.groups()\n",
" index = dict(temperature=int(temperature), gcm=gcm, scenario=scenario, time=datetime.datetime(int(year), 1, 1))\n",
" return index"
]
},
{
"cell_type": "markdown",
"id": "4e263ac7-8b54-4ec2-b66f-15b53839a909",
"metadata": {},
"source": [
"## Read all arrays\n",
"\n",
"Logic for reading all relevant data goes here"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "b4cb885d-cb8f-4dc8-82f9-3647d15776fd",
"metadata": {},
"outputs": [],
"source": [
"arrs = []\n",
"indexes = []\n",
"\n",
"target = OscZarr(store=store)\n",
"\n",
"for key in keys:\n",
" indicator = target.read(f\"chronic_heat/osc/v2/{key}\")\n",
"\n",
" da = indicator.isel(index=0) \n",
" arrs.append(da)\n",
"\n",
" index = parse_path(key, indicator_name=INDICATOR_NAME)\n",
"\n",
" model = {}\n",
" for key in [\"gcm\", \"scenario\"]:\n",
" model[key] = index.pop(key)\n",
" \n",
" indexes.append(index)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "76adc26f-5d8a-4842-a69e-47f9adbef2d8",
"metadata": {},
"outputs": [],
"source": [
"sample_array = arrs[0]"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "57577121-c29f-4c71-9ae0-9074a8194920",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div><svg style=\"position: absolute; width: 0; height: 0; overflow: hidden\">\n",
"<defs>\n",
"<symbol id=\"icon-database\" viewBox=\"0 0 32 32\">\n",
"<path d=\"M16 0c-8.837 0-16 2.239-16 5v4c0 2.761 7.163 5 16 5s16-2.239 16-5v-4c0-2.761-7.163-5-16-5z\"></path>\n",
"<path d=\"M16 17c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n",
"<path d=\"M16 26c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n",
"</symbol>\n",
"<symbol id=\"icon-file-text2\" viewBox=\"0 0 32 32\">\n",
"<path d=\"M28.681 7.159c-0.694-0.947-1.662-2.053-2.724-3.116s-2.169-2.030-3.116-2.724c-1.612-1.182-2.393-1.319-2.841-1.319h-15.5c-1.378 0-2.5 1.121-2.5 2.5v27c0 1.378 1.122 2.5 2.5 2.5h23c1.378 0 2.5-1.122 2.5-2.5v-19.5c0-0.448-0.137-1.23-1.319-2.841zM24.543 5.457c0.959 0.959 1.712 1.825 2.268 2.543h-4.811v-4.811c0.718 0.556 1.584 1.309 2.543 2.268zM28 29.5c0 0.271-0.229 0.5-0.5 0.5h-23c-0.271 0-0.5-0.229-0.5-0.5v-27c0-0.271 0.229-0.5 0.5-0.5 0 0 15.499-0 15.5 0v7c0 0.552 0.448 1 1 1h7v19.5z\"></path>\n",
"<path d=\"M23 26h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
"<path d=\"M23 22h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
"<path d=\"M23 18h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
"</symbol>\n",
"</defs>\n",
"</svg>\n",
"<style>/* CSS stylesheet for displaying xarray objects in jupyterlab.\n",
" *\n",
" */\n",
"\n",
":root {\n",
" --xr-font-color0: var(--jp-content-font-color0, rgba(0, 0, 0, 1));\n",
" --xr-font-color2: var(--jp-content-font-color2, rgba(0, 0, 0, 0.54));\n",
" --xr-font-color3: var(--jp-content-font-color3, rgba(0, 0, 0, 0.38));\n",
" --xr-border-color: var(--jp-border-color2, #e0e0e0);\n",
" --xr-disabled-color: var(--jp-layout-color3, #bdbdbd);\n",
" --xr-background-color: var(--jp-layout-color0, white);\n",
" --xr-background-color-row-even: var(--jp-layout-color1, white);\n",
" --xr-background-color-row-odd: var(--jp-layout-color2, #eeeeee);\n",
"}\n",
"\n",
"html[theme=dark],\n",
"body[data-theme=dark],\n",
"body.vscode-dark {\n",
" --xr-font-color0: rgba(255, 255, 255, 1);\n",
" --xr-font-color2: rgba(255, 255, 255, 0.54);\n",
" --xr-font-color3: rgba(255, 255, 255, 0.38);\n",
" --xr-border-color: #1F1F1F;\n",
" --xr-disabled-color: #515151;\n",
" --xr-background-color: #111111;\n",
" --xr-background-color-row-even: #111111;\n",
" --xr-background-color-row-odd: #313131;\n",
"}\n",
"\n",
".xr-wrap {\n",
" display: block !important;\n",
" min-width: 300px;\n",
" max-width: 700px;\n",
"}\n",
"\n",
".xr-text-repr-fallback {\n",
" /* fallback to plain text repr when CSS is not injected (untrusted notebook) */\n",
" display: none;\n",
"}\n",
"\n",
".xr-header {\n",
" padding-top: 6px;\n",
" padding-bottom: 6px;\n",
" margin-bottom: 4px;\n",
" border-bottom: solid 1px var(--xr-border-color);\n",
"}\n",
"\n",
".xr-header > div,\n",
".xr-header > ul {\n",
" display: inline;\n",
" margin-top: 0;\n",
" margin-bottom: 0;\n",
"}\n",
"\n",
".xr-obj-type,\n",
".xr-array-name {\n",
" margin-left: 2px;\n",
" margin-right: 10px;\n",
"}\n",
"\n",
".xr-obj-type {\n",
" color: var(--xr-font-color2);\n",
"}\n",
"\n",
".xr-sections {\n",
" padding-left: 0 !important;\n",
" display: grid;\n",
" grid-template-columns: 150px auto auto 1fr 20px 20px;\n",
"}\n",
"\n",
".xr-section-item {\n",
" display: contents;\n",
"}\n",
"\n",
".xr-section-item input {\n",
" display: none;\n",
"}\n",
"\n",
".xr-section-item input + label {\n",
" color: var(--xr-disabled-color);\n",
"}\n",
"\n",
".xr-section-item input:enabled + label {\n",
" cursor: pointer;\n",
" color: var(--xr-font-color2);\n",
"}\n",
"\n",
".xr-section-item input:enabled + label:hover {\n",
" color: var(--xr-font-color0);\n",
"}\n",
"\n",
".xr-section-summary {\n",
" grid-column: 1;\n",
" color: var(--xr-font-color2);\n",
" font-weight: 500;\n",
"}\n",
"\n",
".xr-section-summary > span {\n",
" display: inline-block;\n",
" padding-left: 0.5em;\n",
"}\n",
"\n",
".xr-section-summary-in:disabled + label {\n",
" color: var(--xr-font-color2);\n",
"}\n",
"\n",
".xr-section-summary-in + label:before {\n",
" display: inline-block;\n",
" content: '►';\n",
" font-size: 11px;\n",
" width: 15px;\n",
" text-align: center;\n",
"}\n",
"\n",
".xr-section-summary-in:disabled + label:before {\n",
" color: var(--xr-disabled-color);\n",
"}\n",
"\n",
".xr-section-summary-in:checked + label:before {\n",
" content: '▼';\n",
"}\n",
"\n",
".xr-section-summary-in:checked + label > span {\n",
" display: none;\n",
"}\n",
"\n",
".xr-section-summary,\n",
".xr-section-inline-details {\n",
" padding-top: 4px;\n",
" padding-bottom: 4px;\n",
"}\n",
"\n",
".xr-section-inline-details {\n",
" grid-column: 2 / -1;\n",
"}\n",
"\n",
".xr-section-details {\n",
" display: none;\n",
" grid-column: 1 / -1;\n",
" margin-bottom: 5px;\n",
"}\n",
"\n",
".xr-section-summary-in:checked ~ .xr-section-details {\n",
" display: contents;\n",
"}\n",
"\n",
".xr-array-wrap {\n",
" grid-column: 1 / -1;\n",
" display: grid;\n",
" grid-template-columns: 20px auto;\n",
"}\n",
"\n",
".xr-array-wrap > label {\n",
" grid-column: 1;\n",
" vertical-align: top;\n",
"}\n",
"\n",
".xr-preview {\n",
" color: var(--xr-font-color3);\n",
"}\n",
"\n",
".xr-array-preview,\n",
".xr-array-data {\n",
" padding: 0 5px !important;\n",
" grid-column: 2;\n",
"}\n",
"\n",
".xr-array-data,\n",
".xr-array-in:checked ~ .xr-array-preview {\n",
" display: none;\n",
"}\n",
"\n",
".xr-array-in:checked ~ .xr-array-data,\n",
".xr-array-preview {\n",
" display: inline-block;\n",
"}\n",
"\n",
".xr-dim-list {\n",
" display: inline-block !important;\n",
" list-style: none;\n",
" padding: 0 !important;\n",
" margin: 0;\n",
"}\n",
"\n",
".xr-dim-list li {\n",
" display: inline-block;\n",
" padding: 0;\n",
" margin: 0;\n",
"}\n",
"\n",
".xr-dim-list:before {\n",
" content: '(';\n",
"}\n",
"\n",
".xr-dim-list:after {\n",
" content: ')';\n",
"}\n",
"\n",
".xr-dim-list li:not(:last-child):after {\n",
" content: ',';\n",
" padding-right: 5px;\n",
"}\n",
"\n",
".xr-has-index {\n",
" font-weight: bold;\n",
"}\n",
"\n",
".xr-var-list,\n",
".xr-var-item {\n",
" display: contents;\n",
"}\n",
"\n",
".xr-var-item > div,\n",
".xr-var-item label,\n",
".xr-var-item > .xr-var-name span {\n",
" background-color: var(--xr-background-color-row-even);\n",
" margin-bottom: 0;\n",
"}\n",
"\n",
".xr-var-item > .xr-var-name:hover span {\n",
" padding-right: 5px;\n",
"}\n",
"\n",
".xr-var-list > li:nth-child(odd) > div,\n",
".xr-var-list > li:nth-child(odd) > label,\n",
".xr-var-list > li:nth-child(odd) > .xr-var-name span {\n",
" background-color: var(--xr-background-color-row-odd);\n",
"}\n",
"\n",
".xr-var-name {\n",
" grid-column: 1;\n",
"}\n",
"\n",
".xr-var-dims {\n",
" grid-column: 2;\n",
"}\n",
"\n",
".xr-var-dtype {\n",
" grid-column: 3;\n",
" text-align: right;\n",
" color: var(--xr-font-color2);\n",
"}\n",
"\n",
".xr-var-preview {\n",
" grid-column: 4;\n",
"}\n",
"\n",
".xr-index-preview {\n",
" grid-column: 2 / 5;\n",
" color: var(--xr-font-color2);\n",
"}\n",
"\n",
".xr-var-name,\n",
".xr-var-dims,\n",
".xr-var-dtype,\n",
".xr-preview,\n",
".xr-attrs dt {\n",
" white-space: nowrap;\n",
" overflow: hidden;\n",
" text-overflow: ellipsis;\n",
" padding-right: 10px;\n",
"}\n",
"\n",
".xr-var-name:hover,\n",
".xr-var-dims:hover,\n",
".xr-var-dtype:hover,\n",
".xr-attrs dt:hover {\n",
" overflow: visible;\n",
" width: auto;\n",
" z-index: 1;\n",
"}\n",
"\n",
".xr-var-attrs,\n",
".xr-var-data,\n",
".xr-index-data {\n",
" display: none;\n",
" background-color: var(--xr-background-color) !important;\n",
" padding-bottom: 5px !important;\n",
"}\n",
"\n",
".xr-var-attrs-in:checked ~ .xr-var-attrs,\n",
".xr-var-data-in:checked ~ .xr-var-data,\n",
".xr-index-data-in:checked ~ .xr-index-data {\n",
" display: block;\n",
"}\n",
"\n",
".xr-var-data > table {\n",
" float: right;\n",
"}\n",
"\n",
".xr-var-name span,\n",
".xr-var-data,\n",
".xr-index-name div,\n",
".xr-index-data,\n",
".xr-attrs {\n",
" padding-left: 25px !important;\n",
"}\n",
"\n",
".xr-attrs,\n",
".xr-var-attrs,\n",
".xr-var-data,\n",
".xr-index-data {\n",
" grid-column: 1 / -1;\n",
"}\n",
"\n",
"dl.xr-attrs {\n",
" padding: 0;\n",
" margin: 0;\n",
" display: grid;\n",
" grid-template-columns: 125px auto;\n",
"}\n",
"\n",
".xr-attrs dt,\n",
".xr-attrs dd {\n",
" padding: 0;\n",
" margin: 0;\n",
" float: left;\n",
" padding-right: 10px;\n",
" width: auto;\n",
"}\n",
"\n",
".xr-attrs dt {\n",
" font-weight: normal;\n",
" grid-column: 1;\n",
"}\n",
"\n",
".xr-attrs dt:hover span {\n",
" display: inline-block;\n",
" background: var(--xr-background-color);\n",
" padding-right: 10px;\n",
"}\n",
"\n",
".xr-attrs dd {\n",
" grid-column: 2;\n",
" white-space: pre-wrap;\n",
" word-break: break-all;\n",
"}\n",
"\n",
".xr-icon-database,\n",
".xr-icon-file-text2,\n",
".xr-no-icon {\n",
" display: inline-block;\n",
" vertical-align: middle;\n",
" width: 1em;\n",
" height: 1.5em !important;\n",
" stroke-width: 0;\n",
" stroke: currentColor;\n",
" fill: currentColor;\n",
"}\n",
"</style><pre class='xr-text-repr-fallback'>&lt;xarray.DataArray &#x27;from-zarr-930a2315c97d55e7dcacd8f87eef7f2f&#x27; (latitude: 18,\n",
" longitude: 26)&gt;\n",
"dask.array&lt;getitem, shape=(18, 26), dtype=float32, chunksize=(18, 26), chunktype=numpy.ndarray&gt;\n",
"Coordinates:\n",
" * latitude (latitude) float64 60.86 60.13 59.41 ... 49.97 49.25 48.52\n",
" * longitude (longitude) float64 -13.41 -12.68 -11.95 ... 3.286 4.011 4.737\n",
" index int64 0\n",
" spatial_ref int64 0</pre><div class='xr-wrap' style='display:none'><div class='xr-header'><div class='xr-obj-type'>xarray.DataArray</div><div class='xr-array-name'>'from-zarr-930a2315c97d55e7dcacd8f87eef7f2f'</div><ul class='xr-dim-list'><li><span class='xr-has-index'>latitude</span>: 18</li><li><span class='xr-has-index'>longitude</span>: 26</li></ul></div><ul class='xr-sections'><li class='xr-section-item'><div class='xr-array-wrap'><input id='section-140d0db5-c9a2-4246-a3c0-c7e65624e31f' class='xr-array-in' type='checkbox' checked><label for='section-140d0db5-c9a2-4246-a3c0-c7e65624e31f' title='Show/hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-array-preview xr-preview'><span>dask.array&lt;chunksize=(18, 26), meta=np.ndarray&gt;</span></div><div class='xr-array-data'><table>\n",
" <tr>\n",
" <td>\n",
" <table style=\"border-collapse: collapse;\">\n",
" <thead>\n",
" <tr>\n",
" <td> </td>\n",
" <th> Array </th>\n",
" <th> Chunk </th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" \n",
" <tr>\n",
" <th> Bytes </th>\n",
" <td> 1.83 kiB </td>\n",
" <td> 1.83 kiB </td>\n",
" </tr>\n",
" \n",
" <tr>\n",
" <th> Shape </th>\n",
" <td> (18, 26) </td>\n",
" <td> (18, 26) </td>\n",
" </tr>\n",
" <tr>\n",
" <th> Dask graph </th>\n",
" <td colspan=\"2\"> 1 chunks in 3 graph layers </td>\n",
" </tr>\n",
" <tr>\n",
" <th> Data type </th>\n",
" <td colspan=\"2\"> float32 numpy.ndarray </td>\n",
" </tr>\n",
" </tbody>\n",
" </table>\n",
" </td>\n",
" <td>\n",
" <svg width=\"170\" height=\"133\" style=\"stroke:rgb(0,0,0);stroke-width:1\" >\n",
"\n",
" <!-- Horizontal lines -->\n",
" <line x1=\"0\" y1=\"0\" x2=\"120\" y2=\"0\" style=\"stroke-width:2\" />\n",
" <line x1=\"0\" y1=\"83\" x2=\"120\" y2=\"83\" style=\"stroke-width:2\" />\n",
"\n",
" <!-- Vertical lines -->\n",
" <line x1=\"0\" y1=\"0\" x2=\"0\" y2=\"83\" style=\"stroke-width:2\" />\n",
" <line x1=\"120\" y1=\"0\" x2=\"120\" y2=\"83\" style=\"stroke-width:2\" />\n",
"\n",
" <!-- Colored Rectangle -->\n",
" <polygon points=\"0.0,0.0 120.0,0.0 120.0,83.07692307692308 0.0,83.07692307692308\" style=\"fill:#ECB172A0;stroke-width:0\"/>\n",
"\n",
" <!-- Text -->\n",
" <text x=\"60.000000\" y=\"103.076923\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" >26</text>\n",
" <text x=\"140.000000\" y=\"41.538462\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" transform=\"rotate(0,140.000000,41.538462)\">18</text>\n",
"</svg>\n",
" </td>\n",
" </tr>\n",
"</table></div></div></li><li class='xr-section-item'><input id='section-d1eb0eca-4c17-4a45-a1d4-7daf56e1bd98' class='xr-section-summary-in' type='checkbox' checked><label for='section-d1eb0eca-4c17-4a45-a1d4-7daf56e1bd98' class='xr-section-summary' >Coordinates: <span>(4)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>latitude</span></div><div class='xr-var-dims'>(latitude)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>60.86 60.13 59.41 ... 49.25 48.52</div><input id='attrs-59bffc41-9cdd-4270-8df2-d15499709caa' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-59bffc41-9cdd-4270-8df2-d15499709caa' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-46fac7b4-efd1-4e88-b410-90f57b5fa327' class='xr-var-data-in' type='checkbox'><label for='data-46fac7b4-efd1-4e88-b410-90f57b5fa327' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([60.859008, 60.133274, 59.407539, 58.681805, 57.956071, 57.230337,\n",
" 56.504603, 55.778869, 55.053135, 54.327401, 53.601666, 52.875932,\n",
" 52.150198, 51.424464, 50.69873 , 49.972996, 49.247262, 48.521527])</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>longitude</span></div><div class='xr-var-dims'>(longitude)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>-13.41 -12.68 ... 4.011 4.737</div><input id='attrs-90f296b6-d7d0-4d77-9101-9181495336eb' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-90f296b6-d7d0-4d77-9101-9181495336eb' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-cd7c5db2-39a0-429a-b63c-024df48d4048' class='xr-var-data-in' type='checkbox'><label for='data-cd7c5db2-39a0-429a-b63c-024df48d4048' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([-13.406328, -12.680593, -11.954859, -11.229125, -10.503391, -9.777657,\n",
" -9.051923, -8.326189, -7.600454, -6.87472 , -6.148986, -5.423252,\n",
" -4.697518, -3.971784, -3.24605 , -2.520315, -1.794581, -1.068847,\n",
" -0.343113, 0.382621, 1.108355, 1.834089, 2.559824, 3.285558,\n",
" 4.011292, 4.737026])</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>index</span></div><div class='xr-var-dims'>()</div><div class='xr-var-dtype'>int64</div><div class='xr-var-preview xr-preview'>0</div><input id='attrs-f5542e98-c210-4df3-9279-ceb09e34ef68' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-f5542e98-c210-4df3-9279-ceb09e34ef68' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-28ed862b-97b6-4e16-9aa9-f97de28034a0' class='xr-var-data-in' type='checkbox'><label for='data-28ed862b-97b6-4e16-9aa9-f97de28034a0' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array(0)</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>spatial_ref</span></div><div class='xr-var-dims'>()</div><div class='xr-var-dtype'>int64</div><div class='xr-var-preview xr-preview'>0</div><input id='attrs-fe23bd4a-440c-46e2-919d-4d3deb08616e' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-fe23bd4a-440c-46e2-919d-4d3deb08616e' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-65e0d310-9eaf-4698-a93b-ab4437adeb9a' class='xr-var-data-in' type='checkbox'><label for='data-65e0d310-9eaf-4698-a93b-ab4437adeb9a' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>crs_wkt :</span></dt><dd>GEOGCS[&quot;WGS 84&quot;,DATUM[&quot;WGS_1984&quot;,SPHEROID[&quot;WGS 84&quot;,6378137,298.257223563,AUTHORITY[&quot;EPSG&quot;,&quot;7030&quot;]],AUTHORITY[&quot;EPSG&quot;,&quot;6326&quot;]],PRIMEM[&quot;Greenwich&quot;,0,AUTHORITY[&quot;EPSG&quot;,&quot;8901&quot;]],UNIT[&quot;degree&quot;,0.0174532925199433,AUTHORITY[&quot;EPSG&quot;,&quot;9122&quot;]],AXIS[&quot;Latitude&quot;,NORTH],AXIS[&quot;Longitude&quot;,EAST],AUTHORITY[&quot;EPSG&quot;,&quot;4326&quot;]]</dd><dt><span>semi_major_axis :</span></dt><dd>6378137.0</dd><dt><span>semi_minor_axis :</span></dt><dd>6356752.314245179</dd><dt><span>inverse_flattening :</span></dt><dd>298.257223563</dd><dt><span>reference_ellipsoid_name :</span></dt><dd>WGS 84</dd><dt><span>longitude_of_prime_meridian :</span></dt><dd>0.0</dd><dt><span>prime_meridian_name :</span></dt><dd>Greenwich</dd><dt><span>geographic_crs_name :</span></dt><dd>WGS 84</dd><dt><span>horizontal_datum_name :</span></dt><dd>World Geodetic System 1984</dd><dt><span>grid_mapping_name :</span></dt><dd>latitude_longitude</dd><dt><span>spatial_ref :</span></dt><dd>GEOGCS[&quot;WGS 84&quot;,DATUM[&quot;WGS_1984&quot;,SPHEROID[&quot;WGS 84&quot;,6378137,298.257223563,AUTHORITY[&quot;EPSG&quot;,&quot;7030&quot;]],AUTHORITY[&quot;EPSG&quot;,&quot;6326&quot;]],PRIMEM[&quot;Greenwich&quot;,0,AUTHORITY[&quot;EPSG&quot;,&quot;8901&quot;]],UNIT[&quot;degree&quot;,0.0174532925199433,AUTHORITY[&quot;EPSG&quot;,&quot;9122&quot;]],AXIS[&quot;Latitude&quot;,NORTH],AXIS[&quot;Longitude&quot;,EAST],AUTHORITY[&quot;EPSG&quot;,&quot;4326&quot;]]</dd></dl></div><div class='xr-var-data'><pre>array(0)</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-a048fca5-28e1-4aa2-a276-800aaf49c87a' class='xr-section-summary-in' type='checkbox' ><label for='section-a048fca5-28e1-4aa2-a276-800aaf49c87a' class='xr-section-summary' >Indexes: <span>(2)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-index-name'><div>latitude</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-512fd986-4365-40db-af1f-aba350eb0067' class='xr-index-data-in' type='checkbox'/><label for='index-512fd986-4365-40db-af1f-aba350eb0067' title='Show/Hide index repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-index-data'><pre>PandasIndex(Index([ 60.85900777563262, 60.13327363529232, 59.40753949495202,\n",
" 58.68180535461172, 57.95607121427142, 57.23033707393112,\n",
" 56.50460293359082, 55.77886879325052, 55.05313465291022,\n",
" 54.327400512569916, 53.601666372229616, 52.875932231889315,\n",
" 52.150198091549015, 51.424463951208715, 50.698729810868414,\n",
" 49.972995670528114, 49.247261530187814, 48.52152738984751],\n",
" dtype=&#x27;float64&#x27;, name=&#x27;latitude&#x27;))</pre></div></li><li class='xr-var-item'><div class='xr-index-name'><div>longitude</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-7b73eab7-87b3-43da-8cdd-1f72e4aa2f37' class='xr-index-data-in' type='checkbox'/><label for='index-7b73eab7-87b3-43da-8cdd-1f72e4aa2f37' title='Show/Hide index repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-index-data'><pre>PandasIndex(Index([-13.406327527558583, -12.680593387218282, -11.954859246877982,\n",
" -11.229125106537682, -10.503390966197381, -9.77765682585708,\n",
" -9.051922685516782, -8.326188545176482, -7.600454404836181,\n",
" -6.87472026449588, -6.14898612415558, -5.4232519838152795,\n",
" -4.69751784347498, -3.9717837031346797, -3.2460495627943793,\n",
" -2.520315422454079, -1.7945812821137785, -1.0688471417734782,\n",
" -0.3431130014331778, 0.38262113890712257, 1.108355279247423,\n",
" 1.8340894195877233, 2.5598235599280237, 3.2855577002683223,\n",
" 4.011291840608623, 4.737025980948923],\n",
" dtype=&#x27;float64&#x27;, name=&#x27;longitude&#x27;))</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-6f30f705-1241-489f-9b86-b96e5836a2f9' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-6f30f705-1241-489f-9b86-b96e5836a2f9' class='xr-section-summary' title='Expand/collapse section'>Attributes: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'></dl></div></li></ul></div></div>"
],
"text/plain": [
"<xarray.DataArray 'from-zarr-930a2315c97d55e7dcacd8f87eef7f2f' (latitude: 18,\n",
" longitude: 26)>\n",
"dask.array<getitem, shape=(18, 26), dtype=float32, chunksize=(18, 26), chunktype=numpy.ndarray>\n",
"Coordinates:\n",
" * latitude (latitude) float64 60.86 60.13 59.41 ... 49.97 49.25 48.52\n",
" * longitude (longitude) float64 -13.41 -12.68 -11.95 ... 3.286 4.011 4.737\n",
" index int64 0\n",
" spatial_ref int64 0"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sample_array"
]
},
{
"cell_type": "markdown",
"id": "8a60b8c9-70d6-44bd-b5ed-84d3ad0b4144",
"metadata": {},
"source": [
"## Create dimensions"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "1e716b41-56e7-4583-828f-29d8b3551294",
"metadata": {},
"outputs": [],
"source": [
"coords = {key: set() for key in indexes[0]}\n",
"for index in indexes:\n",
" for key, value in index.items():\n",
" coords[key].add(value)\n",
"\n",
"for key in coords:\n",
" coords[key] = sorted(coords[key])"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "f3eada04-927e-43f3-b821-93b0f78b8b3d",
"metadata": {},
"outputs": [],
"source": [
"for key in sample_array.dims:\n",
" coords[key] = arrs[0].coords[key].values"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "3162b3f8-6c35-4f8e-834f-00f82dd0692c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'temperature': [20, 25, 28, 30, 32, 35, 40, 45, 50, 55],\n",
" 'time': [datetime.datetime(2030, 1, 1, 0, 0),\n",
" datetime.datetime(2040, 1, 1, 0, 0),\n",
" datetime.datetime(2050, 1, 1, 0, 0),\n",
" datetime.datetime(2060, 1, 1, 0, 0),\n",
" datetime.datetime(2070, 1, 1, 0, 0),\n",
" datetime.datetime(2080, 1, 1, 0, 0),\n",
" datetime.datetime(2090, 1, 1, 0, 0)],\n",
" 'latitude': array([60.85900778, 60.13327364, 59.40753949, 58.68180535, 57.95607121,\n",
" 57.23033707, 56.50460293, 55.77886879, 55.05313465, 54.32740051,\n",
" 53.60166637, 52.87593223, 52.15019809, 51.42446395, 50.69872981,\n",
" 49.97299567, 49.24726153, 48.52152739]),\n",
" 'longitude': array([-13.40632753, -12.68059339, -11.95485925, -11.22912511,\n",
" -10.50339097, -9.77765683, -9.05192269, -8.32618855,\n",
" -7.6004544 , -6.87472026, -6.14898612, -5.42325198,\n",
" -4.69751784, -3.9717837 , -3.24604956, -2.52031542,\n",
" -1.79458128, -1.06884714, -0.343113 , 0.38262114,\n",
" 1.10835528, 1.83408942, 2.55982356, 3.2855577 ,\n",
" 4.01129184, 4.73702598])}"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"coords"
]
},
{
"cell_type": "markdown",
"id": "cae94675-5a36-4a23-8853-907920a29d32",
"metadata": {},
"source": [
"## Create a master array and fill it"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "49cedd07-c8e1-4947-91b6-12f10c3a4353",
"metadata": {},
"outputs": [],
"source": [
"shape = [len(values) for values in coords.values()]"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "d6632478-5463-43ef-8125-76ea5fcf99da",
"metadata": {},
"outputs": [],
"source": [
"da = xr.DataArray(np.zeros(shape, dtype=arrs[0].dtype), coords=coords, name=INDICATOR_NAME)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "bfcb2de3-2df3-492a-a6c9-9cd511bdc48a",
"metadata": {},
"outputs": [],
"source": [
"for arr, index in zip(arrs, indexes):\n",
" da.loc[index] = arr"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "b7d15c71-8fa3-4b0d-94b1-9b93e78ce8b0",
"metadata": {},
"outputs": [],
"source": [
"for key in sample_array.dims:\n",
" da.coords[key].attrs.update(sample_array.coords[key].attrs)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "ec568d37-4dd6-4391-9d70-bf47f56117ee",
"metadata": {},
"outputs": [],
"source": [
"for key, attrs in COORD_ATTRS.items():\n",
" da.coords[key].attrs.update(attrs)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "855c411e-3910-4e3d-8e27-f90d613a515f",
"metadata": {},
"outputs": [],
"source": [
"da.attrs.update(INDICATOR_ATTRS)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "1569e775-3a20-4e4e-bf1a-d0574154db06",
"metadata": {},
"outputs": [],
"source": [
"ds = da.to_dataset()"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "84caa6a0-f13b-4257-9628-5e7dc8f68a84",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div><svg style=\"position: absolute; width: 0; height: 0; overflow: hidden\">\n",
"<defs>\n",
"<symbol id=\"icon-database\" viewBox=\"0 0 32 32\">\n",
"<path d=\"M16 0c-8.837 0-16 2.239-16 5v4c0 2.761 7.163 5 16 5s16-2.239 16-5v-4c0-2.761-7.163-5-16-5z\"></path>\n",
"<path d=\"M16 17c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n",
"<path d=\"M16 26c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n",
"</symbol>\n",
"<symbol id=\"icon-file-text2\" viewBox=\"0 0 32 32\">\n",
"<path d=\"M28.681 7.159c-0.694-0.947-1.662-2.053-2.724-3.116s-2.169-2.030-3.116-2.724c-1.612-1.182-2.393-1.319-2.841-1.319h-15.5c-1.378 0-2.5 1.121-2.5 2.5v27c0 1.378 1.122 2.5 2.5 2.5h23c1.378 0 2.5-1.122 2.5-2.5v-19.5c0-0.448-0.137-1.23-1.319-2.841zM24.543 5.457c0.959 0.959 1.712 1.825 2.268 2.543h-4.811v-4.811c0.718 0.556 1.584 1.309 2.543 2.268zM28 29.5c0 0.271-0.229 0.5-0.5 0.5h-23c-0.271 0-0.5-0.229-0.5-0.5v-27c0-0.271 0.229-0.5 0.5-0.5 0 0 15.499-0 15.5 0v7c0 0.552 0.448 1 1 1h7v19.5z\"></path>\n",
"<path d=\"M23 26h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
"<path d=\"M23 22h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
"<path d=\"M23 18h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
"</symbol>\n",
"</defs>\n",
"</svg>\n",
"<style>/* CSS stylesheet for displaying xarray objects in jupyterlab.\n",
" *\n",
" */\n",
"\n",
":root {\n",
" --xr-font-color0: var(--jp-content-font-color0, rgba(0, 0, 0, 1));\n",
" --xr-font-color2: var(--jp-content-font-color2, rgba(0, 0, 0, 0.54));\n",
" --xr-font-color3: var(--jp-content-font-color3, rgba(0, 0, 0, 0.38));\n",
" --xr-border-color: var(--jp-border-color2, #e0e0e0);\n",
" --xr-disabled-color: var(--jp-layout-color3, #bdbdbd);\n",
" --xr-background-color: var(--jp-layout-color0, white);\n",
" --xr-background-color-row-even: var(--jp-layout-color1, white);\n",
" --xr-background-color-row-odd: var(--jp-layout-color2, #eeeeee);\n",
"}\n",
"\n",
"html[theme=dark],\n",
"body[data-theme=dark],\n",
"body.vscode-dark {\n",
" --xr-font-color0: rgba(255, 255, 255, 1);\n",
" --xr-font-color2: rgba(255, 255, 255, 0.54);\n",
" --xr-font-color3: rgba(255, 255, 255, 0.38);\n",
" --xr-border-color: #1F1F1F;\n",
" --xr-disabled-color: #515151;\n",
" --xr-background-color: #111111;\n",
" --xr-background-color-row-even: #111111;\n",
" --xr-background-color-row-odd: #313131;\n",
"}\n",
"\n",
".xr-wrap {\n",
" display: block !important;\n",
" min-width: 300px;\n",
" max-width: 700px;\n",
"}\n",
"\n",
".xr-text-repr-fallback {\n",
" /* fallback to plain text repr when CSS is not injected (untrusted notebook) */\n",
" display: none;\n",
"}\n",
"\n",
".xr-header {\n",
" padding-top: 6px;\n",
" padding-bottom: 6px;\n",
" margin-bottom: 4px;\n",
" border-bottom: solid 1px var(--xr-border-color);\n",
"}\n",
"\n",
".xr-header > div,\n",
".xr-header > ul {\n",
" display: inline;\n",
" margin-top: 0;\n",
" margin-bottom: 0;\n",
"}\n",
"\n",
".xr-obj-type,\n",
".xr-array-name {\n",
" margin-left: 2px;\n",
" margin-right: 10px;\n",
"}\n",
"\n",
".xr-obj-type {\n",
" color: var(--xr-font-color2);\n",
"}\n",
"\n",
".xr-sections {\n",
" padding-left: 0 !important;\n",
" display: grid;\n",
" grid-template-columns: 150px auto auto 1fr 20px 20px;\n",
"}\n",
"\n",
".xr-section-item {\n",
" display: contents;\n",
"}\n",
"\n",
".xr-section-item input {\n",
" display: none;\n",
"}\n",
"\n",
".xr-section-item input + label {\n",
" color: var(--xr-disabled-color);\n",
"}\n",
"\n",
".xr-section-item input:enabled + label {\n",
" cursor: pointer;\n",
" color: var(--xr-font-color2);\n",
"}\n",
"\n",
".xr-section-item input:enabled + label:hover {\n",
" color: var(--xr-font-color0);\n",
"}\n",
"\n",
".xr-section-summary {\n",
" grid-column: 1;\n",
" color: var(--xr-font-color2);\n",
" font-weight: 500;\n",
"}\n",
"\n",
".xr-section-summary > span {\n",
" display: inline-block;\n",
" padding-left: 0.5em;\n",
"}\n",
"\n",
".xr-section-summary-in:disabled + label {\n",
" color: var(--xr-font-color2);\n",
"}\n",
"\n",
".xr-section-summary-in + label:before {\n",
" display: inline-block;\n",
" content: '►';\n",
" font-size: 11px;\n",
" width: 15px;\n",
" text-align: center;\n",
"}\n",
"\n",
".xr-section-summary-in:disabled + label:before {\n",
" color: var(--xr-disabled-color);\n",
"}\n",
"\n",
".xr-section-summary-in:checked + label:before {\n",
" content: '▼';\n",
"}\n",
"\n",
".xr-section-summary-in:checked + label > span {\n",
" display: none;\n",
"}\n",
"\n",
".xr-section-summary,\n",
".xr-section-inline-details {\n",
" padding-top: 4px;\n",
" padding-bottom: 4px;\n",
"}\n",
"\n",
".xr-section-inline-details {\n",
" grid-column: 2 / -1;\n",
"}\n",
"\n",
".xr-section-details {\n",
" display: none;\n",
" grid-column: 1 / -1;\n",
" margin-bottom: 5px;\n",
"}\n",
"\n",
".xr-section-summary-in:checked ~ .xr-section-details {\n",
" display: contents;\n",
"}\n",
"\n",
".xr-array-wrap {\n",
" grid-column: 1 / -1;\n",
" display: grid;\n",
" grid-template-columns: 20px auto;\n",
"}\n",
"\n",
".xr-array-wrap > label {\n",
" grid-column: 1;\n",
" vertical-align: top;\n",
"}\n",
"\n",
".xr-preview {\n",
" color: var(--xr-font-color3);\n",
"}\n",
"\n",
".xr-array-preview,\n",
".xr-array-data {\n",
" padding: 0 5px !important;\n",
" grid-column: 2;\n",
"}\n",
"\n",
".xr-array-data,\n",
".xr-array-in:checked ~ .xr-array-preview {\n",
" display: none;\n",
"}\n",
"\n",
".xr-array-in:checked ~ .xr-array-data,\n",
".xr-array-preview {\n",
" display: inline-block;\n",
"}\n",
"\n",
".xr-dim-list {\n",
" display: inline-block !important;\n",
" list-style: none;\n",
" padding: 0 !important;\n",
" margin: 0;\n",
"}\n",
"\n",
".xr-dim-list li {\n",
" display: inline-block;\n",
" padding: 0;\n",
" margin: 0;\n",
"}\n",
"\n",
".xr-dim-list:before {\n",
" content: '(';\n",
"}\n",
"\n",
".xr-dim-list:after {\n",
" content: ')';\n",
"}\n",
"\n",
".xr-dim-list li:not(:last-child):after {\n",
" content: ',';\n",
" padding-right: 5px;\n",
"}\n",
"\n",
".xr-has-index {\n",
" font-weight: bold;\n",
"}\n",
"\n",
".xr-var-list,\n",
".xr-var-item {\n",
" display: contents;\n",
"}\n",
"\n",
".xr-var-item > div,\n",
".xr-var-item label,\n",
".xr-var-item > .xr-var-name span {\n",
" background-color: var(--xr-background-color-row-even);\n",
" margin-bottom: 0;\n",
"}\n",
"\n",
".xr-var-item > .xr-var-name:hover span {\n",
" padding-right: 5px;\n",
"}\n",
"\n",
".xr-var-list > li:nth-child(odd) > div,\n",
".xr-var-list > li:nth-child(odd) > label,\n",
".xr-var-list > li:nth-child(odd) > .xr-var-name span {\n",
" background-color: var(--xr-background-color-row-odd);\n",
"}\n",
"\n",
".xr-var-name {\n",
" grid-column: 1;\n",
"}\n",
"\n",
".xr-var-dims {\n",
" grid-column: 2;\n",
"}\n",
"\n",
".xr-var-dtype {\n",
" grid-column: 3;\n",
" text-align: right;\n",
" color: var(--xr-font-color2);\n",
"}\n",
"\n",
".xr-var-preview {\n",
" grid-column: 4;\n",
"}\n",
"\n",
".xr-index-preview {\n",
" grid-column: 2 / 5;\n",
" color: var(--xr-font-color2);\n",
"}\n",
"\n",
".xr-var-name,\n",
".xr-var-dims,\n",
".xr-var-dtype,\n",
".xr-preview,\n",
".xr-attrs dt {\n",
" white-space: nowrap;\n",
" overflow: hidden;\n",
" text-overflow: ellipsis;\n",
" padding-right: 10px;\n",
"}\n",
"\n",
".xr-var-name:hover,\n",
".xr-var-dims:hover,\n",
".xr-var-dtype:hover,\n",
".xr-attrs dt:hover {\n",
" overflow: visible;\n",
" width: auto;\n",
" z-index: 1;\n",
"}\n",
"\n",
".xr-var-attrs,\n",
".xr-var-data,\n",
".xr-index-data {\n",
" display: none;\n",
" background-color: var(--xr-background-color) !important;\n",
" padding-bottom: 5px !important;\n",
"}\n",
"\n",
".xr-var-attrs-in:checked ~ .xr-var-attrs,\n",
".xr-var-data-in:checked ~ .xr-var-data,\n",
".xr-index-data-in:checked ~ .xr-index-data {\n",
" display: block;\n",
"}\n",
"\n",
".xr-var-data > table {\n",
" float: right;\n",
"}\n",
"\n",
".xr-var-name span,\n",
".xr-var-data,\n",
".xr-index-name div,\n",
".xr-index-data,\n",
".xr-attrs {\n",
" padding-left: 25px !important;\n",
"}\n",
"\n",
".xr-attrs,\n",
".xr-var-attrs,\n",
".xr-var-data,\n",
".xr-index-data {\n",
" grid-column: 1 / -1;\n",
"}\n",
"\n",
"dl.xr-attrs {\n",
" padding: 0;\n",
" margin: 0;\n",
" display: grid;\n",
" grid-template-columns: 125px auto;\n",
"}\n",
"\n",
".xr-attrs dt,\n",
".xr-attrs dd {\n",
" padding: 0;\n",
" margin: 0;\n",
" float: left;\n",
" padding-right: 10px;\n",
" width: auto;\n",
"}\n",
"\n",
".xr-attrs dt {\n",
" font-weight: normal;\n",
" grid-column: 1;\n",
"}\n",
"\n",
".xr-attrs dt:hover span {\n",
" display: inline-block;\n",
" background: var(--xr-background-color);\n",
" padding-right: 10px;\n",
"}\n",
"\n",
".xr-attrs dd {\n",
" grid-column: 2;\n",
" white-space: pre-wrap;\n",
" word-break: break-all;\n",
"}\n",
"\n",
".xr-icon-database,\n",
".xr-icon-file-text2,\n",
".xr-no-icon {\n",
" display: inline-block;\n",
" vertical-align: middle;\n",
" width: 1em;\n",
" height: 1.5em !important;\n",
" stroke-width: 0;\n",
" stroke: currentColor;\n",
" fill: currentColor;\n",
"}\n",
"</style><pre class='xr-text-repr-fallback'>&lt;xarray.Dataset&gt;\n",
"Dimensions: (temperature: 10, time: 7, latitude: 18, longitude: 26)\n",
"Coordinates:\n",
" * temperature (temperature) int64 20 25 28 30 32 35 40 45 50 55\n",
" * time (time) datetime64[ns] 2030-01-01 2040-01-01 ... 2090-01-01\n",
" * latitude (latitude) float64 60.86 60.13 59.41 ... 49.97 49.25 48.52\n",
" * longitude (longitude) float64 -13.41 -12.68 -11.95 ... 4.011 4.737\n",
"Data variables:\n",
" days_tas_above (temperature, time, latitude, longitude) float32 0.0 ... 0.0</pre><div class='xr-wrap' style='display:none'><div class='xr-header'><div class='xr-obj-type'>xarray.Dataset</div></div><ul class='xr-sections'><li class='xr-section-item'><input id='section-c1d734d6-766d-450d-94a0-164c52690873' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-c1d734d6-766d-450d-94a0-164c52690873' class='xr-section-summary' title='Expand/collapse section'>Dimensions:</label><div class='xr-section-inline-details'><ul class='xr-dim-list'><li><span class='xr-has-index'>temperature</span>: 10</li><li><span class='xr-has-index'>time</span>: 7</li><li><span class='xr-has-index'>latitude</span>: 18</li><li><span class='xr-has-index'>longitude</span>: 26</li></ul></div><div class='xr-section-details'></div></li><li class='xr-section-item'><input id='section-1322a454-4c8d-4126-a62e-4dbf2dd4f412' class='xr-section-summary-in' type='checkbox' checked><label for='section-1322a454-4c8d-4126-a62e-4dbf2dd4f412' class='xr-section-summary' >Coordinates: <span>(4)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>temperature</span></div><div class='xr-var-dims'>(temperature)</div><div class='xr-var-dtype'>int64</div><div class='xr-var-preview xr-preview'>20 25 28 30 32 35 40 45 50 55</div><input id='attrs-eb810426-1b36-40b3-898d-995c43394bce' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-eb810426-1b36-40b3-898d-995c43394bce' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-90d77f14-e43d-4e3f-aeff-5530467a75d5' class='xr-var-data-in' type='checkbox'><label for='data-90d77f14-e43d-4e3f-aeff-5530467a75d5' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>long_name :</span></dt><dd>Threshold temperature</dd><dt><span>units :</span></dt><dd>Degrees Celsius</dd></dl></div><div class='xr-var-data'><pre>array([20, 25, 28, 30, 32, 35, 40, 45, 50, 55])</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>time</span></div><div class='xr-var-dims'>(time)</div><div class='xr-var-dtype'>datetime64[ns]</div><div class='xr-var-preview xr-preview'>2030-01-01 ... 2090-01-01</div><input id='attrs-912f2634-36f7-40a8-940a-71a8187bfa25' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-912f2634-36f7-40a8-940a-71a8187bfa25' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-eb3ee4bc-4f6d-4b7c-abaf-1d506fa9bfc5' class='xr-var-data-in' type='checkbox'><label for='data-eb3ee4bc-4f6d-4b7c-abaf-1d506fa9bfc5' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>long_name :</span></dt><dd>Predicted year</dd></dl></div><div class='xr-var-data'><pre>array([&#x27;2030-01-01T00:00:00.000000000&#x27;, &#x27;2040-01-01T00:00:00.000000000&#x27;,\n",
" &#x27;2050-01-01T00:00:00.000000000&#x27;, &#x27;2060-01-01T00:00:00.000000000&#x27;,\n",
" &#x27;2070-01-01T00:00:00.000000000&#x27;, &#x27;2080-01-01T00:00:00.000000000&#x27;,\n",
" &#x27;2090-01-01T00:00:00.000000000&#x27;], dtype=&#x27;datetime64[ns]&#x27;)</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>latitude</span></div><div class='xr-var-dims'>(latitude)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>60.86 60.13 59.41 ... 49.25 48.52</div><input id='attrs-580c8ca6-62f5-4f77-bed6-b894aab673eb' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-580c8ca6-62f5-4f77-bed6-b894aab673eb' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-a9fa46c9-adb4-4472-8416-bfe358f1a15b' class='xr-var-data-in' type='checkbox'><label for='data-a9fa46c9-adb4-4472-8416-bfe358f1a15b' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([60.859008, 60.133274, 59.407539, 58.681805, 57.956071, 57.230337,\n",
" 56.504603, 55.778869, 55.053135, 54.327401, 53.601666, 52.875932,\n",
" 52.150198, 51.424464, 50.69873 , 49.972996, 49.247262, 48.521527])</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>longitude</span></div><div class='xr-var-dims'>(longitude)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>-13.41 -12.68 ... 4.011 4.737</div><input id='attrs-9ce6ac8e-d51a-4ae3-aeed-6d727b5b1da2' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-9ce6ac8e-d51a-4ae3-aeed-6d727b5b1da2' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-3ab8e0a9-5bb0-4707-9644-9da41d198c8b' class='xr-var-data-in' type='checkbox'><label for='data-3ab8e0a9-5bb0-4707-9644-9da41d198c8b' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([-13.406328, -12.680593, -11.954859, -11.229125, -10.503391, -9.777657,\n",
" -9.051923, -8.326189, -7.600454, -6.87472 , -6.148986, -5.423252,\n",
" -4.697518, -3.971784, -3.24605 , -2.520315, -1.794581, -1.068847,\n",
" -0.343113, 0.382621, 1.108355, 1.834089, 2.559824, 3.285558,\n",
" 4.011292, 4.737026])</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-60963b8a-d5d1-4e64-825b-37e182b7f050' class='xr-section-summary-in' type='checkbox' checked><label for='section-60963b8a-d5d1-4e64-825b-37e182b7f050' class='xr-section-summary' >Data variables: <span>(1)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span>days_tas_above</span></div><div class='xr-var-dims'>(temperature, time, latitude, longitude)</div><div class='xr-var-dtype'>float32</div><div class='xr-var-preview xr-preview'>0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0</div><input id='attrs-ea8b3df5-3db0-4539-b575-70b29a84ebd8' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-ea8b3df5-3db0-4539-b575-70b29a84ebd8' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-a853a5f5-16aa-45c6-9fbc-e03b3060db09' class='xr-var-data-in' type='checkbox'><label for='data-a853a5f5-16aa-45c6-9fbc-e03b3060db09' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>long_name :</span></dt><dd>Days per year for which the average near-surface temperature &#x27;tas&#x27; is above a threshold</dd><dt><span>units :</span></dt><dd>Days per year</dd></dl></div><div class='xr-var-data'><pre>array([[[[0.0000000e+00, 0.0000000e+00, 0.0000000e+00, ...,\n",
" 0.0000000e+00, 0.0000000e+00, 0.0000000e+00],\n",
" [0.0000000e+00, 0.0000000e+00, 0.0000000e+00, ...,\n",
" 0.0000000e+00, 0.0000000e+00, 0.0000000e+00],\n",
" [0.0000000e+00, 0.0000000e+00, 0.0000000e+00, ...,\n",
" 0.0000000e+00, 0.0000000e+00, 0.0000000e+00],\n",
" ...,\n",
" [0.0000000e+00, 0.0000000e+00, 0.0000000e+00, ...,\n",
" 4.4611111e+01, 0.0000000e+00, 0.0000000e+00],\n",
" [0.0000000e+00, 0.0000000e+00, 0.0000000e+00, ...,\n",
" 0.0000000e+00, 0.0000000e+00, 0.0000000e+00],\n",
" [0.0000000e+00, 0.0000000e+00, 0.0000000e+00, ...,\n",
" 0.0000000e+00, 0.0000000e+00, 0.0000000e+00]],\n",
"\n",
" [[0.0000000e+00, 0.0000000e+00, 0.0000000e+00, ...,\n",
" 0.0000000e+00, 0.0000000e+00, 0.0000000e+00],\n",
" [0.0000000e+00, 0.0000000e+00, 0.0000000e+00, ...,\n",
" 0.0000000e+00, 0.0000000e+00, 0.0000000e+00],\n",
" [0.0000000e+00, 0.0000000e+00, 0.0000000e+00, ...,\n",
" 0.0000000e+00, 0.0000000e+00, 0.0000000e+00],\n",
"...\n",
" [0.0000000e+00, 0.0000000e+00, 0.0000000e+00, ...,\n",
" 0.0000000e+00, 0.0000000e+00, 0.0000000e+00],\n",
" [0.0000000e+00, 0.0000000e+00, 0.0000000e+00, ...,\n",
" 0.0000000e+00, 0.0000000e+00, 0.0000000e+00],\n",
" [0.0000000e+00, 0.0000000e+00, 0.0000000e+00, ...,\n",
" 0.0000000e+00, 0.0000000e+00, 0.0000000e+00]],\n",
"\n",
" [[0.0000000e+00, 0.0000000e+00, 0.0000000e+00, ...,\n",
" 0.0000000e+00, 0.0000000e+00, 0.0000000e+00],\n",
" [0.0000000e+00, 0.0000000e+00, 0.0000000e+00, ...,\n",
" 0.0000000e+00, 0.0000000e+00, 0.0000000e+00],\n",
" [0.0000000e+00, 0.0000000e+00, 0.0000000e+00, ...,\n",
" 0.0000000e+00, 0.0000000e+00, 0.0000000e+00],\n",
" ...,\n",
" [0.0000000e+00, 0.0000000e+00, 0.0000000e+00, ...,\n",
" 0.0000000e+00, 0.0000000e+00, 0.0000000e+00],\n",
" [0.0000000e+00, 0.0000000e+00, 0.0000000e+00, ...,\n",
" 0.0000000e+00, 0.0000000e+00, 0.0000000e+00],\n",
" [0.0000000e+00, 0.0000000e+00, 0.0000000e+00, ...,\n",
" 0.0000000e+00, 0.0000000e+00, 0.0000000e+00]]]], dtype=float32)</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-b4be9a74-cb07-4e5d-a99b-76b86b32acc1' class='xr-section-summary-in' type='checkbox' ><label for='section-b4be9a74-cb07-4e5d-a99b-76b86b32acc1' class='xr-section-summary' >Indexes: <span>(4)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-index-name'><div>temperature</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-64186a85-fc48-4406-9497-bdf605b377b8' class='xr-index-data-in' type='checkbox'/><label for='index-64186a85-fc48-4406-9497-bdf605b377b8' title='Show/Hide index repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-index-data'><pre>PandasIndex(Index([20, 25, 28, 30, 32, 35, 40, 45, 50, 55], dtype=&#x27;int64&#x27;, name=&#x27;temperature&#x27;))</pre></div></li><li class='xr-var-item'><div class='xr-index-name'><div>time</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-af0de8ca-6779-4dc6-95c3-0059b37e5532' class='xr-index-data-in' type='checkbox'/><label for='index-af0de8ca-6779-4dc6-95c3-0059b37e5532' title='Show/Hide index repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-index-data'><pre>PandasIndex(DatetimeIndex([&#x27;2030-01-01&#x27;, &#x27;2040-01-01&#x27;, &#x27;2050-01-01&#x27;, &#x27;2060-01-01&#x27;,\n",
" &#x27;2070-01-01&#x27;, &#x27;2080-01-01&#x27;, &#x27;2090-01-01&#x27;],\n",
" dtype=&#x27;datetime64[ns]&#x27;, name=&#x27;time&#x27;, freq=None))</pre></div></li><li class='xr-var-item'><div class='xr-index-name'><div>latitude</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-59ed99ed-d414-4ee5-ba59-fd23a01af23b' class='xr-index-data-in' type='checkbox'/><label for='index-59ed99ed-d414-4ee5-ba59-fd23a01af23b' title='Show/Hide index repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-index-data'><pre>PandasIndex(Index([ 60.85900777563262, 60.13327363529232, 59.40753949495202,\n",
" 58.68180535461172, 57.95607121427142, 57.23033707393112,\n",
" 56.50460293359082, 55.77886879325052, 55.05313465291022,\n",
" 54.327400512569916, 53.601666372229616, 52.875932231889315,\n",
" 52.150198091549015, 51.424463951208715, 50.698729810868414,\n",
" 49.972995670528114, 49.247261530187814, 48.52152738984751],\n",
" dtype=&#x27;float64&#x27;, name=&#x27;latitude&#x27;))</pre></div></li><li class='xr-var-item'><div class='xr-index-name'><div>longitude</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-61ac8b5c-dd1f-4ecc-b58f-adab8f970a0a' class='xr-index-data-in' type='checkbox'/><label for='index-61ac8b5c-dd1f-4ecc-b58f-adab8f970a0a' title='Show/Hide index repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-index-data'><pre>PandasIndex(Index([-13.406327527558583, -12.680593387218282, -11.954859246877982,\n",
" -11.229125106537682, -10.503390966197381, -9.77765682585708,\n",
" -9.051922685516782, -8.326188545176482, -7.600454404836181,\n",
" -6.87472026449588, -6.14898612415558, -5.4232519838152795,\n",
" -4.69751784347498, -3.9717837031346797, -3.2460495627943793,\n",
" -2.520315422454079, -1.7945812821137785, -1.0688471417734782,\n",
" -0.3431130014331778, 0.38262113890712257, 1.108355279247423,\n",
" 1.8340894195877233, 2.5598235599280237, 3.2855577002683223,\n",
" 4.011291840608623, 4.737025980948923],\n",
" dtype=&#x27;float64&#x27;, name=&#x27;longitude&#x27;))</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-a2550754-e054-4034-9d36-2a38566eed57' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-a2550754-e054-4034-9d36-2a38566eed57' class='xr-section-summary' title='Expand/collapse section'>Attributes: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'></dl></div></li></ul></div></div>"
],
"text/plain": [
"<xarray.Dataset>\n",
"Dimensions: (temperature: 10, time: 7, latitude: 18, longitude: 26)\n",
"Coordinates:\n",
" * temperature (temperature) int64 20 25 28 30 32 35 40 45 50 55\n",
" * time (time) datetime64[ns] 2030-01-01 2040-01-01 ... 2090-01-01\n",
" * latitude (latitude) float64 60.86 60.13 59.41 ... 49.97 49.25 48.52\n",
" * longitude (longitude) float64 -13.41 -12.68 -11.95 ... 4.011 4.737\n",
"Data variables:\n",
" days_tas_above (temperature, time, latitude, longitude) float32 0.0 ... 0.0"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ds"
]
},
{
"cell_type": "markdown",
"id": "86297b43-a5b8-465b-8480-8f3d5ff6131f",
"metadata": {},
"source": [
"## Write to Zarr"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "762733b6-4f82-4802-9369-1d36429c10cc",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<xarray.Dataset>\n",
"Dimensions: (temperature: 10, time: 7, latitude: 18, longitude: 26)\n",
"Coordinates:\n",
" * temperature (temperature) int64 20 25 28 30 32 35 40 45 50 55\n",
" * time (time) datetime64[ns] 2030-01-01 2040-01-01 ... 2090-01-01\n",
" * latitude (latitude) float64 60.86 60.13 59.41 ... 49.97 49.25 48.52\n",
" * longitude (longitude) float64 -13.41 -12.68 -11.95 ... 4.011 4.737\n",
"Data variables:\n",
" days_tas_above (temperature, time, latitude, longitude) float32 0.0 ... 0.0\n"
]
}
],
"source": [
"print(ds)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "c83be201-e7d5-409e-aa4a-c07c367d36b9",
"metadata": {},
"outputs": [],
"source": [
"#ds = ds.chunk(dict(temperature=1))"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "cf686e4b-9643-495b-8f24-2ca351734541",
"metadata": {},
"outputs": [],
"source": [
"ds.to_zarr(OUTPUT_PATH, mode=\"w\", consolidated=True) ;"
]
},
{
"cell_type": "markdown",
"id": "b2cfa02f-69aa-46bf-ac90-cba096b3a323",
"metadata": {},
"source": [
"## Round-trip"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "8ffea7b5-fbf8-40d6-9869-aa908dd6f106",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div><svg style=\"position: absolute; width: 0; height: 0; overflow: hidden\">\n",
"<defs>\n",
"<symbol id=\"icon-database\" viewBox=\"0 0 32 32\">\n",
"<path d=\"M16 0c-8.837 0-16 2.239-16 5v4c0 2.761 7.163 5 16 5s16-2.239 16-5v-4c0-2.761-7.163-5-16-5z\"></path>\n",
"<path d=\"M16 17c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n",
"<path d=\"M16 26c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n",
"</symbol>\n",
"<symbol id=\"icon-file-text2\" viewBox=\"0 0 32 32\">\n",
"<path d=\"M28.681 7.159c-0.694-0.947-1.662-2.053-2.724-3.116s-2.169-2.030-3.116-2.724c-1.612-1.182-2.393-1.319-2.841-1.319h-15.5c-1.378 0-2.5 1.121-2.5 2.5v27c0 1.378 1.122 2.5 2.5 2.5h23c1.378 0 2.5-1.122 2.5-2.5v-19.5c0-0.448-0.137-1.23-1.319-2.841zM24.543 5.457c0.959 0.959 1.712 1.825 2.268 2.543h-4.811v-4.811c0.718 0.556 1.584 1.309 2.543 2.268zM28 29.5c0 0.271-0.229 0.5-0.5 0.5h-23c-0.271 0-0.5-0.229-0.5-0.5v-27c0-0.271 0.229-0.5 0.5-0.5 0 0 15.499-0 15.5 0v7c0 0.552 0.448 1 1 1h7v19.5z\"></path>\n",
"<path d=\"M23 26h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
"<path d=\"M23 22h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
"<path d=\"M23 18h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
"</symbol>\n",
"</defs>\n",
"</svg>\n",
"<style>/* CSS stylesheet for displaying xarray objects in jupyterlab.\n",
" *\n",
" */\n",
"\n",
":root {\n",
" --xr-font-color0: var(--jp-content-font-color0, rgba(0, 0, 0, 1));\n",
" --xr-font-color2: var(--jp-content-font-color2, rgba(0, 0, 0, 0.54));\n",
" --xr-font-color3: var(--jp-content-font-color3, rgba(0, 0, 0, 0.38));\n",
" --xr-border-color: var(--jp-border-color2, #e0e0e0);\n",
" --xr-disabled-color: var(--jp-layout-color3, #bdbdbd);\n",
" --xr-background-color: var(--jp-layout-color0, white);\n",
" --xr-background-color-row-even: var(--jp-layout-color1, white);\n",
" --xr-background-color-row-odd: var(--jp-layout-color2, #eeeeee);\n",
"}\n",
"\n",
"html[theme=dark],\n",
"body[data-theme=dark],\n",
"body.vscode-dark {\n",
" --xr-font-color0: rgba(255, 255, 255, 1);\n",
" --xr-font-color2: rgba(255, 255, 255, 0.54);\n",
" --xr-font-color3: rgba(255, 255, 255, 0.38);\n",
" --xr-border-color: #1F1F1F;\n",
" --xr-disabled-color: #515151;\n",
" --xr-background-color: #111111;\n",
" --xr-background-color-row-even: #111111;\n",
" --xr-background-color-row-odd: #313131;\n",
"}\n",
"\n",
".xr-wrap {\n",
" display: block !important;\n",
" min-width: 300px;\n",
" max-width: 700px;\n",
"}\n",
"\n",
".xr-text-repr-fallback {\n",
" /* fallback to plain text repr when CSS is not injected (untrusted notebook) */\n",
" display: none;\n",
"}\n",
"\n",
".xr-header {\n",
" padding-top: 6px;\n",
" padding-bottom: 6px;\n",
" margin-bottom: 4px;\n",
" border-bottom: solid 1px var(--xr-border-color);\n",
"}\n",
"\n",
".xr-header > div,\n",
".xr-header > ul {\n",
" display: inline;\n",
" margin-top: 0;\n",
" margin-bottom: 0;\n",
"}\n",
"\n",
".xr-obj-type,\n",
".xr-array-name {\n",
" margin-left: 2px;\n",
" margin-right: 10px;\n",
"}\n",
"\n",
".xr-obj-type {\n",
" color: var(--xr-font-color2);\n",
"}\n",
"\n",
".xr-sections {\n",
" padding-left: 0 !important;\n",
" display: grid;\n",
" grid-template-columns: 150px auto auto 1fr 20px 20px;\n",
"}\n",
"\n",
".xr-section-item {\n",
" display: contents;\n",
"}\n",
"\n",
".xr-section-item input {\n",
" display: none;\n",
"}\n",
"\n",
".xr-section-item input + label {\n",
" color: var(--xr-disabled-color);\n",
"}\n",
"\n",
".xr-section-item input:enabled + label {\n",
" cursor: pointer;\n",
" color: var(--xr-font-color2);\n",
"}\n",
"\n",
".xr-section-item input:enabled + label:hover {\n",
" color: var(--xr-font-color0);\n",
"}\n",
"\n",
".xr-section-summary {\n",
" grid-column: 1;\n",
" color: var(--xr-font-color2);\n",
" font-weight: 500;\n",
"}\n",
"\n",
".xr-section-summary > span {\n",
" display: inline-block;\n",
" padding-left: 0.5em;\n",
"}\n",
"\n",
".xr-section-summary-in:disabled + label {\n",
" color: var(--xr-font-color2);\n",
"}\n",
"\n",
".xr-section-summary-in + label:before {\n",
" display: inline-block;\n",
" content: '►';\n",
" font-size: 11px;\n",
" width: 15px;\n",
" text-align: center;\n",
"}\n",
"\n",
".xr-section-summary-in:disabled + label:before {\n",
" color: var(--xr-disabled-color);\n",
"}\n",
"\n",
".xr-section-summary-in:checked + label:before {\n",
" content: '▼';\n",
"}\n",
"\n",
".xr-section-summary-in:checked + label > span {\n",
" display: none;\n",
"}\n",
"\n",
".xr-section-summary,\n",
".xr-section-inline-details {\n",
" padding-top: 4px;\n",
" padding-bottom: 4px;\n",
"}\n",
"\n",
".xr-section-inline-details {\n",
" grid-column: 2 / -1;\n",
"}\n",
"\n",
".xr-section-details {\n",
" display: none;\n",
" grid-column: 1 / -1;\n",
" margin-bottom: 5px;\n",
"}\n",
"\n",
".xr-section-summary-in:checked ~ .xr-section-details {\n",
" display: contents;\n",
"}\n",
"\n",
".xr-array-wrap {\n",
" grid-column: 1 / -1;\n",
" display: grid;\n",
" grid-template-columns: 20px auto;\n",
"}\n",
"\n",
".xr-array-wrap > label {\n",
" grid-column: 1;\n",
" vertical-align: top;\n",
"}\n",
"\n",
".xr-preview {\n",
" color: var(--xr-font-color3);\n",
"}\n",
"\n",
".xr-array-preview,\n",
".xr-array-data {\n",
" padding: 0 5px !important;\n",
" grid-column: 2;\n",
"}\n",
"\n",
".xr-array-data,\n",
".xr-array-in:checked ~ .xr-array-preview {\n",
" display: none;\n",
"}\n",
"\n",
".xr-array-in:checked ~ .xr-array-data,\n",
".xr-array-preview {\n",
" display: inline-block;\n",
"}\n",
"\n",
".xr-dim-list {\n",
" display: inline-block !important;\n",
" list-style: none;\n",
" padding: 0 !important;\n",
" margin: 0;\n",
"}\n",
"\n",
".xr-dim-list li {\n",
" display: inline-block;\n",
" padding: 0;\n",
" margin: 0;\n",
"}\n",
"\n",
".xr-dim-list:before {\n",
" content: '(';\n",
"}\n",
"\n",
".xr-dim-list:after {\n",
" content: ')';\n",
"}\n",
"\n",
".xr-dim-list li:not(:last-child):after {\n",
" content: ',';\n",
" padding-right: 5px;\n",
"}\n",
"\n",
".xr-has-index {\n",
" font-weight: bold;\n",
"}\n",
"\n",
".xr-var-list,\n",
".xr-var-item {\n",
" display: contents;\n",
"}\n",
"\n",
".xr-var-item > div,\n",
".xr-var-item label,\n",
".xr-var-item > .xr-var-name span {\n",
" background-color: var(--xr-background-color-row-even);\n",
" margin-bottom: 0;\n",
"}\n",
"\n",
".xr-var-item > .xr-var-name:hover span {\n",
" padding-right: 5px;\n",
"}\n",
"\n",
".xr-var-list > li:nth-child(odd) > div,\n",
".xr-var-list > li:nth-child(odd) > label,\n",
".xr-var-list > li:nth-child(odd) > .xr-var-name span {\n",
" background-color: var(--xr-background-color-row-odd);\n",
"}\n",
"\n",
".xr-var-name {\n",
" grid-column: 1;\n",
"}\n",
"\n",
".xr-var-dims {\n",
" grid-column: 2;\n",
"}\n",
"\n",
".xr-var-dtype {\n",
" grid-column: 3;\n",
" text-align: right;\n",
" color: var(--xr-font-color2);\n",
"}\n",
"\n",
".xr-var-preview {\n",
" grid-column: 4;\n",
"}\n",
"\n",
".xr-index-preview {\n",
" grid-column: 2 / 5;\n",
" color: var(--xr-font-color2);\n",
"}\n",
"\n",
".xr-var-name,\n",
".xr-var-dims,\n",
".xr-var-dtype,\n",
".xr-preview,\n",
".xr-attrs dt {\n",
" white-space: nowrap;\n",
" overflow: hidden;\n",
" text-overflow: ellipsis;\n",
" padding-right: 10px;\n",
"}\n",
"\n",
".xr-var-name:hover,\n",
".xr-var-dims:hover,\n",
".xr-var-dtype:hover,\n",
".xr-attrs dt:hover {\n",
" overflow: visible;\n",
" width: auto;\n",
" z-index: 1;\n",
"}\n",
"\n",
".xr-var-attrs,\n",
".xr-var-data,\n",
".xr-index-data {\n",
" display: none;\n",
" background-color: var(--xr-background-color) !important;\n",
" padding-bottom: 5px !important;\n",
"}\n",
"\n",
".xr-var-attrs-in:checked ~ .xr-var-attrs,\n",
".xr-var-data-in:checked ~ .xr-var-data,\n",
".xr-index-data-in:checked ~ .xr-index-data {\n",
" display: block;\n",
"}\n",
"\n",
".xr-var-data > table {\n",
" float: right;\n",
"}\n",
"\n",
".xr-var-name span,\n",
".xr-var-data,\n",
".xr-index-name div,\n",
".xr-index-data,\n",
".xr-attrs {\n",
" padding-left: 25px !important;\n",
"}\n",
"\n",
".xr-attrs,\n",
".xr-var-attrs,\n",
".xr-var-data,\n",
".xr-index-data {\n",
" grid-column: 1 / -1;\n",
"}\n",
"\n",
"dl.xr-attrs {\n",
" padding: 0;\n",
" margin: 0;\n",
" display: grid;\n",
" grid-template-columns: 125px auto;\n",
"}\n",
"\n",
".xr-attrs dt,\n",
".xr-attrs dd {\n",
" padding: 0;\n",
" margin: 0;\n",
" float: left;\n",
" padding-right: 10px;\n",
" width: auto;\n",
"}\n",
"\n",
".xr-attrs dt {\n",
" font-weight: normal;\n",
" grid-column: 1;\n",
"}\n",
"\n",
".xr-attrs dt:hover span {\n",
" display: inline-block;\n",
" background: var(--xr-background-color);\n",
" padding-right: 10px;\n",
"}\n",
"\n",
".xr-attrs dd {\n",
" grid-column: 2;\n",
" white-space: pre-wrap;\n",
" word-break: break-all;\n",
"}\n",
"\n",
".xr-icon-database,\n",
".xr-icon-file-text2,\n",
".xr-no-icon {\n",
" display: inline-block;\n",
" vertical-align: middle;\n",
" width: 1em;\n",
" height: 1.5em !important;\n",
" stroke-width: 0;\n",
" stroke: currentColor;\n",
" fill: currentColor;\n",
"}\n",
"</style><pre class='xr-text-repr-fallback'>&lt;xarray.Dataset&gt;\n",
"Dimensions: (temperature: 10, time: 7, latitude: 18, longitude: 26)\n",
"Coordinates:\n",
" * latitude (latitude) float64 60.86 60.13 59.41 ... 49.97 49.25 48.52\n",
" * longitude (longitude) float64 -13.41 -12.68 -11.95 ... 4.011 4.737\n",
" * temperature (temperature) int64 20 25 28 30 32 35 40 45 50 55\n",
" * time (time) datetime64[ns] 2030-01-01 2040-01-01 ... 2090-01-01\n",
"Data variables:\n",
" days_tas_above (temperature, time, latitude, longitude) float32 ...</pre><div class='xr-wrap' style='display:none'><div class='xr-header'><div class='xr-obj-type'>xarray.Dataset</div></div><ul class='xr-sections'><li class='xr-section-item'><input id='section-f83612b4-4784-43c2-9bf4-339c0da85d00' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-f83612b4-4784-43c2-9bf4-339c0da85d00' class='xr-section-summary' title='Expand/collapse section'>Dimensions:</label><div class='xr-section-inline-details'><ul class='xr-dim-list'><li><span class='xr-has-index'>temperature</span>: 10</li><li><span class='xr-has-index'>time</span>: 7</li><li><span class='xr-has-index'>latitude</span>: 18</li><li><span class='xr-has-index'>longitude</span>: 26</li></ul></div><div class='xr-section-details'></div></li><li class='xr-section-item'><input id='section-a3f2ee0e-6c43-438b-84a1-09e655981890' class='xr-section-summary-in' type='checkbox' checked><label for='section-a3f2ee0e-6c43-438b-84a1-09e655981890' class='xr-section-summary' >Coordinates: <span>(4)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>latitude</span></div><div class='xr-var-dims'>(latitude)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>60.86 60.13 59.41 ... 49.25 48.52</div><input id='attrs-d459b757-e712-49bc-9517-65da9edcaef7' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-d459b757-e712-49bc-9517-65da9edcaef7' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-f59e39ca-3447-4a68-9fbe-72e2da1390dd' class='xr-var-data-in' type='checkbox'><label for='data-f59e39ca-3447-4a68-9fbe-72e2da1390dd' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([60.859008, 60.133274, 59.407539, 58.681805, 57.956071, 57.230337,\n",
" 56.504603, 55.778869, 55.053135, 54.327401, 53.601666, 52.875932,\n",
" 52.150198, 51.424464, 50.69873 , 49.972996, 49.247262, 48.521527])</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>longitude</span></div><div class='xr-var-dims'>(longitude)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>-13.41 -12.68 ... 4.011 4.737</div><input id='attrs-ea373752-03db-4208-8b57-43887e62b6f1' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-ea373752-03db-4208-8b57-43887e62b6f1' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-4e29c0e3-b3a9-4d15-a498-95cb26661183' class='xr-var-data-in' type='checkbox'><label for='data-4e29c0e3-b3a9-4d15-a498-95cb26661183' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([-13.406328, -12.680593, -11.954859, -11.229125, -10.503391, -9.777657,\n",
" -9.051923, -8.326189, -7.600454, -6.87472 , -6.148986, -5.423252,\n",
" -4.697518, -3.971784, -3.24605 , -2.520315, -1.794581, -1.068847,\n",
" -0.343113, 0.382621, 1.108355, 1.834089, 2.559824, 3.285558,\n",
" 4.011292, 4.737026])</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>temperature</span></div><div class='xr-var-dims'>(temperature)</div><div class='xr-var-dtype'>int64</div><div class='xr-var-preview xr-preview'>20 25 28 30 32 35 40 45 50 55</div><input id='attrs-b98c9a6c-92a9-489b-acad-599c273dbd34' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-b98c9a6c-92a9-489b-acad-599c273dbd34' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-4b8ce47d-4441-4262-b24d-f283d4cde451' class='xr-var-data-in' type='checkbox'><label for='data-4b8ce47d-4441-4262-b24d-f283d4cde451' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>long_name :</span></dt><dd>Threshold temperature</dd><dt><span>units :</span></dt><dd>Degrees Celsius</dd></dl></div><div class='xr-var-data'><pre>array([20, 25, 28, 30, 32, 35, 40, 45, 50, 55])</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>time</span></div><div class='xr-var-dims'>(time)</div><div class='xr-var-dtype'>datetime64[ns]</div><div class='xr-var-preview xr-preview'>2030-01-01 ... 2090-01-01</div><input id='attrs-c65bbc7e-8b00-4e9d-bd9b-bbba211cfc5d' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-c65bbc7e-8b00-4e9d-bd9b-bbba211cfc5d' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-44d17300-3d96-448f-9479-b925c7daef1e' class='xr-var-data-in' type='checkbox'><label for='data-44d17300-3d96-448f-9479-b925c7daef1e' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>long_name :</span></dt><dd>Predicted year</dd></dl></div><div class='xr-var-data'><pre>array([&#x27;2030-01-01T00:00:00.000000000&#x27;, &#x27;2040-01-01T00:00:00.000000000&#x27;,\n",
" &#x27;2050-01-01T00:00:00.000000000&#x27;, &#x27;2060-01-01T00:00:00.000000000&#x27;,\n",
" &#x27;2070-01-01T00:00:00.000000000&#x27;, &#x27;2080-01-01T00:00:00.000000000&#x27;,\n",
" &#x27;2090-01-01T00:00:00.000000000&#x27;], dtype=&#x27;datetime64[ns]&#x27;)</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-a69a5d1d-8f78-4f70-9739-eea7d7197a67' class='xr-section-summary-in' type='checkbox' checked><label for='section-a69a5d1d-8f78-4f70-9739-eea7d7197a67' class='xr-section-summary' >Data variables: <span>(1)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span>days_tas_above</span></div><div class='xr-var-dims'>(temperature, time, latitude, longitude)</div><div class='xr-var-dtype'>float32</div><div class='xr-var-preview xr-preview'>...</div><input id='attrs-9c60d23e-8b4b-484c-bdf7-162d90e884a5' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-9c60d23e-8b4b-484c-bdf7-162d90e884a5' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-d5de5b29-ee5c-4680-aea7-655f8b798829' class='xr-var-data-in' type='checkbox'><label for='data-d5de5b29-ee5c-4680-aea7-655f8b798829' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>long_name :</span></dt><dd>Days per year for which the average near-surface temperature &#x27;tas&#x27; is above a threshold</dd><dt><span>units :</span></dt><dd>Days per year</dd></dl></div><div class='xr-var-data'><pre>[32760 values with dtype=float32]</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-04455a9b-86d2-4445-b9d9-276ae04a9c3a' class='xr-section-summary-in' type='checkbox' ><label for='section-04455a9b-86d2-4445-b9d9-276ae04a9c3a' class='xr-section-summary' >Indexes: <span>(4)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-index-name'><div>latitude</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-a7aba828-7bc4-41a9-87fb-44101ff96dec' class='xr-index-data-in' type='checkbox'/><label for='index-a7aba828-7bc4-41a9-87fb-44101ff96dec' title='Show/Hide index repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-index-data'><pre>PandasIndex(Index([ 60.85900777563262, 60.13327363529232, 59.40753949495202,\n",
" 58.68180535461172, 57.95607121427142, 57.23033707393112,\n",
" 56.50460293359082, 55.77886879325052, 55.05313465291022,\n",
" 54.327400512569916, 53.601666372229616, 52.875932231889315,\n",
" 52.150198091549015, 51.424463951208715, 50.698729810868414,\n",
" 49.972995670528114, 49.247261530187814, 48.52152738984751],\n",
" dtype=&#x27;float64&#x27;, name=&#x27;latitude&#x27;))</pre></div></li><li class='xr-var-item'><div class='xr-index-name'><div>longitude</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-8b5dcf29-dabd-4b81-a50c-c0740dd9669b' class='xr-index-data-in' type='checkbox'/><label for='index-8b5dcf29-dabd-4b81-a50c-c0740dd9669b' title='Show/Hide index repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-index-data'><pre>PandasIndex(Index([-13.406327527558583, -12.680593387218282, -11.954859246877982,\n",
" -11.229125106537682, -10.503390966197381, -9.77765682585708,\n",
" -9.051922685516782, -8.326188545176482, -7.600454404836181,\n",
" -6.87472026449588, -6.14898612415558, -5.4232519838152795,\n",
" -4.69751784347498, -3.9717837031346797, -3.2460495627943793,\n",
" -2.520315422454079, -1.7945812821137785, -1.0688471417734782,\n",
" -0.3431130014331778, 0.38262113890712257, 1.108355279247423,\n",
" 1.8340894195877233, 2.5598235599280237, 3.2855577002683223,\n",
" 4.011291840608623, 4.737025980948923],\n",
" dtype=&#x27;float64&#x27;, name=&#x27;longitude&#x27;))</pre></div></li><li class='xr-var-item'><div class='xr-index-name'><div>temperature</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-ad5a8903-a41e-4999-b690-bbd3138e441d' class='xr-index-data-in' type='checkbox'/><label for='index-ad5a8903-a41e-4999-b690-bbd3138e441d' title='Show/Hide index repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-index-data'><pre>PandasIndex(Index([20, 25, 28, 30, 32, 35, 40, 45, 50, 55], dtype=&#x27;int64&#x27;, name=&#x27;temperature&#x27;))</pre></div></li><li class='xr-var-item'><div class='xr-index-name'><div>time</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-4d051ed2-d23f-4084-9691-2f092774c417' class='xr-index-data-in' type='checkbox'/><label for='index-4d051ed2-d23f-4084-9691-2f092774c417' title='Show/Hide index repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-index-data'><pre>PandasIndex(DatetimeIndex([&#x27;2030-01-01&#x27;, &#x27;2040-01-01&#x27;, &#x27;2050-01-01&#x27;, &#x27;2060-01-01&#x27;,\n",
" &#x27;2070-01-01&#x27;, &#x27;2080-01-01&#x27;, &#x27;2090-01-01&#x27;],\n",
" dtype=&#x27;datetime64[ns]&#x27;, name=&#x27;time&#x27;, freq=None))</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-2cbc69ac-b898-4eee-8b88-06d33ddb0daa' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-2cbc69ac-b898-4eee-8b88-06d33ddb0daa' class='xr-section-summary' title='Expand/collapse section'>Attributes: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'></dl></div></li></ul></div></div>"
],
"text/plain": [
"<xarray.Dataset>\n",
"Dimensions: (temperature: 10, time: 7, latitude: 18, longitude: 26)\n",
"Coordinates:\n",
" * latitude (latitude) float64 60.86 60.13 59.41 ... 49.97 49.25 48.52\n",
" * longitude (longitude) float64 -13.41 -12.68 -11.95 ... 4.011 4.737\n",
" * temperature (temperature) int64 20 25 28 30 32 35 40 45 50 55\n",
" * time (time) datetime64[ns] 2030-01-01 2040-01-01 ... 2090-01-01\n",
"Data variables:\n",
" days_tas_above (temperature, time, latitude, longitude) float32 ..."
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"xr.open_dataset(OUTPUT_PATH, engine=\"zarr\")"
]
},
{
"cell_type": "markdown",
"id": "99cbf755-b0ae-47f1-8b7c-fca7f677b9fa",
"metadata": {},
"source": [
"## Generate STAC metadata with [datacube](https://github.com/stactools-packages/datacube) and [render](https://github.com/stac-extensions/render) extensions"
]
},
{
"cell_type": "markdown",
"id": "f8cc595c-72f9-4d0f-872e-882f4e7ce59d",
"metadata": {},
"source": [
"Using `xstac`, following https://github.com/stac-utils/xstac/blob/main/examples/daymet/generate.py"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "ab603d04-30e3-4023-bd3c-9e58d77cac07",
"metadata": {},
"outputs": [],
"source": [
"BBOX = list(map(float, [\n",
" ds[\"longitude\"].min(), \n",
" ds[\"latitude\"].min(), \n",
" ds[\"longitude\"].max(), \n",
" ds[\"latitude\"].max()\n",
"]))"
]
},
{
"cell_type": "markdown",
"id": "e5c4c51b-d091-4551-8222-8f1e8c2e941d",
"metadata": {},
"source": [
"### STAC Collection"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "1996eb9a-6f6d-4e0c-8b88-6d835d0e6386",
"metadata": {},
"outputs": [],
"source": [
"collection_template = {\n",
" \"id\": INDICATOR_NAME,\n",
" \"description\": INDICATOR_ATTRS[\"long_name\"],\n",
" \"type\": \"Collection\",\n",
" \"title\": INDICATOR_NAME,\n",
" \"license\": \"MIT\",\n",
" \"keywords\": [\n",
" \"OS-Climate\",\n",
" \"Climate Hazards\",\n",
" ],\n",
" \"stac_version\": \"1.0.0\",\n",
" \"stac_extensions\": [\n",
" \"https://stac-extensions.github.io/render/v2.0.0/schema.json\"\n",
" ],\n",
" \"links\": [],\n",
" \"extent\": {\n",
" \"spatial\": {\"bbox\": BBOX},\n",
" \"temporal\": {\"interval\": [[None, None]]},\n",
" },\n",
" \"providers\": [\n",
" {\n",
" \"name\": \"UK EO Data Hub\",\n",
" \"roles\": [\"host\", \"processor\", \"producer\"],\n",
" \"url\": \"https://eodatahub.org.uk/\",\n",
" }\n",
" ],\n",
" \"assets\": {\n",
" \"zarr-local\": {\n",
" \"href\": OUTPUT_PATH.relative_to(OUTPUT_DIR),\n",
" \"type\": \"application/vnd+zarr\",\n",
" \"title\": f\"{INDICATOR_NAME} Zarr root\",\n",
" \"description\": f\"Local path of the {INDICATOR_NAME} Zarr root.\",\n",
" \"roles\": [\"data\", \"zarr\"],\n",
" \"xarray:open_kwargs\": {\"consolidated\": True},\n",
" },\n",
" },\n",
" \"renders\":{\n",
" \"heating\":\n",
" {\n",
" \"title\": \"Heating\",\n",
" \"assets\": [\"zarr-local\"],\n",
" \"rescale\": [[0,100]],\n",
" \"nodata\": 0\n",
" },\n",
" },\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "016ef17b-ee40-476d-8137-7206035c3a36",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\n",
" \"type\": \"Collection\",\n",
" \"id\": \"days_tas_above\",\n",
" \"stac_version\": \"1.0.0\",\n",
" \"description\": \"Days per year for which the average near-surface temperature 'tas' is above a threshold\",\n",
" \"links\": [],\n",
" \"stac_extensions\": [\n",
" \"https://stac-extensions.github.io/render/v2.0.0/schema.json\",\n",
" \"https://stac-extensions.github.io/datacube/v2.2.0/schema.json\"\n",
" ],\n",
" \"renders\": {\n",
" \"heating\": {\n",
" \"title\": \"Heating\",\n",
" \"assets\": [\n",
" \"zarr-local\"\n",
" ],\n",
" \"rescale\": [\n",
" [\n",
" 0,\n",
" 100\n",
" ]\n",
" ],\n",
" \"nodata\": 0\n",
" }\n",
" },\n",
" \"cube:dimensions\": {\n",
" \"time\": {\n",
" \"extent\": [\n",
" \"2030-01-01T00:00:00Z\",\n",
" \"2090-01-01T00:00:00Z\"\n",
" ],\n",
" \"description\": \"Predicted year\",\n",
" \"type\": \"temporal\"\n",
" },\n",
" \"longitude\": {\n",
" \"axis\": \"x\",\n",
" \"extent\": [\n",
" -13.406327527558583,\n",
" 4.737025980948923\n",
" ],\n",
" \"reference_system\": \"epsg:4326\",\n",
" \"type\": \"spatial\"\n",
" },\n",
" \"latitude\": {\n",
" \"axis\": \"y\",\n",
" \"extent\": [\n",
" 48.52152738984751,\n",
" 60.85900777563262\n",
" ],\n",
" \"step\": -0.7257341403403004,\n",
" \"reference_system\": \"epsg:4326\",\n",
" \"type\": \"spatial\"\n",
" },\n",
" \"temperature\": {\n",
" \"type\": \"other\",\n",
" \"description\": \"Threshold temperature\",\n",
" \"values\": [\n",
" 20,\n",
" 25,\n",
" 28,\n",
" 30,\n",
" 32,\n",
" 35,\n",
" 40,\n",
" 45,\n",
" 50,\n",
" 55\n",
" ]\n",
" }\n",
" },\n",
" \"cube:variables\": {\n",
" \"days_tas_above\": {\n",
" \"type\": \"data\",\n",
" \"description\": \"Days per year for which the average near-surface temperature 'tas' is above a threshold\",\n",
" \"dimensions\": [\n",
" \"temperature\",\n",
" \"time\",\n",
" \"latitude\",\n",
" \"longitude\"\n",
" ],\n",
" \"unit\": \"Days per year\",\n",
" \"attrs\": {\n",
" \"long_name\": \"Days per year for which the average near-surface temperature 'tas' is above a threshold\",\n",
" \"units\": \"Days per year\"\n",
" },\n",
" \"shape\": [\n",
" 10,\n",
" 7,\n",
" 18,\n",
" 26\n",
" ]\n",
" }\n",
" },\n",
" \"title\": \"days_tas_above\",\n",
" \"extent\": {\n",
" \"spatial\": {\n",
" \"bbox\": [\n",
" [\n",
" -13.406327527558583,\n",
" 48.52152738984751,\n",
" 4.737025980948923,\n",
" 60.85900777563262\n",
" ]\n",
" ]\n",
" },\n",
" \"temporal\": {\n",
" \"interval\": [\n",
" [\n",
" \"2030-01-01T00:00:00Z\",\n",
" \"2090-01-01T00:00:00Z\"\n",
" ]\n",
" ]\n",
" }\n",
" },\n",
" \"license\": \"MIT\",\n",
" \"keywords\": [\n",
" \"OS-Climate\",\n",
" \"Climate Hazards\"\n",
" ],\n",
" \"providers\": [\n",
" {\n",
" \"name\": \"UK EO Data Hub\",\n",
" \"roles\": [\n",
" \"host\",\n",
" \"processor\",\n",
" \"producer\"\n",
" ],\n",
" \"url\": \"https://eodatahub.org.uk/\"\n",
" }\n",
" ],\n",
" \"assets\": {\n",
" \"zarr-local\": {\n",
" \"href\": \"days_tas_above.zarr\",\n",
" \"type\": \"application/vnd+zarr\",\n",
" \"title\": \"days_tas_above Zarr root\",\n",
" \"description\": \"Local path of the days_tas_above Zarr root.\",\n",
" \"xarray:open_kwargs\": {\n",
" \"consolidated\": true\n",
" },\n",
" \"roles\": [\n",
" \"data\",\n",
" \"zarr\"\n",
" ]\n",
" }\n",
" }\n",
"}\n"
]
}
],
"source": [
"collection = xstac.xarray_to_stac(\n",
" ds,\n",
" collection_template,\n",
" reference_system=\"epsg:4326\",\n",
" temporal_dimension=\"time\",\n",
" x_dimension=\"longitude\",\n",
" y_dimension=\"latitude\",\n",
")\n",
"\n",
"collection.remove_links(pystac.RelType.SELF)\n",
"collection.remove_links(pystac.RelType.ROOT)\n",
"\n",
"collection_result = collection.to_dict(include_self_link=False)\n",
"\n",
"# additional dimensions not implemented in xstac\n",
"collection_result[\"cube:dimensions\"][\"temperature\"] = {\n",
" \"type\": \"other\",\n",
" \"description\": ds[\"temperature\"].attrs[\"long_name\"],\n",
" \"values\": list(map(int, ds[\"temperature\"].values)),\n",
"}\n",
"\n",
"(OUTPUT_DIR / \"collection.json\").write_text(json.dumps(collection_result, indent=2))\n",
"print(json.dumps(collection_result, indent=2))"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "ef6bca57-19b4-4c74-ba2f-9c8258d18d7e",
"metadata": {},
"outputs": [],
"source": [
"item_template = {\n",
" \"id\": INDICATOR_NAME,\n",
" \"type\": \"Feature\",\n",
" \"links\": [],\n",
" \"bbox\": BBOX,\n",
" \"geometry\": shapely.geometry.mapping(shapely.geometry.box(*BBOX)),\n",
" \"stac_version\": \"1.0.0\",\n",
" \"properties\": {\"start_datetime\": None, \"end_datetime\": None},\n",
" \"assets\": {\n",
" \"zarr-local\": {\n",
" \"href\": OUTPUT_PATH.relative_to(OUTPUT_DIR),\n",
" \"type\": \"application/vnd+zarr\",\n",
" \"title\": f\"{INDICATOR_NAME} Zarr root\",\n",
" \"description\": f\"Local path of the {INDICATOR_NAME} Zarr root.\",\n",
" \"roles\": [\"data\", \"zarr\"],\n",
" \"xarray:open_kwargs\": {\"consolidated\": True},\n",
" },\n",
" }\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "323fc8c4-5599-4aa7-8f45-786bad171102",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\n",
" \"type\": \"Feature\",\n",
" \"stac_version\": \"1.0.0\",\n",
" \"id\": \"days_tas_above\",\n",
" \"properties\": {\n",
" \"start_datetime\": \"2030-01-01T00:00:00Z\",\n",
" \"end_datetime\": \"2090-01-01T00:00:00Z\",\n",
" \"cube:dimensions\": {\n",
" \"time\": {\n",
" \"extent\": [\n",
" \"2030-01-01T00:00:00Z\",\n",
" \"2090-01-01T00:00:00Z\"\n",
" ],\n",
" \"description\": \"Predicted year\",\n",
" \"type\": \"temporal\"\n",
" },\n",
" \"longitude\": {\n",
" \"axis\": \"x\",\n",
" \"extent\": [\n",
" -13.406327527558583,\n",
" 4.737025980948923\n",
" ],\n",
" \"reference_system\": \"epsg:4326\",\n",
" \"type\": \"spatial\"\n",
" },\n",
" \"latitude\": {\n",
" \"axis\": \"y\",\n",
" \"extent\": [\n",
" 48.52152738984751,\n",
" 60.85900777563262\n",
" ],\n",
" \"step\": -0.7257341403403004,\n",
" \"reference_system\": \"epsg:4326\",\n",
" \"type\": \"spatial\"\n",
" },\n",
" \"temperature\": {\n",
" \"type\": \"other\",\n",
" \"description\": \"Threshold temperature\",\n",
" \"values\": [\n",
" 20,\n",
" 25,\n",
" 28,\n",
" 30,\n",
" 32,\n",
" 35,\n",
" 40,\n",
" 45,\n",
" 50,\n",
" 55\n",
" ]\n",
" }\n",
" },\n",
" \"cube:variables\": {\n",
" \"days_tas_above\": {\n",
" \"type\": \"data\",\n",
" \"description\": \"Days per year for which the average near-surface temperature 'tas' is above a threshold\",\n",
" \"dimensions\": [\n",
" \"temperature\",\n",
" \"time\",\n",
" \"latitude\",\n",
" \"longitude\"\n",
" ],\n",
" \"unit\": \"Days per year\",\n",
" \"attrs\": {\n",
" \"long_name\": \"Days per year for which the average near-surface temperature 'tas' is above a threshold\",\n",
" \"units\": \"Days per year\"\n",
" },\n",
" \"shape\": [\n",
" 10,\n",
" 7,\n",
" 18,\n",
" 26\n",
" ]\n",
" }\n",
" },\n",
" \"datetime\": null\n",
" },\n",
" \"geometry\": {\n",
" \"type\": \"Polygon\",\n",
" \"coordinates\": [\n",
" [\n",
" [\n",
" 4.737025980948923,\n",
" 48.52152738984751\n",
" ],\n",
" [\n",
" 4.737025980948923,\n",
" 60.85900777563262\n",
" ],\n",
" [\n",
" -13.406327527558583,\n",
" 60.85900777563262\n",
" ],\n",
" [\n",
" -13.406327527558583,\n",
" 48.52152738984751\n",
" ],\n",
" [\n",
" 4.737025980948923,\n",
" 48.52152738984751\n",
" ]\n",
" ]\n",
" ]\n",
" },\n",
" \"links\": [],\n",
" \"assets\": {\n",
" \"zarr-local\": {\n",
" \"href\": \"days_tas_above.zarr\",\n",
" \"type\": \"application/vnd+zarr\",\n",
" \"title\": \"days_tas_above Zarr root\",\n",
" \"description\": \"Local path of the days_tas_above Zarr root.\",\n",
" \"xarray:open_kwargs\": {\n",
" \"consolidated\": true\n",
" },\n",
" \"roles\": [\n",
" \"data\",\n",
" \"zarr\"\n",
" ]\n",
" }\n",
" },\n",
" \"bbox\": [\n",
" -13.406327527558583,\n",
" 48.52152738984751,\n",
" 4.737025980948923,\n",
" 60.85900777563262\n",
" ],\n",
" \"stac_extensions\": [\n",
" \"https://stac-extensions.github.io/datacube/v2.2.0/schema.json\"\n",
" ]\n",
"}\n"
]
}
],
"source": [
"item = xstac.xarray_to_stac(\n",
" ds, \n",
" item_template,\n",
" reference_system=\"epsg:4326\",\n",
" temporal_dimension=\"time\",\n",
" x_dimension=\"longitude\",\n",
" y_dimension=\"latitude\"\n",
")\n",
"\n",
"item_result = item.to_dict(include_self_link=False)\n",
"\n",
"# additional dimensions not implemented in xstac\n",
"item_result[\"properties\"][\"cube:dimensions\"][\"temperature\"] = {\n",
" \"type\": \"other\",\n",
" \"description\": ds[\"temperature\"].attrs[\"long_name\"],\n",
" \"values\": list(map(int, ds[\"temperature\"].values)),\n",
"}\n",
"\n",
"(OUTPUT_DIR / \"item.json\").write_text(json.dumps(item_result, indent=2))\n",
"print(json.dumps(item_result, indent=2))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.9.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment