{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Plotting Precipitation as Time Series" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now, we will test how different ICON files can be combined together. This is done with `2d_cloud` files and a total (domain-average) precipitation time series will be plotted at the end. " ] }, { "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", "import datetime\n", "\n", "# array operators and netcdf datasets\n", "import numpy as np\n", "import xarray as xr\n", "xr.set_options(keep_attrs=True)\n", "\n", "# plotting\n", "import pylab as plt\n", "import seaborn as sns\n", "sns.set_context('talk')\n", "\n", "import matplotlib.dates as mdates\n", "myFmt = mdates.DateFormatter('%H:%M')\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Open Data with `xarray`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### General Paths" ] }, { "cell_type": "code", "execution_count": 2, "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 very similar to the tasks already done." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['bc-init', 'grids-extpar', 'experiments']" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "os.listdir(icon_data_path)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now, we select the `experiment`folder in which pre-calculated experiments are stored. **Later, you need to change this directory to your ICON output directory!** " ] }, { "cell_type": "code", "execution_count": 4, "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": [ "### Base Files " ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "dset = xr.open_mfdataset( f'{exp_path}/2d_cloud_DOM01_ML_20210516T*Z.nc', chunks={'time':1}, combine='by_coords' ) " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is the content of the dataset. " ] }, { "cell_type": "code", "execution_count": 6, "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) float64 2.021e+07 2.021e+07 ... 2.021e+07 2.021e+07\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...