.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/tc_rainfall.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_tc_rainfall.py: ========================= Tropical Cyclone Rainfall ========================= This sample script shows how to use Tropycal to retrieve and plot rainfall associated with U.S. tropical cyclones, from the Weather Prediction Center (WPC)'s database. .. GENERATED FROM PYTHON SOURCE LINES 7-10 .. code-block:: default from tropycal import tracks, rain .. GENERATED FROM PYTHON SOURCE LINES 11-19 Reading In HURTDAT2 Dataset --------------------------- Let's start with the HURDAT2 dataset by loading it into memory. By default, this reads in the HURDAT dataset from the National Hurricane Center (NHC) website, unless you specify a local file path using either ``atlantic_url`` for the North Atlantic basin on ``pacific_url`` for the East & Central Pacific basin. HURDAT data is not available for the current year. To include the latest data up through today, the "include_btk" flag needs to be set to True, which reads in preliminary best track data from the NHC website. For this example, we'll set this to False. Let's create an instance of a TrackDataset object, which will store the North Atlantic HURDAT2 dataset in memory. Once we have this we can use its methods for various types of analyses. .. GENERATED FROM PYTHON SOURCE LINES 19-22 .. code-block:: default basin = tracks.TrackDataset(basin='north_atlantic',include_btk=False) .. rst-class:: sphx-glr-script-out .. code-block:: none --> Starting to read in HURDAT2 data --> Completed reading in HURDAT2 data (2.16 seconds) .. GENERATED FROM PYTHON SOURCE LINES 23-29 WPC Rainfall Dataset -------------------- Next, we'll read in rainfall associated with tropical cyclones. Tropical cyclones are known to produce heavy rainfall, with at times catastrophic flooding. The Weather Prediction Center (WPC) routinely issues advisories on tropical cyclones or their remnants inland, and maintains a database of rainfall associated with tropical cyclones in the US. This dataset is now available in CSV format, and can be easily read into Tropycal using the new Rain module: .. GENERATED FROM PYTHON SOURCE LINES 29-32 .. code-block:: default rain_obj = rain.RainDataset() .. rst-class:: sphx-glr-script-out .. code-block:: none --> Starting to read in rainfall data --> Completed reading in rainfall data (8.87 seconds) .. GENERATED FROM PYTHON SOURCE LINES 33-36 Hurricane Harvey (2017) produced catastrophic flooding over Texas. Let's pull its rain observations to take a deeper look. To do so, we'll first need to retrieve a Storm object for Harvey, then provide it as an input argument to ``get_storm_rainfall()``. This will return a Pandas DataFrame containing all rainfall observations associated with Harvey. .. GENERATED FROM PYTHON SOURCE LINES 36-43 .. code-block:: default #Retrieve storm object storm = basin.get_storm(('harvey',2017)) #Retrieve storm rainfall harvey_rain = rain_obj.get_storm_rainfall(storm) .. GENERATED FROM PYTHON SOURCE LINES 44-45 Now let's look through the pandas DataFrame containing Harvey's rainfall: .. GENERATED FROM PYTHON SOURCE LINES 45-48 .. code-block:: default harvey_rain .. raw:: html
Station Total Lat Lon
261570 ABEL 5 SW 1.79 33.60 -85.65
261571 ADDISON 2.17 34.20 -87.18
261572 ALABASTER 1.42 33.18 -86.78
261573 ALBERTVILLE 1.63 34.24 -86.19
261574 ALEXANDER CITY 2.46 32.95 -85.95
... ... ... ... ...
268375 WHITE SULPHUR SPRINGS 1.14 37.80 -80.48
268376 WHITE SULPHUR SPRINGS 0.96 37.80 -80.30
268377 WHITMER 3 W 0.20 38.82 -79.60
268378 WILLIAMSON 0.61 37.67 -82.28
268379 WOLF PEN 0.40 37.53 -81.58

6797 rows × 4 columns



.. GENERATED FROM PYTHON SOURCE LINES 49-50 We can use Pandas' DataFrame utility to rearrange this by the "Total" column (representing rainfall in inches) to see the highest rain total associated with Harvey - which gives us 60.58 inches near Nederland. .. GENERATED FROM PYTHON SOURCE LINES 50-53 .. code-block:: default harvey_rain.sort_values('Total',ascending=False) .. raw:: html
Station Total Lat Lon
267161 Nederland 1.5 SW 60.58 29.950000 -94.010000
266354 Groves 1.3 N 60.54 29.960000 -93.920000
266199 Friendswood 56.00 29.500000 -95.200000
267575 Santa Fe 3 ENE 54.77 29.390000 -95.050000
265621 Friendswood 54.00 29.745100 -95.566600
... ... ... ... ...
263372 MADISON 0.00 39.430000 -92.170000
266215 Fulshear 2.7 WNW 0.00 29.707364 -95.939681
263375 MARSHALL 0.00 39.130000 -93.220000
263376 MARSHFIELD 0.00 37.340000 -92.900000
263374 MANSFIELD 0.00 37.120000 -92.580000

