{ "cells": [ { "cell_type": "markdown", "id": "3dbac58d-0638-4e3a-a594-efca35d34a7e", "metadata": {}, "source": [ "## Climate Impact Lab Global Downscaled Projections for Climate Impacts Research\n", "\n", "The Climate Impact Lab Downscaled Projections for Climate Impacts Research (CIL-GDPCR) collections contain bias corrected and downscaled 1/4° CMIP6 projections for temperature and precipitation.\n", "\n", "See the project homepage for more information: [github.com/ClimateImpactLab/downscaleCMIP6](https://github.com/ClimateImpactLab/downscaleCMIP6).\n", "\n", "This tutorial covers accessing the STAC API to explore the collections and open a dataset. Additional tutorials are available at [github.com/microsoft/PlanetaryComputerExamples](https://github.com/microsoft/PlanetaryComputerExamples/blob/main/datasets/cil-gdpcir).\n" ] }, { "cell_type": "code", "execution_count": 1, "id": "f6c291ba-5b61-41d9-bde9-3e49afddebaf", "metadata": { "tags": [] }, "outputs": [], "source": [ "import planetary_computer\n", "import pystac_client" ] }, { "cell_type": "markdown", "id": "a0cd264a-6a8a-4bca-8d37-dd7109461107", "metadata": {}, "source": [ "### STAC Metadata\n", "\n", "The [CIL-GDPR datasets](https://planetarycomputer.microsoft.com/dataset/group/cil-gdpcir) are grouped into two collections, depending on the license the data are provided under.\n", "\n", "- [CIL-GDPCIR-CC0](https://planetarycomputer.microsoft.com/dataset/cil-gdpcir-cc0)\n", "- [CIL-GDPCIR-CC-BY](https://planetarycomputer.microsoft.com/dataset/cil-gdpcir-cc-by)\n", "\n", "The data assets in this collection are a set of [Zarr](https://zarr.readthedocs.io/) groups which can be opend by tools like [xarray](https://xarray.pydata.org/). Each Zarr group contains a single data variable (either `pr`, `tasmax`, or `tasmin`). The Planetary Computer provides a single STAC item per experiment, and each STAC item has one asset per data variable.\n", "\n", "To access the data, we'll create a `pystac_client.Client` to access the Planetary Computer data catalog, including `modifier=planetary_computer.sign_inplace` to automatically sign the returned results. See https://planetarycomputer.microsoft.com/docs/quickstarts/reading-stac/ for more." ] }, { "cell_type": "code", "execution_count": 2, "id": "c90e0b79-851c-4f7f-904f-74ef91bec841", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "{'pr': ,\n", " 'tasmax': ,\n", " 'tasmin': }" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "catalog = pystac_client.Client.open(\n", " \"https://planetarycomputer.microsoft.com/api/stac/v1/\",\n", " modifier=planetary_computer.sign_inplace,\n", ")\n", "collection = catalog.get_collection(\"cil-gdpcir-cc-by\")\n", "item = collection.get_item(\"cil-gdpcir-NUIST-NESM3-ssp585-r1i1p1f1-day\")\n", "item.assets" ] }, { "cell_type": "markdown", "id": "f12407bc-d02f-4906-9158-5f3db6249e62", "metadata": {}, "source": [ "The STAC metadata includes all the required fields from the [CMIP 6 controlled vocabularies](https://wcrp-cmip.github.io/CMIP6_CVs/)." ] }, { "cell_type": "code", "execution_count": 3, "id": "8c0a5288-bd26-4542-b328-3a7d61546a44", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "'NESM3'" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "item.properties[\"cmip6:source_id\"]" ] }, { "cell_type": "markdown", "id": "36d24e09-3b1c-45be-aa08-5c381e876435", "metadata": {}, "source": [ "### Querying the STAC API\n", "\n", "Use the Planetary Computer STAC API to find the exact data you want. You'll most likely want to query on the controlled vocabularies fields, under the `cmip6:` prefix.. See the collection summary for the set of allowed values for each of those." ] }, { "cell_type": "code", "execution_count": 4, "id": "4289ade3-8c04-4356-8bbf-2cae463cd036", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "{'cmip6:variable': ['pr', 'tasmax', 'tasmin'],\n", " 'cmip6:source_id': ['BCC-CSM2-MR',\n", " 'ACCESS-ESM1-5',\n", " 'ACCESS-CM2',\n", " 'MIROC-ES2L',\n", " 'MIROC6',\n", " 'NorESM2-LM',\n", " 'NorESM2-MM',\n", " 'GFDL-CM4',\n", " 'GFDL-ESM4',\n", " 'NESM3',\n", " 'MPI-ESM1-2-HR',\n", " 'HadGEM3-GC31-LL',\n", " 'UKESM1-0-LL',\n", " 'MPI-ESM1-2-LR',\n", " 'EC-Earth3',\n", " 'EC-Earth3-AerChem',\n", " 'EC-Earth3-CC',\n", " 'EC-Earth3-Veg',\n", " 'EC-Earth3-Veg-LR',\n", " 'CMCC-CM2-SR5',\n", " 'CMCC-ESM2'],\n", " 'cmip6:experiment_id': ['historical', 'ssp126', 'ssp245', 'ssp370', 'ssp585'],\n", " 'cmip6:institution_id': ['BCC',\n", " 'CAS',\n", " 'CCCma',\n", " 'CMCC',\n", " 'CSIRO',\n", " 'CSIRO-ARCCSS',\n", " 'DKRZ',\n", " 'EC-Earth-Consortium',\n", " 'INM',\n", " 'MIROC',\n", " 'MOHC',\n", " 'MPI-M',\n", " 'NCC',\n", " 'NOAA-GFDL',\n", " 'NUIST']}" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "collection.summaries.to_dict()" ] }, { "cell_type": "code", "execution_count": 5, "id": "9f10c8f5-2f29-4cd7-bddf-9facd6515b0e", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/srv/conda/envs/notebook/lib/python3.10/site-packages/pystac_client/item_search.py:841: FutureWarning: get_all_items() is deprecated, use item_collection() instead.\n", " warnings.warn(\n" ] }, { "data": { "text/plain": [ "1" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "search = catalog.search(\n", " collections=[\"cil-gdpcir-cc-by\"],\n", " query={\"cmip6:source_id\": {\"eq\": \"NESM3\"}, \"cmip6:experiment_id\": {\"eq\": \"ssp585\"}},\n", ")\n", "items = search.get_all_items()\n", "len(items)" ] }, { "cell_type": "code", "execution_count": 6, "id": "df0e956a-baa5-4357-978f-21aeb1ec9aee", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "
\n", "
\n", "
\n", " \n", "

Item: cil-gdpcir-NUIST-NESM3-ssp585-r1i1p1f1-day

\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
id: cil-gdpcir-NUIST-NESM3-ssp585-r1i1p1f1-day
bbox: [-180, -90, 180, 90]
datetime: None
cmip6:realm: atmos
cmip6:source: NESM v3 (2016): \n", "aerosol: none\n", "atmos: ECHAM v6.3 (T63; 192 x 96 longitude/latitude; 47 levels; top level 1 Pa)\n", "atmosChem: none\n", "land: JSBACH v3.1\n", "landIce: none\n", "ocean: NEMO v3.4 (NEMO v3.4, tripolar primarily 1deg; 384 x 362 longitude/latitude; 46 levels; top grid cell 0-6 m)\n", "ocnBgchem: none\n", "seaIce: CICE4.1
end_datetime: 2100-12-31T12:00:00Z
cmip6:license: https://github.com/ClimateImpactLab/downscaleCMIP6/tree/master/data_licenses/NESM3.txt
cmip6:mip_era: CMIP6
cmip6:product: model-output
cmip6:table_id: day
cube:variables: {'pr': {'type': 'data', 'unit': 'mm day-1', 'attrs': {'units': 'mm day-1'}, 'shape': [31390, 720, 1440], 'dimensions': ['time', 'lat', 'lon']}, 'tasmax': {'type': 'data', 'unit': 'K', 'attrs': {'units': 'K', 'comment': \"maximum near-surface (usually, 2 meter) air temperature (add cell_method attribute 'time: max')\", 'history': \"2019-08-11T09:50:24Z altered by CMOR: Treated scalar dimension: 'height'. 2019-08-11T09:50:24Z altered by CMOR: Inverted axis: lat.\", 'long_name': 'Daily Maximum Near-Surface Air Temperature', 'cell_methods': 'area: mean time: maximum', 'cell_measures': 'area: areacella', 'standard_name': 'air_temperature'}, 'shape': [31390, 720, 1440], 'dimensions': ['time', 'lat', 'lon'], 'description': 'Daily Maximum Near-Surface Air Temperature'}, 'tasmin': {'type': 'data', 'unit': 'K', 'attrs': {'units': 'K', 'comment': \"minimum near-surface (usually, 2 meter) air temperature (add cell_method attribute 'time: min')\", 'history': \"2019-08-11T09:48:45Z altered by CMOR: Treated scalar dimension: 'height'. 2019-08-11T09:48:45Z altered by CMOR: Inverted axis: lat.\", 'long_name': 'Daily Minimum Near-Surface Air Temperature', 'cell_methods': 'area: mean time: minimum', 'cell_measures': 'area: areacella', 'standard_name': 'air_temperature'}, 'shape': [31390, 720, 1440], 'dimensions': ['time', 'lat', 'lon'], 'description': 'Daily Minimum Near-Surface Air Temperature'}}
start_datetime: 2015-01-01T12:00:00Z
cmip6:frequency: day
cmip6:source_id: NESM3
cube:dimensions: {'lat': {'axis': 'y', 'step': 0.25, 'type': 'spatial', 'extent': [-89.875, 89.875], 'reference_system': 'epsg:4326'}, 'lon': {'axis': 'x', 'step': 0.25, 'type': 'spatial', 'extent': [-179.875, 179.875], 'reference_system': 'epsg:4326'}, 'time': {'step': 'P1DT0H0M0S', 'type': 'temporal', 'extent': ['2015-01-01T12:00:00Z', '2100-12-31T12:00:00Z'], 'description': 'time'}}
cmip6:experiment: update of RCP8.5 based on SSP5
cmip6:Conventions: CF-1.7 CMIP-6.2
cmip6:activity_id: ScenarioMIP
cmip6:institution: Nanjing University of Information Science and Technology, Nanjing, 210044, China
cmip6:source_type: AOGCM
cmip6:experiment_id: ssp585
cmip6:forcing_index: 1
cmip6:physics_index: 1
cmip6:variant_label: r1i1p1f1
cmip6:institution_id: NUIST
cmip6:sub_experiment: none
cmip6:further_info_url: https://furtherinfo.es-doc.org/CMIP6.NUIST.NESM3.ssp585.none.r1i1p1f1
cmip6:realization_index: 1
cmip6:sub_experiment_id: none
cmip6:data_specs_version: 01.00.30
cmip6:nominal_resolution: 250 km
cmip6:initialization_index: 1
\n", " \n", "
\n", " \n", "

STAC Extensions

\n", "
\n", " \n", " \n", " \n", " \n", "
https://stac-extensions.github.io/datacube/v2.0.0/schema.json
\n", "
\n", " \n", " \n", "
\n", " \n", "

Assets

\n", "
\n", " \n", " \n", "\n", "
\n", "
\n", "
\n", "
\n", "
\n", " \n", "

Asset:

\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
href: abfs://cil-gdpcir/ScenarioMIP/NUIST/NESM3/ssp585/r1i1p1f1/day/pr/v1.1.zarr
type: application/vnd+zarr
owner: cil-gdpcir-NUIST-NESM3-ssp585-r1i1p1f1-day
cmip6:grid: T63
msft:https-url: https://rhgeuwest.blob.core.windows.net/cil-gdpcir/ScenarioMIP/NUIST/NESM3/ssp585/r1i1p1f1/day/pr/v1.1.zarr
cmip6:grid_label: gn
cmip6:tracking_id: hdl:21.14100/ed432434-922e-4cea-8400-c321598fd7cf\n", "hdl:21.14100/abea2bb8-09d0-4114-9051-fe232efe108e\n", "hdl:21.14100/205a607f-75f4-4919-b495-45fa8fdb77b8
cmip6:variable_id: pr
xarray:open_kwargs: {'chunks': {}, 'engine': 'zarr', 'consolidated': True, 'storage_options': {'account_name': 'rhgeuwest', 'credential': 'st=2023-06-22T15%3A36%3A45Z&se=2023-06-30T15%3A36%3A45Z&sp=rl&sv=2021-06-08&sr=c&skoid=c85c15d6-d1ae-42d4-af60-e2ca0f81359b&sktid=72f988bf-86f1-41af-91ab-2d7cd011db47&skt=2023-06-23T15%3A36%3A44Z&ske=2023-06-30T15%3A36%3A44Z&sks=b&skv=2021-06-08&sig=C8zGe%2B5GRYp/uYA%2B4yhjz8Sk5ZztiuRwRmLEj5fMQM0%3D'}}
cmip6:creation_date: 2019-08-11T09:53:50Z
\n", "
\n", "
\n", "
\n", " \n", " \n", "\n", "
\n", "
\n", "
\n", "
\n", "
\n", " \n", "

Asset:

\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
href: abfs://cil-gdpcir/ScenarioMIP/NUIST/NESM3/ssp585/r1i1p1f1/day/tasmax/v1.1.zarr
type: application/vnd+zarr
owner: cil-gdpcir-NUIST-NESM3-ssp585-r1i1p1f1-day
cmip6:grid: T63
msft:https-url: https://rhgeuwest.blob.core.windows.net/cil-gdpcir/ScenarioMIP/NUIST/NESM3/ssp585/r1i1p1f1/day/tasmax/v1.1.zarr
cmip6:grid_label: gn
cmip6:tracking_id: hdl:21.14100/01f58d9c-1317-467e-813d-a2358cdf7954\n", "hdl:21.14100/e027cda7-ac28-4e00-b03f-53ad2e6d30b4\n", "hdl:21.14100/3898bc79-5174-4fcc-9637-4573914ad548
cmip6:variable_id: tasmax
xarray:open_kwargs: {'chunks': {}, 'engine': 'zarr', 'consolidated': True, 'storage_options': {'account_name': 'rhgeuwest', 'credential': 'st=2023-06-22T15%3A36%3A45Z&se=2023-06-30T15%3A36%3A45Z&sp=rl&sv=2021-06-08&sr=c&skoid=c85c15d6-d1ae-42d4-af60-e2ca0f81359b&sktid=72f988bf-86f1-41af-91ab-2d7cd011db47&skt=2023-06-23T15%3A36%3A44Z&ske=2023-06-30T15%3A36%3A44Z&sks=b&skv=2021-06-08&sig=C8zGe%2B5GRYp/uYA%2B4yhjz8Sk5ZztiuRwRmLEj5fMQM0%3D'}}
cmip6:creation_date: 2019-08-11T09:50:24Z
\n", "
\n", "
\n", "
\n", " \n", " \n", "\n", "
\n", "
\n", "
\n", "
\n", "
\n", " \n", "

Asset:

\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
href: abfs://cil-gdpcir/ScenarioMIP/NUIST/NESM3/ssp585/r1i1p1f1/day/tasmin/v1.1.zarr
type: application/vnd+zarr
owner: cil-gdpcir-NUIST-NESM3-ssp585-r1i1p1f1-day
cmip6:grid: T63
msft:https-url: https://rhgeuwest.blob.core.windows.net/cil-gdpcir/ScenarioMIP/NUIST/NESM3/ssp585/r1i1p1f1/day/tasmin/v1.1.zarr
cmip6:grid_label: gn
cmip6:tracking_id: hdl:21.14100/1998e7f0-ad6a-4720-8150-9085db6f96b8\n", "hdl:21.14100/ca181871-4103-481d-8764-b74c2448427f\n", "hdl:21.14100/fceb22c4-0454-4d68-bb48-1d903df19e63
cmip6:variable_id: tasmin
xarray:open_kwargs: {'chunks': {}, 'engine': 'zarr', 'consolidated': True, 'storage_options': {'account_name': 'rhgeuwest', 'credential': 'st=2023-06-22T15%3A36%3A45Z&se=2023-06-30T15%3A36%3A45Z&sp=rl&sv=2021-06-08&sr=c&skoid=c85c15d6-d1ae-42d4-af60-e2ca0f81359b&sktid=72f988bf-86f1-41af-91ab-2d7cd011db47&skt=2023-06-23T15%3A36%3A44Z&ske=2023-06-30T15%3A36%3A44Z&sks=b&skv=2021-06-08&sig=C8zGe%2B5GRYp/uYA%2B4yhjz8Sk5ZztiuRwRmLEj5fMQM0%3D'}}
cmip6:creation_date: 2019-08-11T09:48:45Z
\n", "
\n", "
\n", "
\n", " \n", "
\n", " \n", " \n", "
\n", " \n", "

Links

\n", "
\n", " \n", " \n", "\n", "
\n", "
\n", "
\n", "
\n", "

Link:

\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
rel: collection
href: https://planetarycomputer.microsoft.com/api/stac/v1/collections/cil-gdpcir-cc-by
type: application/json
\n", " \n", "
\n", "
\n", " \n", " \n", "\n", "
\n", "
\n", "
\n", "
\n", "

Link:

\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
rel: parent
href: https://planetarycomputer.microsoft.com/api/stac/v1/collections/cil-gdpcir-cc-by
type: application/json
\n", " \n", "
\n", "
\n", " \n", " \n", "\n", "
\n", "
\n", "
\n", "
\n", "

Link: Microsoft Planetary Computer STAC API

\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
rel: root
href: https://planetarycomputer.microsoft.com/api/stac/v1/
type: application/json
title: Microsoft Planetary Computer STAC API
\n", " \n", "
\n", "
\n", " \n", " \n", "\n", "
\n", "
\n", "
\n", "
\n", "

Link:

\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
rel: self
href: https://planetarycomputer.microsoft.com/api/stac/v1/collections/cil-gdpcir-cc-by/items/cil-gdpcir-NUIST-NESM3-ssp585-r1i1p1f1-day
type: application/geo+json
\n", " \n", "
\n", "
\n", " \n", "
\n", " \n", "
\n", "
\n", "
" ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "item = items[0]\n", "item" ] }, { "cell_type": "markdown", "id": "66128434-151c-47f9-a5ee-f0ec72f3a2a7", "metadata": {}, "source": [ "We can now load the assets with xarray:" ] }, { "cell_type": "code", "execution_count": 7, "id": "58acf247-7e52-488f-818e-258ab54ee8c6", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
<xarray.Dataset>\n",
       "Dimensions:  (lat: 720, lon: 1440, time: 31390)\n",
       "Coordinates:\n",
       "  * lat      (lat) float64 -89.88 -89.62 -89.38 -89.12 ... 89.38 89.62 89.88\n",
       "  * lon      (lon) float64 -179.9 -179.6 -179.4 -179.1 ... 179.4 179.6 179.9\n",
       "  * time     (time) object 2015-01-01 12:00:00 ... 2100-12-31 12:00:00\n",
       "Data variables:\n",
       "    tasmax   (time, lat, lon) float32 dask.array<chunksize=(365, 360, 360), meta=np.ndarray>\n",
       "Attributes: (12/47)\n",
       "    Conventions:                  CF-1.7 CMIP-6.2\n",
       "    activity_id:                  ScenarioMIP\n",
       "    contact:                      climatesci@rhg.com\n",
       "    creation_date:                2019-08-11T09:50:24Z\n",
       "    data_specs_version:           01.00.30\n",
       "    dc6_bias_correction_method:   Quantile Delta Method (QDM)\n",
       "    ...                           ...\n",
       "    sub_experiment_id:            none\n",
       "    table_id:                     day\n",
       "    tracking_id:                  hdl:21.14100/01f58d9c-1317-467e-813d-a2358c...\n",
       "    variable_id:                  tasmax\n",
       "    variant_label:                r1i1p1f1\n",
       "    version_id:                   v20190811
" ], "text/plain": [ "\n", "Dimensions: (lat: 720, lon: 1440, time: 31390)\n", "Coordinates:\n", " * lat (lat) float64 -89.88 -89.62 -89.38 -89.12 ... 89.38 89.62 89.88\n", " * lon (lon) float64 -179.9 -179.6 -179.4 -179.1 ... 179.4 179.6 179.9\n", " * time (time) object 2015-01-01 12:00:00 ... 2100-12-31 12:00:00\n", "Data variables:\n", " tasmax (time, lat, lon) float32 dask.array\n", "Attributes: (12/47)\n", " Conventions: CF-1.7 CMIP-6.2\n", " activity_id: ScenarioMIP\n", " contact: climatesci@rhg.com\n", " creation_date: 2019-08-11T09:50:24Z\n", " data_specs_version: 01.00.30\n", " dc6_bias_correction_method: Quantile Delta Method (QDM)\n", " ... ...\n", " sub_experiment_id: none\n", " table_id: day\n", " tracking_id: hdl:21.14100/01f58d9c-1317-467e-813d-a2358c...\n", " variable_id: tasmax\n", " variant_label: r1i1p1f1\n", " version_id: v20190811" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import xarray as xr\n", "\n", "asset = item.assets[\"tasmax\"]\n", "\n", "ds = xr.open_dataset(asset.href, **asset.extra_fields[\"xarray:open_kwargs\"])\n", "ds" ] }, { "cell_type": "markdown", "id": "acf2bbfb-e364-4f61-ac17-85fd1ec7fa3b", "metadata": {}, "source": [ "And form a datacube with [`xarray.combine_by_coords`](https://docs.xarray.dev/en/stable/generated/xarray.combine_by_coords.html)." ] }, { "cell_type": "code", "execution_count": 8, "id": "c9b4c42c-e016-40e6-95db-4d80d781b2d9", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
<xarray.Dataset>\n",
       "Dimensions:  (lat: 720, lon: 1440, time: 31390)\n",
       "Coordinates:\n",
       "  * lat      (lat) float64 -89.88 -89.62 -89.38 -89.12 ... 89.38 89.62 89.88\n",
       "  * lon      (lon) float64 -179.9 -179.6 -179.4 -179.1 ... 179.4 179.6 179.9\n",
       "  * time     (time) object 2015-01-01 12:00:00 ... 2100-12-31 12:00:00\n",
       "Data variables:\n",
       "    pr       (time, lat, lon) float64 dask.array<chunksize=(365, 360, 360), meta=np.ndarray>\n",
       "    tasmax   (time, lat, lon) float32 dask.array<chunksize=(365, 360, 360), meta=np.ndarray>\n",
       "    tasmin   (time, lat, lon) float32 dask.array<chunksize=(365, 360, 360), meta=np.ndarray>\n",
       "Attributes: (12/40)\n",
       "    Conventions:                  CF-1.7 CMIP-6.2\n",
       "    activity_id:                  ScenarioMIP\n",
       "    contact:                      climatesci@rhg.com\n",
       "    data_specs_version:           01.00.30\n",
       "    dc6_bias_correction_method:   Quantile Delta Method (QDM)\n",
       "    dc6_citation:                 Please refer to https://github.com/ClimateI...\n",
       "    ...                           ...\n",
       "    source_type:                  AOGCM\n",
       "    sub_experiment:               none\n",
       "    sub_experiment_id:            none\n",
       "    table_id:                     day\n",
       "    variant_label:                r1i1p1f1\n",
       "    version_id:                   v20190811
" ], "text/plain": [ "\n", "Dimensions: (lat: 720, lon: 1440, time: 31390)\n", "Coordinates:\n", " * lat (lat) float64 -89.88 -89.62 -89.38 -89.12 ... 89.38 89.62 89.88\n", " * lon (lon) float64 -179.9 -179.6 -179.4 -179.1 ... 179.4 179.6 179.9\n", " * time (time) object 2015-01-01 12:00:00 ... 2100-12-31 12:00:00\n", "Data variables:\n", " pr (time, lat, lon) float64 dask.array\n", " tasmax (time, lat, lon) float32 dask.array\n", " tasmin (time, lat, lon) float32 dask.array\n", "Attributes: (12/40)\n", " Conventions: CF-1.7 CMIP-6.2\n", " activity_id: ScenarioMIP\n", " contact: climatesci@rhg.com\n", " data_specs_version: 01.00.30\n", " dc6_bias_correction_method: Quantile Delta Method (QDM)\n", " dc6_citation: Please refer to https://github.com/ClimateI...\n", " ... ...\n", " source_type: AOGCM\n", " sub_experiment: none\n", " sub_experiment_id: none\n", " table_id: day\n", " variant_label: r1i1p1f1\n", " version_id: v20190811" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import xarray as xr\n", "\n", "asset = item.assets[\"tasmax\"]\n", "ds = xr.combine_by_coords(\n", " [\n", " xr.open_dataset(asset.href, **asset.extra_fields[\"xarray:open_kwargs\"])\n", " for asset in item.assets.values()\n", " ],\n", " combine_attrs=\"drop_conflicts\",\n", ")\n", "ds" ] }, { "cell_type": "markdown", "id": "ef38a5be-3961-4795-8350-b2673206530d", "metadata": {}, "source": [ "We'll load the data for a specific date and plot the result." ] }, { "cell_type": "code", "execution_count": 9, "id": "537443aa-379f-4405-b12d-036017079ee0", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "tmax = ds.tasmax.isel(time=0).load()\n", "tmax.plot(size=10);" ] } ], "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.10.10" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 5 }