.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/tracks.tornado.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_tracks.tornado.py: ========================= Tornado Analyses ========================= This sample script illustrates how to retrieve and analyze the Storm Prediction Center (SPC) tornado database (1950-present), using both the tornado and tracks modules. For documentation generation purposes, return_ax must be set True for plotting functions. You don't need to have this extra argument in every plotting function call (e.g., "storm.plot(return_ax=True)" will produce the same output as "storm.plot()"). .. GENERATED FROM PYTHON SOURCE LINES 9-14 .. code-block:: default import tropycal.tracks as tracks import tropycal.tornado as tornado import datetime as dt .. GENERATED FROM PYTHON SOURCE LINES 15-18 Using TornadoDataset -------------------- Let's start by creating an instance of a TornadoDataset object. By default, this reads in the SPC tornado database from their website. .. GENERATED FROM PYTHON SOURCE LINES 18-21 .. code-block:: default tor_data = tornado.TornadoDataset() .. rst-class:: sphx-glr-script-out .. code-block:: none --> Starting to read in tornado track data /Users/tomerburg/python/github/tropycal/src/tropycal/tornado/dataset.py:59: FutureWarning: The error_bad_lines argument has been deprecated and will be removed in a future version. Use on_bad_lines in the future. Tors = pd.read_csv(f'https://www.spc.noaa.gov/wcm/data/1950-{yrlast}_actual_tornadoes.csv', --> Completed reading in tornado data for 1950-2022 (8.11 seconds) .. GENERATED FROM PYTHON SOURCE LINES 22-23 We can use a TornadoDataset object to analyze both tornadoes associated with tropical cyclones and non-TC tornadoes. As an example of the latter, we can make a plot of all tornadoes during the 27 April 2011 tornado outbreak, along with the Practically Perfect Forecast (PPH) in filled contours: .. GENERATED FROM PYTHON SOURCE LINES 23-27 .. code-block:: default tor_ax,domain,leg_tor = tor_data.plot_tors(dt.datetime(2011,4,27),plotPPH=True,return_ax=True) tor_ax .. image-sg:: /examples/images/sphx_glr_tracks.tornado_001.png :alt: Tornado tracks and daily PPH (%), Start ... 12:02 UTC 27 Apr 2011 End ... 11:50 UTC 28 Apr 2011 :srcset: /examples/images/sphx_glr_tracks.tornado_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /Users/tomerburg/python/github/tropycal/src/tropycal/tornado/tools.py:36: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy dfTors['SPC_time'] = dfTors['UTC_time'] - timedelta(hours=12) .. GENERATED FROM PYTHON SOURCE LINES 28-31 Using TrackDataset ------------------ We can also use TornadoDataset to assess tornadoes associated with tropical cyclones. First off let's get an instance of TrackDataset for the North Atlantic HURDAT2 basin: .. GENERATED FROM PYTHON SOURCE LINES 31-34 .. code-block:: default hurdat_atl = tracks.TrackDataset(basin='north_atlantic',source='hurdat',include_btk=False) .. rst-class:: sphx-glr-script-out .. code-block:: none --> Starting to read in HURDAT2 data --> Completed reading in HURDAT2 data (2.29 seconds) .. GENERATED FROM PYTHON SOURCE LINES 35-40 This instance of Storm contains several methods that return the storm data back in different data types. The following examples will show how to retrieve 3 different data types. Now we want to attribute tornadoes from the SPC database to all tropical cyclones which produced tornadoes. We do so using the ``assign_storm_tornadoes()`` method of TrackDataset. The main input parameter is "dist_thresh", which controls the distance from the tropical cyclone center over which to attribute tornadoes to. For this example we'll use 750 kilometers as the threshold. This code block will take a while to run, as it will iterate over every storm in HURDAT2 and match tornadoes to those that produced them. .. GENERATED FROM PYTHON SOURCE LINES 40-43 .. code-block:: default hurdat_atl.assign_storm_tornadoes(dist_thresh=750) .. rst-class:: sphx-glr-script-out .. code-block:: none --> Starting to read in tornado track data --> Completed reading in tornado data for 1950-2022 (5.28 seconds) --> Starting to assign tornadoes to storms --> Completed assigning tornadoes to storm (164.94 seconds) .. GENERATED FROM PYTHON SOURCE LINES 44-47 Once the above block is done running, we can now look at a climatology of tornadoes associated with North Atlantic tropical cyclones. The current method of analysis is via the ``plot_TCtors_rotated()`` method, which rotates tropical cyclones to a storm motion relative framework. Most tornadoes associated with tropical cyclones occur in the front right quadrant (i.e., forward and right of the storm track). We can visualize this by plotting all tornadoes associated with tropical cyclones in a motion relative framework: .. GENERATED FROM PYTHON SOURCE LINES 47-50 .. code-block:: default hurdat_atl.plot_TCtors_rotated('all') .. image-sg:: /examples/images/sphx_glr_tracks.tornado_002.png :alt: Composite motion-relative tornadoes Min threshold: EF-0 | n=242 storms :srcset: /examples/images/sphx_glr_tracks.tornado_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 51-52 We can also make the same plot for a composite subset of tropical cyclones, given either their IDs (e.g., "AL052004"), or a storm tuple. For instance, let's composite the four hurricanes that made landfall in Florida in 2004: .. GENERATED FROM PYTHON SOURCE LINES 52-55 .. code-block:: default hurdat_atl.plot_TCtors_rotated(storms=[('charley',2004),('frances',2004),('ivan',2004),('jeanne',2004)]) .. image-sg:: /examples/images/sphx_glr_tracks.tornado_003.png :alt: Composite motion-relative tornadoes Min threshold: EF-0 | n=4 storms :srcset: /examples/images/sphx_glr_tracks.tornado_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 56-64 Using a Storm object -------------------- Tropical cyclone tornado analyses can also be done via a Storm object. Let's get the data for Hurricane Ivan from 2004, which produced a major tornado outbreak: .. warning:: If you retrieve an instance of a Storm object without first running ``TrackDataset.assign_storm_tornadoes()`` method, doing tornado analyses with a Storm object will require re-downloading the tornado database for each new instance of Storm. If you plan to analyze multiple storms with tornadoes, it is recommended to run ``assign_storm_tornadoes()`` first. .. GENERATED FROM PYTHON SOURCE LINES 64-67 .. code-block:: default storm = hurdat_atl.get_storm(('ivan',2004)) .. GENERATED FROM PYTHON SOURCE LINES 68-69 Let's plot all the tornado tracks, and daily PPH, associated with Hurricane Ivan: .. GENERATED FROM PYTHON SOURCE LINES 69-72 .. code-block:: default storm.plot_tors(plotPPH=True) .. image-sg:: /examples/images/sphx_glr_tracks.tornado_004.png :alt: Hurricane IVAN Tornado tracks and daily PPH (%), 02 Sep 2004 – 24 Sep 2004 145 kt • 910 hPa • 70.4 ACE :srcset: /examples/images/sphx_glr_tracks.tornado_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 73-74 Let's make a plot of the tornadoes in storm motion relative coordinates: .. GENERATED FROM PYTHON SOURCE LINES 74-76 .. code-block:: default storm.plot_TCtors_rotated() .. image-sg:: /examples/images/sphx_glr_tracks.tornado_005.png :alt: IVAN 2004 tornadoes relative to heading :srcset: /examples/images/sphx_glr_tracks.tornado_005.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 3 minutes 6.997 seconds) .. _sphx_glr_download_examples_tracks.tornado.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: tracks.tornado.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: tracks.tornado.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_