{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "tobac example: Tracking isolated convection based on updraft velocity and total condensate\n", "==" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This example notebook demonstrates the use of tobac to track isolated deep convective clouds in cloud-resolving model simulation output based on vertical velocity and total condensate mixing ratio.\n", "\n", "The simulation results used in this example were performed as part of the ACPC deep convection intercomparison case study (http://acpcinitiative.org/Docs/ACPC_DCC_Roadmap_171019.pdf) with WRF using the Morrison microphysics scheme. \n", "\n", "The data used in this example is downloaded from \"zenodo link\" automatically as part of the notebooks (This only has to be done once for all the tobac example notebooks)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Import libraries:**" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2026-02-02T20:19:16.014189Z", "iopub.status.busy": "2026-02-02T20:19:16.013655Z", "iopub.status.idle": "2026-02-02T20:19:16.866252Z", "shell.execute_reply": "2026-02-02T20:19:16.865799Z" } }, "outputs": [], "source": [ "# Import a range of python libraries used in this notebook:\n", "import datetime\n", "import shutil\n", "from pathlib import Path\n", "from six.moves import urllib\n", "\n", "import numpy as np\n", "import pandas as pd\n", "import xarray as xr\n", "\n", "import matplotlib.pyplot as plt\n", "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2026-02-02T20:19:16.867863Z", "iopub.status.busy": "2026-02-02T20:19:16.867694Z", "iopub.status.idle": "2026-02-02T20:19:18.234348Z", "shell.execute_reply": "2026-02-02T20:19:18.233948Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "using tobac version 1.6.2\n" ] } ], "source": [ "# Import tobac itself:\n", "import tobac\n", "print('using tobac version', str(tobac.__version__))" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2026-02-02T20:19:18.253049Z", "iopub.status.busy": "2026-02-02T20:19:18.252824Z", "iopub.status.idle": "2026-02-02T20:19:18.254974Z", "shell.execute_reply": "2026-02-02T20:19:18.254611Z" } }, "outputs": [], "source": [ "#Disable a couple of warnings:\n", "import warnings\n", "warnings.filterwarnings('ignore', category=UserWarning, append=True)\n", "warnings.filterwarnings('ignore', category=RuntimeWarning, append=True)\n", "warnings.filterwarnings('ignore', category=FutureWarning, append=True)\n", "warnings.filterwarnings('ignore',category=pd.io.pytables.PerformanceWarning)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Download and load example data:** \n", "The actual dowloading is only necessary once for all example notebooks." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2026-02-02T20:19:18.256445Z", "iopub.status.busy": "2026-02-02T20:19:18.256343Z", "iopub.status.idle": "2026-02-02T20:19:18.257894Z", "shell.execute_reply": "2026-02-02T20:19:18.257539Z" } }, "outputs": [], "source": [ "data_out=Path('../')" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2026-02-02T20:19:18.259080Z", "iopub.status.busy": "2026-02-02T20:19:18.258994Z", "iopub.status.idle": "2026-02-02T20:19:18.262402Z", "shell.execute_reply": "2026-02-02T20:19:18.261948Z" } }, "outputs": [], "source": [ "# Download the data: This only has to be done once for all tobac examples and can take a while\n", "data_file = list(data_out.rglob('data/Example_input_midlevelUpdraft.nc'))\n", "if len(data_file) == 0:\n", " file_path='https://zenodo.org/records/3195910/files/climate-processes/tobac_example_data-v1.0.1.zip'\n", " #file_path='http://zenodo..'\n", " tempfile=Path('temp.zip')\n", " print('start downloading data')\n", " request=urllib.request.urlretrieve(file_path, tempfile)\n", " print('start extracting data')\n", " shutil.unpack_archive(tempfile, data_out)\n", " tempfile.unlink()\n", " print('data extracted')\n", " data_file = list(data_out.rglob('data/Example_input_midlevelUpdraft.nc'))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Load Data from downloaded file:**" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2026-02-02T20:19:18.263695Z", "iopub.status.busy": "2026-02-02T20:19:18.263610Z", "iopub.status.idle": "2026-02-02T20:19:18.266870Z", "shell.execute_reply": "2026-02-02T20:19:18.266442Z" } }, "outputs": [], "source": [ "data_file_W_mid_max = list(data_out.rglob('data/Example_input_midlevelUpdraft.nc'))[0]\n", "data_file_TWC = list(data_out.rglob('data/Example_input_Condensate.nc'))[0]" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2026-02-02T20:19:18.267999Z", "iopub.status.busy": "2026-02-02T20:19:18.267922Z", "iopub.status.idle": "2026-02-02T20:19:18.923143Z", "shell.execute_reply": "2026-02-02T20:19:18.922516Z" } }, "outputs": [], "source": [ "W_mid_max = xr.open_dataset(data_file_W_mid_max).w" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "execution": { "iopub.execute_input": "2026-02-02T20:19:18.925032Z", "iopub.status.busy": "2026-02-02T20:19:18.924817Z", "iopub.status.idle": "2026-02-02T20:19:18.934605Z", "shell.execute_reply": "2026-02-02T20:19:18.934065Z" } }, "outputs": [], "source": [ "TWC = xr.open_dataset(data_file_TWC).twc" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "execution": { "iopub.execute_input": "2026-02-02T20:19:18.936234Z", "iopub.status.busy": "2026-02-02T20:19:18.936129Z", "iopub.status.idle": "2026-02-02T20:19:18.949671Z", "shell.execute_reply": "2026-02-02T20:19:18.949260Z" } }, "outputs": [ { "data": { "text/html": [ "
<xarray.DataArray 'w' (time: 47, south_north: 198, west_east: 198)> Size: 7MB\n",
"[1842588 values with dtype=float32]\n",
"Coordinates:\n",
" * time (time) datetime64[ns] 376B 2013-06-19T20:05:00 ... 20...\n",
" * south_north (south_north) int64 2kB 281 282 283 284 ... 476 477 478\n",
" * west_east (west_east) int64 2kB 281 282 283 284 ... 476 477 478\n",
" bottom_top_stag int64 8B ...\n",
" latitude (south_north, west_east) float32 157kB ...\n",
" longitude (south_north, west_east) float32 157kB ...\n",
" model_level_number int64 8B ...\n",
" x (west_east) float64 2kB ...\n",
" y (south_north) float64 2kB ...\n",
" x_0 (west_east) int64 2kB ...\n",
" y_0 (south_north) int64 2kB ...\n",
"Attributes:\n",
" long_name: w\n",
" units: m s-1\n",
" cell_methods: model_level_number: maximum<xarray.DataArray 'twc' (time: 47, bottom_top: 94, south_north: 198,\n",
" west_east: 198)> Size: 693MB\n",
"[173203272 values with dtype=float32]\n",
"Coordinates:\n",
" * time (time) datetime64[ns] 376B 2013-06-19T20:05:00 ... 20...\n",
" * bottom_top (bottom_top) int64 752B 0 1 2 3 4 5 ... 89 90 91 92 93\n",
" * south_north (south_north) int64 2kB 281 282 283 284 ... 476 477 478\n",
" * west_east (west_east) int64 2kB 281 282 283 284 ... 476 477 478\n",
" latitude (south_north, west_east) float32 157kB ...\n",
" longitude (south_north, west_east) float32 157kB ...\n",
" model_level_number (bottom_top) int64 752B ...\n",
" x (west_east) float64 2kB ...\n",
" y (south_north) float64 2kB ...\n",
" x_0 (west_east) int64 2kB ...\n",
" y_0 (south_north) int64 2kB ...\n",
"Attributes:\n",
" long_name: TWC\n",
" units: kg kg-1