{ "cells": [ { "cell_type": "markdown", "id": "cdeff258-f4af-48fb-99df-8f01e6ea1170", "metadata": {}, "source": [ "# Caching results of computations for later use\n", "\n", "These examples were provided by Florian Ziemen (ziemen@dkrz.de) for use on the Levante Supercomputer of DKRZ.\n", "Some of the ideas were contributed by Lukas Kluft and Tobi Kölling, and others.\n", "The examples are by no means meant to be perfect. They should just provide some input on how things _can_ be done.\n", "\n", "Copyright 2022 Florian Ziemen / DKRZ\n", "\n", "Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n", "\n", "1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n", "\n", "2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\n", "\n", "3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.\n", "\n", "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." ] }, { "cell_type": "markdown", "id": "6a57dfdb-1a25-4fdd-8673-1183fb43a671", "metadata": {}, "source": [ "## Preparations" ] }, { "cell_type": "code", "execution_count": 1, "id": "46946fd9-a2f6-40d8-8d1e-9439e0a2e14a", "metadata": {}, "outputs": [], "source": [ "# basics\n", "import intake\n", "import numpy as np\n", "import xarray as xr\n", "import dask # memory-efficient parallel computation and delayed execution (lazy evaluation).\n", "\n", "\n", "# fewer red warnings\n", "import warnings, matplotlib\n", "\n", "warnings.simplefilter(action=\"ignore\", category=FutureWarning)\n", "warnings.filterwarnings(\"ignore\", category=matplotlib.cbook.mplDeprecation)" ] }, { "cell_type": "markdown", "id": "089e40ef-64e5-49a8-bda2-2c061ed347bf", "metadata": {}, "source": [ "### Paths for data cache\n", "\n", "We create a data cache in our /scratch/ directory. Data there will be deleted automatically after two weeks. This way, we can cache things and the cache is automatically purged after a while." ] }, { "cell_type": "code", "execution_count": 2, "id": "4ee81831-02aa-498d-a127-5d05dc9b58f8", "metadata": {}, "outputs": [], "source": [ "%run gem_helpers.ipynb # see https://easy.gems.dkrz.de/Processing/Intake/gem_helpers.html" ] }, { "cell_type": "code", "execution_count": 3, "id": "0478ce7b-4f50-4439-a9c9-a2b283281a38", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Caching results in /scratch/k/k202134/intake_demo_data\n" ] } ], "source": [ "data_cache_path = make_tempdir(\"intake_demo_data\")\n", "print(\"Caching results in\", data_cache_path)" ] }, { "cell_type": "markdown", "id": "3c8f5012-f33b-4c17-9c8c-17924083f274", "metadata": {}, "source": [ "### Helper function for caching and loading" ] }, { "cell_type": "code", "execution_count": 4, "id": "6e944c20-5f51-427b-a9b7-01bc0bfdda1d", "metadata": {}, "outputs": [], "source": [ "def cache_data(data, filename):\n", " cache_file = os.path.join(data_cache_path, filename)\n", " if not os.access(cache_file, os.R_OK):\n", " data = data.compute()\n", " data.to_netcdf(cache_file)\n", " else:\n", " if type(data) == xr.core.dataarray.DataArray:\n", " data = xr.open_dataarray(cache_file)\n", " else:\n", " data = xr.open_dataset(cache_file)\n", " return data" ] }, { "cell_type": "markdown", "id": "62e4a6d7-f869-4f43-9d39-4e5add9b2eb3", "metadata": {}, "source": [ "## The catalog containing all the data" ] }, { "cell_type": "code", "execution_count": 5, "id": "76e954d6-85e6-4fd6-98af-0a522affbfca", "metadata": {}, "outputs": [], "source": [ "catalog_file = \"/work/ka1081/Catalogs/dyamond-nextgems.json\"" ] }, { "cell_type": "code", "execution_count": 6, "id": "1a529e8e-1fc9-4041-9b19-adc52323624e", "metadata": {}, "outputs": [ { "data": { "text/html": [ "

ICON-ESM catalog with 130 dataset(s) from 88823 asset(s):

\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", " \n", " \n", " \n", " \n", "
unique
variable_id546
project2
institution_id12
source_id19
experiment_id4
simulation_id12
realm5
frequency12
time_reduction4
grid_label7
level_type9
time_min918
time_max1094
grid_id3
format1
uri88813
\n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "cat = intake.open_esm_datastore(catalog_file)\n", "cat" ] }, { "cell_type": "code", "execution_count": 7, "id": "9d3f8de7-741c-434b-b3b3-e54011ed0f3a", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\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", " \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", " \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", "
projectsource_idexperiment_idsimulation_id
0DYAMOND_WINTERARPEGE-NH-2kmDW-ATMr1i1p1f1
1DYAMOND_WINTERGEMDW-ATMr1i1p1f1
2DYAMOND_WINTERGEOS-1kmDW-ATMr1i1p1f1
3DYAMOND_WINTERGEOS-3kmDW-ATMr1i1p1f1
4DYAMOND_WINTERGEOS-6kmDW-CPLr1i1p1f1
5DYAMOND_WINTERICON-NWP-2kmDW-ATMr1i1p1f1
6DYAMOND_WINTERICON-SAP-5kmDW-ATMdpp0014
7DYAMOND_WINTERICON-SAP-5kmDW-CPLdpp0029
8DYAMOND_WINTERIFS-4kmDW-CPLr1i1p1f1
9DYAMOND_WINTERIFS-9kmDW-CPLr1i1p1f1
10DYAMOND_WINTERNICAM-3kmDW-ATMr1i1p1f1
11DYAMOND_WINTERNICAM-3kmDW-CPLr1i1p1f1
12DYAMOND_WINTERSAM2-4kmDW-ATMr1i1p1f1
13DYAMOND_WINTERSCREAM-3kmDW-ATMr1i1p1f1
14DYAMOND_WINTERSHiELD-3kmDW-ATMr1i1p1f1
15DYAMOND_WINTERUM-5kmDW-ATMr1i1p1f1
16NextGEMSICON-ESMCycle2-alphadpp0066
17NextGEMSICON-ESMCycle2-alphadpp0067
18NextGEMSICON-SAP-5kmCycle1dpp0052
19NextGEMSICON-SAP-5kmCycle1dpp0054
20NextGEMSICON-SAP-5kmCycle1dpp0065
21NextGEMSIFS-FESOM2-4kmCycle1hlq0
22NextGEMSIFS-NEMO-4kmCycle1hmrt
23NextGEMSIFS-NEMO-9kmCycle1hmt0
24NextGEMSIFS-NEMO-DEEPon-4kmCycle1hmwz
\n", "
" ], "text/plain": [ " project source_id experiment_id simulation_id\n", "0 DYAMOND_WINTER ARPEGE-NH-2km DW-ATM r1i1p1f1\n", "1 DYAMOND_WINTER GEM DW-ATM r1i1p1f1\n", "2 DYAMOND_WINTER GEOS-1km DW-ATM r1i1p1f1\n", "3 DYAMOND_WINTER GEOS-3km DW-ATM r1i1p1f1\n", "4 DYAMOND_WINTER GEOS-6km DW-CPL r1i1p1f1\n", "5 DYAMOND_WINTER ICON-NWP-2km DW-ATM r1i1p1f1\n", "6 DYAMOND_WINTER ICON-SAP-5km DW-ATM dpp0014\n", "7 DYAMOND_WINTER ICON-SAP-5km DW-CPL dpp0029\n", "8 DYAMOND_WINTER IFS-4km DW-CPL r1i1p1f1\n", "9 DYAMOND_WINTER IFS-9km DW-CPL r1i1p1f1\n", "10 DYAMOND_WINTER NICAM-3km DW-ATM r1i1p1f1\n", "11 DYAMOND_WINTER NICAM-3km DW-CPL r1i1p1f1\n", "12 DYAMOND_WINTER SAM2-4km DW-ATM r1i1p1f1\n", "13 DYAMOND_WINTER SCREAM-3km DW-ATM r1i1p1f1\n", "14 DYAMOND_WINTER SHiELD-3km DW-ATM r1i1p1f1\n", "15 DYAMOND_WINTER UM-5km DW-ATM r1i1p1f1\n", "16 NextGEMS ICON-ESM Cycle2-alpha dpp0066\n", "17 NextGEMS ICON-ESM Cycle2-alpha dpp0067\n", "18 NextGEMS ICON-SAP-5km Cycle1 dpp0052\n", "19 NextGEMS ICON-SAP-5km Cycle1 dpp0054\n", "20 NextGEMS ICON-SAP-5km Cycle1 dpp0065\n", "21 NextGEMS IFS-FESOM2-4km Cycle1 hlq0\n", "22 NextGEMS IFS-NEMO-4km Cycle1 hmrt\n", "23 NextGEMS IFS-NEMO-9km Cycle1 hmt0\n", "24 NextGEMS IFS-NEMO-DEEPon-4km Cycle1 hmwz" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# a somewhat closer look at the catalog using get_from_cat\n", "get_from_cat(cat, [\"project\", \"source_id\", \"experiment_id\", \"simulation_id\"])" ] }, { "cell_type": "markdown", "id": "e874654b-083d-4f5b-a05e-b79afdda9858", "metadata": {}, "source": [ "## Selecting 'tas' for two simulations from the catalog" ] }, { "cell_type": "code", "execution_count": 8, "id": "e988f177-7e51-4727-87f1-45e7ac701c15", "metadata": {}, "outputs": [ { "data": { "text/html": [ "

ICON-ESM catalog with 2 dataset(s) from 479 asset(s):

\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", " \n", " \n", " \n", " \n", "
unique
variable_id37
project1
institution_id1
source_id1
experiment_id1
simulation_id2
realm1
frequency1
time_reduction1
grid_label1
level_type1
time_min406
time_max406
grid_id1
format1
uri479
\n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "var = \"tas\"\n", "hits = cat.search(simulation_id=[\"dpp0066\", \"dpp0067\"], variable_id=[var])\n", "hits" ] }, { "cell_type": "markdown", "id": "5676d7c3-df12-409b-8526-af980e79bf5c", "metadata": {}, "source": [ "## Loading the data into xarray" ] }, { "cell_type": "code", "execution_count": 9, "id": "cf35a314-b258-4501-bf99-3ea5ff2078e5", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "--> The keys in the returned dictionary of datasets are constructed as follows:\n", "\t'project.institution_id.source_id.experiment_id.simulation_id.realm.frequency.time_reduction.grid_label.level_type'\n" ] }, { "data": { "text/html": [ "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " \n", " 100.00% [2/2 00:16<00:00]\n", "
\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# a dictionary containing all datasets in this match\n", "dataset_dict = hits.to_dataset_dict(\n", " cdf_kwargs={\n", " \"chunks\": dict(\n", " time=4,\n", " height=1,\n", " )\n", " }\n", ")\n", "# The chunks thing is important to prevent python from loading waaaaay to much data at a time and thus crashing." ] }, { "cell_type": "markdown", "id": "2304618e-bacf-43a8-96e0-1749a71cfceb", "metadata": {}, "source": [ "### A first look at the contents" ] }, { "cell_type": "code", "execution_count": 10, "id": "bc71ad65-8230-4055-ba0d-b1177b259e24", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "NextGEMS.MPI-M.ICON-ESM.Cycle2-alpha.dpp0067.atm.30minute.mean.gn.ml \n", "\n", " \n", "Dimensions: (time: 3458, height_2: 1, ncells: 83886080)\n", "Coordinates:\n", " * height_2 (height_2) float64 2.0\n", " * time (time) float64 2.02e+07 2.02e+07 2.02e+07 ... 2.02e+07 2.02e+07\n", "Dimensions without coordinates: ncells\n", "Data variables:\n", " tas (time, height_2, ncells) float32 dask.array\n", "Attributes: (12/14)\n", " title: ICON simulation\n", " references: see MPIM/DWD publications\n", " number_of_grid_used: 39\n", " uuidOfHGrid: e85b34ae-6577-11eb-81a9-93127e10b90d\n", " history: ./icon at 20220219 165833\\n./icon at 20220219 23...\n", " grid_file_uri: http://icon-downloads.mpimet.mpg.de/grids/public...\n", " ... ...\n", " source: icon-dkrz\\tgit@gitlab.dkrz.de:icon/icon-dkrz.git...\n", " institution: Max Planck Institute for Meteorology/Deutscher W...\n", " comment: Daniel Klocke (m218027) on l30783 (Linux 4.18.0-...\n", " Conventions: CF-1.6\n", " CDO: Climate Data Operators version 1.9.10 (https://m...\n", " intake_esm_dataset_key: NextGEMS.MPI-M.ICON-ESM.Cycle2-alpha.dpp0067.atm... \n", "\n", "\n", "\n", "\n", "NextGEMS.MPI-M.ICON-ESM.Cycle2-alpha.dpp0066.atm.30minute.mean.gn.ml \n", "\n", " \n", "Dimensions: (time: 19488, height_2: 1, ncells: 20971520)\n", "Coordinates:\n", " * height_2 (height_2) float64 2.0\n", " * time (time) float64 2.02e+07 2.02e+07 2.02e+07 ... 2.021e+07 2.021e+07\n", "Dimensions without coordinates: ncells\n", "Data variables:\n", " tas (time, height_2, ncells) float32 dask.array\n", "Attributes: (12/13)\n", " title: ICON simulation\n", " references: see MPIM/DWD publications\n", " number_of_grid_used: 15\n", " uuidOfHGrid: 0f1e7d66-637e-11e8-913b-51232bb4d8f9\n", " history: ./icon at 20220218 173036\\n./icon at 20220218 20...\n", " grid_file_uri: http://icon-downloads.mpimet.mpg.de/grids/public...\n", " ... ...\n", " intake_esm_varname: ['tas']\n", " source: icon-dkrz\\tgit@gitlab.dkrz.de:icon/icon-dkrz.git...\n", " institution: Max Planck Institute for Meteorology/Deutscher W...\n", " comment: Rene Redler (m300083) on l40544 (Linux 4.18.0-30...\n", " Conventions: CF-1.6\n", " intake_esm_dataset_key: NextGEMS.MPI-M.ICON-ESM.Cycle2-alpha.dpp0066.atm... \n", "\n", "\n", "\n", "\n" ] } ], "source": [ "for name, data in dataset_dict.items():\n", " print(name, \"\\n\\n\", data, \"\\n\\n\\n\\n\")" ] }, { "cell_type": "markdown", "id": "69a61330-03ca-40f9-a348-0fda803a113d", "metadata": {}, "source": [ "## Adding grid information" ] }, { "cell_type": "code", "execution_count": 11, "id": "48f7cf1e-b383-4316-9230-30c45e257acf", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "NextGEMS.MPI-M.ICON-ESM.Cycle2-alpha.dpp0067.atm.30minute.mean.gn.ml\n", "NextGEMS.MPI-M.ICON-ESM.Cycle2-alpha.dpp0066.atm.30minute.mean.gn.ml\n" ] } ], "source": [ "# to plot, we need to associate a grid file with the data. The easiest way is to get the info from the grid_file_uri attribute in the data.\n", "data_dict = {}\n", "for name, dataset in dataset_dict.items():\n", " print(name)\n", " grid_file_path = \"/pool/data/ICON\" + dataset.grid_file_uri.split(\".de\")[1]\n", " grid_data = xr.open_dataset(grid_file_path).rename(\n", " cell=\"ncells\"\n", " ) # the dimension has different names in the grid file and in the output.\n", " data = xr.merge((dataset, grid_data))\n", " fix_time_axis(data)\n", " data_dict[name] = data" ] }, { "cell_type": "code", "execution_count": 12, "id": "64d9c1c7-6c9a-4ee0-a91d-865608775e07", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
<xarray.DataArray 'tas' (time: 19488, height_2: 1, ncells: 20971520)>\n",
       "dask.array<concatenate, shape=(19488, 1, 20971520), dtype=float32, chunksize=(4, 1, 20971520), chunktype=numpy.ndarray>\n",
       "Coordinates:\n",
       "  * height_2  (height_2) float64 2.0\n",
       "  * time      (time) datetime64[ns] 2020-01-20 ... 2021-02-28T23:30:00.000115200\n",
       "    clon      (ncells) float64 ...\n",
       "    clat      (ncells) float64 ...\n",
       "Dimensions without coordinates: ncells\n",
       "Attributes:\n",
       "    standard_name:                tas\n",
       "    long_name:                    temperature in 2m\n",
       "    units:                        K\n",
       "    param:                        0.0.0\n",
       "    CDI_grid_type:                unstructured\n",
       "    number_of_grid_in_reference:  1
" ], "text/plain": [ "\n", "dask.array\n", "Coordinates:\n", " * height_2 (height_2) float64 2.0\n", " * time (time) datetime64[ns] 2020-01-20 ... 2021-02-28T23:30:00.000115200\n", " clon (ncells) float64 ...\n", " clat (ncells) float64 ...\n", "Dimensions without coordinates: ncells\n", "Attributes:\n", " standard_name: tas\n", " long_name: temperature in 2m\n", " units: K\n", " param: 0.0.0\n", " CDI_grid_type: unstructured\n", " number_of_grid_in_reference: 1" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# A brief overview of our data\n", "for name, data in data_dict.items():\n", " pass\n", "data[var]" ] }, { "cell_type": "markdown", "id": "b32c463c-6beb-4821-b79d-634883268292", "metadata": {}, "source": [ "## Computing time averages" ] }, { "cell_type": "code", "execution_count": 13, "id": "9bd9c459-8dbf-4bd2-bcf1-6397ac3f946f", "metadata": {}, "outputs": [], "source": [ "# Lazy evaluation in dask means computations are only performed when the result is used.\n", "\n", "for data in data_dict.values():\n", " data[\"tas\"].mean(\n", " dim=\"time\"\n", " ) # no actual work is done yet due to dask lazy evaluation." ] }, { "cell_type": "markdown", "id": "db2b91d8-cc75-4303-a59b-8f6f9bb077b5", "metadata": {}, "source": [ "### Caching time-averaged data for subsequent use" ] }, { "cell_type": "code", "execution_count": 14, "id": "e3380cc5-506a-4b90-80e1-c6b67f623fb5", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Min (tas) for NextGEMS.MPI-M.ICON-ESM.Cycle2-alpha.dpp0067.atm.30minute.mean.gn.ml is 309.189208984375\n", "Min (tas) for NextGEMS.MPI-M.ICON-ESM.Cycle2-alpha.dpp0066.atm.30minute.mean.gn.ml is 308.2714538574219\n" ] } ], "source": [ "# Computing the average March TAS and storing it to a netcdf file for later use.\n", "# This will be slow on the first run, but fast on any subsequent one.\n", "# See helpers at top for implementation\n", "for (name, data) in data_dict.items():\n", " tas_mar = data[\"tas\"].isel(time=(data.time.dt.month == 3)).mean(dim=\"time\")\n", " tas_mar = cache_data(tas_mar, f\"tas_mar_{name}.nc\")\n", " print(f\"Min (tas) for {name} is {tas_mar.max().values}\")" ] }, { "cell_type": "code", "execution_count": 15, "id": "c41559a7-e6a2-4269-a97a-cba28f18ad70", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Max (tas) for NextGEMS.MPI-M.ICON-ESM.Cycle2-alpha.dpp0067.atm.30minute.mean.gn.ml is 309.189208984375\n", "Max (tas) for NextGEMS.MPI-M.ICON-ESM.Cycle2-alpha.dpp0066.atm.30minute.mean.gn.ml is 308.2714538574219\n" ] } ], "source": [ "for (name, data) in data_dict.items():\n", " tas_mar = data[\"tas\"].isel(time=(data.time.dt.month == 3)).mean(dim=\"time\")\n", " tas_mar = cache_data(tas_mar, f\"tas_mar_{name}.nc\")\n", " print(f\"Max (tas) for {name} is {tas_mar.max().values}\")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (based on the module python3/2022.01)", "language": "python", "name": "python3_2022_01" }, "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.9" } }, "nbformat": 4, "nbformat_minor": 5 }