{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Plotting Precipitation Overview Maps" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here, we combine several aspects explored in the previous notebooks. We will\n", "\n", "* read the ICON grid file\n", "* read multiple ICON 2D data file and extract information on precipitation and\n", "* finally combine all precipitation fields to a multi-panel plot\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load Python Libraries " ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "\n", "# system libs\n", "import os, sys, glob\n", "\n", "# array operators and netcdf datasets\n", "import numpy as np\n", "import xarray as xr\n", "import datetime\n", "\n", "# plotting\n", "import pylab as plt\n", "import seaborn as sns\n", "sns.set_context('talk')\n", "\n", "# drawing onto a map\n", "import cartopy.crs as ccrs\n", "import cartopy.feature as cfeature\n", "import cartopy.io.shapereader as shpreader\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As mentioned in the notebook `03-Plottting_Precipitation_as_Time_Series.ipynb`, here we will import our tools module. The imported function `convert_timevec` will handle the time axis in the ICON data." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "sys.path.append( '/work/bb1224/2024_MS-COURSE/tools/analysis' )\n", "from tools import convert_timevec" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Open Data with `xarray`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### General Paths" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "exercise_path = '/work/bb1224/2024_MS-COURSE'\n", "data_path = f'{exercise_path}/data'\n", "icon_data_path = f'{data_path}/icon-lem'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is the content of the `data` directory:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['bc-init', 'grids-extpar', 'experiments']" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "os.listdir(icon_data_path)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "grid_name = 'lpz_r2'\n", "grid_path = f'{icon_data_path}/grids-extpar/{grid_name}'" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "exp_name = 'icon_lam_1dom_lpz-base'\n", "exp_path = f'{icon_data_path}/experiments/{exp_name}'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Grid File" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "grid1 = xr.open_dataset( f'{grid_path}/lpz_r2_dom01_DOM01.nc', chunks={} ) \n", "# grid1 = xr.open_dataset( f'{grid_path}/lpz_r2_dom02_DOM02.nc', chunks={} ) \n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Data Files " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Again, we use the `xarray`function `open_mfdataset` to read in multiple ICON datasets. The data are not load into memory, but handled as pointers." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "dset = xr.open_mfdataset( f'{exp_path}/2d_cloud_DOM01_ML_20210516T*Z.nc', chunks={'time':1}, combine='by_coords' ) \n", "# dset = xr.open_mfdataset( f'{exp_path}/2d_cloud_DOM02_ML_20210516T*.nc', chunks={'time':1}, combine='by_coords' ) " ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "dset['time'] = convert_timevec( dset.time.data )" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset>\n", "Dimensions: (time: 288, plev: 1, bnds: 2, plev_2: 1, plev_3: 1,\n", " ncells: 10212)\n", "Coordinates:\n", " * time (time) datetime64[ns] 2021-05-16 ... 2021-05-16T23:55:00\n", " * plev (plev) float64 0.0\n", " * plev_2 (plev_2) float64 400.0\n", " * plev_3 (plev_3) float64 800.0\n", "Dimensions without coordinates: bnds, ncells\n", "Data variables: (12/17)\n", " plev_bnds (time, plev, bnds) float64 dask.array<chunksize=(12, 1, 2), meta=np.ndarray>\n", " plev_2_bnds (time, plev_2, bnds) float64 dask.array<chunksize=(12, 1, 2), meta=np.ndarray>\n", " plev_3_bnds (time, plev_3, bnds) float64 dask.array<chunksize=(12, 1, 2), meta=np.ndarray>\n", " tqv_dia (time, ncells) float32 dask.array<chunksize=(1, 10212), meta=np.ndarray>\n", " tqc_dia (time, ncells) float32 dask.array<chunksize=(1, 10212), meta=np.ndarray>\n", " tqi_dia (time, ncells) float32 dask.array<chunksize=(1, 10212), meta=np.ndarray>\n", " ... ...\n", " cape (time, ncells) float32 dask.array<chunksize=(1, 10212), meta=np.ndarray>\n", " cape_ml (time, ncells) float32 dask.array<chunksize=(1, 10212), meta=np.ndarray>\n", " cin_ml (time, ncells) float32 dask.array<chunksize=(1, 10212), meta=np.ndarray>\n", " rain_con_rate (time, ncells) float32 dask.array<chunksize=(1, 10212), meta=np.ndarray>\n", " prec_con (time, ncells) float32 dask.array<chunksize=(1, 10212), meta=np.ndarray>\n", " prec_gsp (time, ncells) float32 dask.array<chunksize=(1, 10212), meta=np.ndarray>\n", "Attributes:\n", " CDI: Climate Data Interface version 2.2.4 (https://mpime...\n", " Conventions: CF-1.6\n", " number_of_grid_used: 99\n", " uuidOfHGrid: 718d4bb6-2c67-4c84-a5ab-440d28412a00\n", " institution: Max Planck Institute for Meteorology/Deutscher Wett...\n", " title: ICON simulation\n", " source: https://gitlab.dkrz.de/icon/icon-model.git@bbcca057...\n", " history: /home/k/k206107/workspace/icon-build/bin/icon at 20...\n", " references: see MPIM/DWD publications\n", " comment: v107 Workshop (k206107) on l10647 (Linux 4.18.0-425...
<xarray.DataArray (time: 288, ncells: 10212)>\n", "dask.array<mul, shape=(288, 10212), dtype=float64, chunksize=(1, 10212), chunktype=numpy.ndarray>\n", "Coordinates:\n", " * time (time) datetime64[ns] 2021-05-16 ... 2021-05-16T23:55:00\n", "Dimensions without coordinates: ncells\n", "Attributes:\n", " units: mm day-1