{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "tobac example: Tracking of precipitation features\n", "===\n", "This example notebook demonstrates the use of tobac to track precipitation features from isolated deep convective clouds.\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 necessary python libraries:**" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2026-02-02T20:14:41.054935Z", "iopub.status.busy": "2026-02-02T20:14:41.054540Z", "iopub.status.idle": "2026-02-02T20:14:41.808031Z", "shell.execute_reply": "2026-02-02T20:14:41.807373Z" } }, "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:14:41.809738Z", "iopub.status.busy": "2026-02-02T20:14:41.809542Z", "iopub.status.idle": "2026-02-02T20:14:43.088254Z", "shell.execute_reply": "2026-02-02T20:14:43.087673Z" } }, "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:14:43.107401Z", "iopub.status.busy": "2026-02-02T20:14:43.107123Z", "iopub.status.idle": "2026-02-02T20:14:43.109424Z", "shell.execute_reply": "2026-02-02T20:14:43.109044Z" } }, "outputs": [], "source": [ "# Disable a few 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)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Download example data:**\n", "\n", "Actual download has to be performed only once for all example notebooks!" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2026-02-02T20:14:43.110736Z", "iopub.status.busy": "2026-02-02T20:14:43.110629Z", "iopub.status.idle": "2026-02-02T20:14:43.112288Z", "shell.execute_reply": "2026-02-02T20:14:43.111987Z" } }, "outputs": [], "source": [ "data_out=Path('../')" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2026-02-02T20:14:43.113563Z", "iopub.status.busy": "2026-02-02T20:14:43.113470Z", "iopub.status.idle": "2026-02-02T20:14:43.116890Z", "shell.execute_reply": "2026-02-02T20:14:43.116469Z" } }, "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_Precip.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_Precip.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:14:43.118042Z", "iopub.status.busy": "2026-02-02T20:14:43.117958Z", "iopub.status.idle": "2026-02-02T20:14:43.759999Z", "shell.execute_reply": "2026-02-02T20:14:43.759475Z" } }, "outputs": [], "source": [ "Precip = xr.open_dataset(data_file[0]).surface_precipitation_average" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2026-02-02T20:14:43.761593Z", "iopub.status.busy": "2026-02-02T20:14:43.761434Z", "iopub.status.idle": "2026-02-02T20:14:43.768236Z", "shell.execute_reply": "2026-02-02T20:14:43.767908Z" } }, "outputs": [ { "data": { "text/html": [ "
<xarray.DataArray 'surface_precipitation_average' (time: 47, south_north: 198,\n",
" west_east: 198)> Size: 7MB\n",
"[1842588 values with dtype=float32]\n",
"Coordinates:\n",
" * time (time) datetime64[ns] 376B 2013-06-19T20:05:00 ... 2013-06-1...\n",
" * south_north (south_north) int64 2kB 281 282 283 284 285 ... 475 476 477 478\n",
" * west_east (west_east) int64 2kB 281 282 283 284 285 ... 475 476 477 478\n",
" latitude (south_north, west_east) float32 157kB ...\n",
" longitude (south_north, west_east) float32 157kB ...\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: surface_precipitation_average\n",
" units: mm h-1| \n", " | frame | \n", "idx | \n", "hdim_1 | \n", "hdim_2 | \n", "num | \n", "threshold_value | \n", "feature | \n", "time | \n", "timestr | \n", "south_north | \n", "west_east | \n", "latitude | \n", "longitude | \n", "x | \n", "y | \n", "x_0 | \n", "y_0 | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | \n", "0 | \n", "1 | \n", "50.065727 | \n", "139.857477 | \n", "9 | \n", "1 | \n", "1 | \n", "2013-06-19 20:05:00 | \n", "2013-06-19 20:05:00 | \n", "331.065727 | \n", "420.857477 | \n", "29.846362 | \n", "-94.172015 | \n", "210678.738492 | \n", "165782.863285 | \n", "420.857477 | \n", "331.065727 | \n", "
| 1 | \n", "0 | \n", "15 | \n", "120.527119 | \n", "172.500325 | \n", "4 | \n", "1 | \n", "2 | \n", "2013-06-19 20:05:00 | \n", "2013-06-19 20:05:00 | \n", "401.527119 | \n", "453.500325 | \n", "30.166929 | \n", "-93.996892 | \n", "227000.162468 | \n", "201013.559414 | \n", "453.500325 | \n", "401.527119 | \n", "
| 2 | \n", "0 | \n", "18 | \n", "126.779273 | \n", "145.368401 | \n", "15 | \n", "1 | \n", "3 | \n", "2013-06-19 20:05:00 | \n", "2013-06-19 20:05:00 | \n", "407.779273 | \n", "426.368401 | \n", "30.196499 | \n", "-94.139960 | \n", "213434.200454 | \n", "204139.636582 | \n", "426.368401 | \n", "407.779273 | \n", "
| 3 | \n", "0 | \n", "34 | \n", "111.611369 | \n", "155.452030 | \n", "4 | \n", "2 | \n", "4 | \n", "2013-06-19 20:05:00 | \n", "2013-06-19 20:05:00 | \n", "392.611369 | \n", "436.452030 | \n", "30.126871 | \n", "-94.087317 | \n", "218476.015240 | \n", "196555.684682 | \n", "436.452030 | \n", "392.611369 | \n", "
| 4 | \n", "0 | \n", "35 | \n", "111.765231 | \n", "164.938866 | \n", "8 | \n", "2 | \n", "5 | \n", "2013-06-19 20:05:00 | \n", "2013-06-19 20:05:00 | \n", "392.765231 | \n", "445.938866 | \n", "30.127221 | \n", "-94.037226 | \n", "223219.433218 | \n", "196632.615461 | \n", "445.938866 | \n", "392.765231 | \n", "