6797 rows × 4 columns



.. GENERATED FROM PYTHON SOURCE LINES 54-55 More generically speaking, we can write the code below to retrieve the row with the maximum rainfall for the storm, then retrieve its rain total in inches, station name, and coordinates. .. GENERATED FROM PYTHON SOURCE LINES 55-65 .. code-block:: default import numpy as np row = harvey_rain.loc[harvey_rain['Total'] == np.nanmax(harvey_rain['Total'])] print(f"Max Rainfall = {row['Total'].values[0]} Inches") print(f"Location = {row['Station'].values[0]}") print(f"Latitude = {row['Lat'].values[0]}") print(f"Longitude = {row['Lon'].values[0]}") .. rst-class:: sphx-glr-script-out .. code-block:: none Max Rainfall = 60.58 Inches Location = Nederland 1.5 SW Latitude = 29.95 Longitude = -94.01 .. GENERATED FROM PYTHON SOURCE LINES 66-73 Plotting TC Rainfall -------------------- Tropycal provides two methods to plot tropical cyclone rainfall: by grid, or by individual observations. We'll start off with plotting gridded rainfall. First we'll need to interpolate to a cartesian grid using the ``interpolate_to_grid()`` method, and retrieve an xarray DataArray of the grid and its associated coordinates. Note that the default is to interpolate to a 0.1 degree grid - you can use the ``grid_res`` argument to provide a different resolution. Next we'll use the ``plot_rain_grid()`` method to plot the output, and provide contour levels for plotting. As Hurricane Harvey was most damaging in Texas, we'll provide a custom domain zoomed in over Texas. .. GENERATED FROM PYTHON SOURCE LINES 73-80 .. code-block:: default #Interpolate to grid grid = rain_obj.interpolate_to_grid(storm,return_xarray=True) levels = [1,2,4,8,12,16,20,30,40,50,60] rain_obj.plot_rain_grid(storm,grid,levels,domain={'s':26,'n':39,'w':-103,'e':-82}) .. image-sg:: /examples/images/sphx_glr_tc_rainfall_001.png :alt: Hurricane HARVEY Interpolated WPC Storm Rainfall (in), 17 Aug 2017 – 01 Sep 2017 115 kt • 937 hPa • 11.4 ACE :srcset: /examples/images/sphx_glr_tc_rainfall_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 81-84 Linear interpolation isn't perfect of course, especially considering that some observations in this dataset aren't perfectly quality controlled. To compensate, we can also plot the individual rain observation dots using the ``plot_rain()`` method: .. GENERATED FROM PYTHON SOURCE LINES 84-88 .. code-block:: default levels = [1,2,4,8,12,16,20,30,40,50,60] rain_obj.plot_rain(storm,levels=levels,domain={'s':26,'n':39,'w':-103,'e':-82}) .. image-sg:: /examples/images/sphx_glr_tc_rainfall_002.png :alt: Hurricane HARVEY WPC Storm Rainfall (inch), 17 Aug 2017 – 01 Sep 2017 115 kt • 937 hPa • 11.4 ACE :srcset: /examples/images/sphx_glr_tc_rainfall_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 89-92 The Houston, Texas metro was particularly hard-hit by Hurricane Harvey, with rain totals over 30 inches in many locations. Let's filter the plot to only rain observations over 30 inches to highlight this, while zooming in closer over Houston: .. GENERATED FROM PYTHON SOURCE LINES 92-94 .. code-block:: default levels = [1,2,4,8,12,16,20,30,40,50,60] rain_obj.plot_rain(storm,levels=levels,minimum_threshold=30,domain={'s':27,'n':32,'w':-99,'e':-92}) .. image-sg:: /examples/images/sphx_glr_tc_rainfall_003.png :alt: Hurricane HARVEY WPC Storm Rainfall (>30 inch), 17 Aug 2017 – 01 Sep 2017 115 kt • 937 hPa • 11.4 ACE :srcset: /examples/images/sphx_glr_tc_rainfall_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none 30 inch)', 'right': '17 Aug 2017 – 01 Sep 2017\n115 kt • 937 hPa • 11.4 ACE'}> .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 18.383 seconds) .. _sphx_glr_download_examples_tc_rainfall.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: tc_rainfall.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: tc_rainfall.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_