.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/ships.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_ships.py: ================== Reading SHIPS Data ================== This sample script illustrates how to leverage Tropycal's SHIPS reading capability. .. GENERATED FROM PYTHON SOURCE LINES 7-13 .. code-block:: default import json import datetime as dt import matplotlib.pyplot as plt from tropycal import tracks .. GENERATED FROM PYTHON SOURCE LINES 14-22 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 22-25 .. 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 (1.66 seconds) .. GENERATED FROM PYTHON SOURCE LINES 26-31 Reading in SHIPS data --------------------- SHIPS data can be read either using the standalone ``ships.Ships`` class by providing the SHIPS text data, or via Storm objects. The more conventional method is via Storm objects, as this automatically locates the SHIPS text files from UCAR's online archive dating back to 2011. Let's retrieve an instance of Hurricane Ida from 2021 for our example: .. GENERATED FROM PYTHON SOURCE LINES 31-34 .. code-block:: default storm = basin.get_storm(('ida',2021)) .. GENERATED FROM PYTHON SOURCE LINES 35-36 Next, let's search for times where SHIPS forecasts are available: .. GENERATED FROM PYTHON SOURCE LINES 36-42 .. code-block:: default available_times = storm.search_ships() for time in available_times: print(time) .. rst-class:: sphx-glr-script-out .. code-block:: none 2021-08-26 12:00:00 2021-08-26 18:00:00 2021-08-27 00:00:00 2021-08-27 06:00:00 2021-08-27 12:00:00 2021-08-27 18:00:00 2021-08-28 00:00:00 2021-08-28 06:00:00 2021-08-28 12:00:00 2021-08-28 18:00:00 2021-08-29 00:00:00 2021-08-29 06:00:00 2021-08-29 12:00:00 2021-08-29 18:00:00 2021-08-30 00:00:00 2021-08-30 06:00:00 2021-08-30 12:00:00 2021-08-30 18:00:00 .. GENERATED FROM PYTHON SOURCE LINES 43-44 Now that we know what times are available, let's use the SHIPS forecast from 1800 UTC 27 August 2021. The following line retrieves an instance of a Ships object and stores it in the variable ``ships``: .. GENERATED FROM PYTHON SOURCE LINES 44-47 .. code-block:: default ships = storm.get_ships(dt.datetime(2021, 8, 27, 18)) .. GENERATED FROM PYTHON SOURCE LINES 48-49 We now have a Ships object containing the forecast initialized at this time. Let's peek at our Ships object: .. GENERATED FROM PYTHON SOURCE LINES 49-52 .. code-block:: default print(ships) .. rst-class:: sphx-glr-script-out .. code-block:: none Variables: fhr (int) [0 .... 168] vmax_noland_kt (int) [70 .... 55] vmax_land_kt (int) [70 .... 27] vmax_lgem_kt (int) [70 .... 27] storm_type (str) [TROP .... TROP] shear_kt (int) [11 .... 16] shear_adj_kt (int) [-1 .... 0] shear_dir (int) [216 .... 348] sst_c (float) [29.5 .... 29.3] vmax_pot_kt (int) [162 .... 156] 200mb_temp_c (float) [-52.8 .... -54.1] thetae_dev_c (int) [9 .... 1] 700_500_rh (int) [64 .... 45] model_vortex_kt (int) [17 .... 7] 850mb_env_vort (int) [47 .... 16] 200mb_div (int) [86 .... -35] 700_850_tadv (int) [8 .... -8] dist_land_km (int) [98 .... -32] lat (float) [21.6 .... nan] lon (float) [-82.7 .... nan] storm_speed_kt (int) [14 .... 7] heat_content (int) [71 .... 4] RI Probabilities: 20kt/12hr: 61% (12.4x climo mean) 25kt/24hr: 82% (7.5x climo mean) 30kt/24hr: 76% (11.1x climo mean) 35kt/24hr: 70% (17.9x climo mean) 40kt/24hr: 53% (22.2x climo mean) 45kt/36hr: 73% (15.8x climo mean) 55kt/48hr: 47% (10.0x climo mean) 65kt/72hr: 31% (5.9x climo mean) Attributes: forecast_init: 2021-08-27 18:00:00 storm_name: IDA storm_bearing_deg: 325 storm_motion_kt: 14 max_wind_t-12_kt: 45 steering_level_pres_hpa: 518 steering_level_pres_mean_hpa: 620 brightness_temp_stdev: 4.8 brightness_temp_stdev_mean: 14.5 pixels_below_-20c: 99.0 pixels_below_-20c_mean: 65.0 lat: 21.6 lon: -82.7 .. GENERATED FROM PYTHON SOURCE LINES 53-57 Retrieving Data --------------- There's a lot of data in this object, as SHIPS files provide a lot of variables over many forecast hours. If we want data only valid at a specific forecast hour, we can use the following method: .. GENERATED FROM PYTHON SOURCE LINES 57-63 .. code-block:: default output_dict = ships.get_snapshot(hour=48) # Format nicely for documentation purposes print(json.dumps(output_dict, indent=4)) .. rst-class:: sphx-glr-script-out .. code-block:: none { "fhr": 48, "vmax_noland_kt": 121, "vmax_land_kt": 116, "vmax_lgem_kt": 127, "storm_type": "TROP", "shear_kt": 9, "shear_adj_kt": -5, "shear_dir": 263, "sst_c": 30.7, "vmax_pot_kt": 171, "200mb_temp_c": -51.8, "thetae_dev_c": 7, "700_500_rh": 73, "model_vortex_kt": 29, "850mb_env_vort": -8, "200mb_div": 41, "700_850_tadv": 6, "dist_land_km": 62, "lat": 28.6, "lon": -90.5, "storm_speed_kt": 8, "heat_content": 42 } .. GENERATED FROM PYTHON SOURCE LINES 64-65 We can also fetch the rapid intensification probabilities that SHIPS provides: .. GENERATED FROM PYTHON SOURCE LINES 65-71 .. code-block:: default output_dict = ships.get_ri_prob() # Format nicely for documentation purposes print(json.dumps(output_dict, indent=4)) .. rst-class:: sphx-glr-script-out .. code-block:: none { "20kt/12hr": { "probability": 61, "climo_mean": 4.9, "prob / climo": 12.4 }, "25kt/24hr": { "probability": 82, "climo_mean": 10.9, "prob / climo": 7.5 }, "30kt/24hr": { "probability": 76, "climo_mean": 6.8, "prob / climo": 11.1 }, "35kt/24hr": { "probability": 70, "climo_mean": 3.9, "prob / climo": 17.9 }, "40kt/24hr": { "probability": 53, "climo_mean": 2.4, "prob / climo": 22.2 }, "45kt/36hr": { "probability": 73, "climo_mean": 4.6, "prob / climo": 15.8 }, "55kt/48hr": { "probability": 47, "climo_mean": 4.7, "prob / climo": 10.0 }, "65kt/72hr": { "probability": 31, "climo_mean": 5.3, "prob / climo": 5.9 } } .. GENERATED FROM PYTHON SOURCE LINES 72-73 Ships objects also allow us to convert data to other formats, such as xarray Datasets: .. GENERATED FROM PYTHON SOURCE LINES 73-77 .. code-block:: default ds = ships.to_xarray() print(ds) .. rst-class:: sphx-glr-script-out .. code-block:: none Dimensions: (fhr: 17) Coordinates: * fhr (fhr) int64 0 6 12 18 24 36 48 ... 108 120 132 144 156 168 Data variables: (12/21) vmax_noland_kt (fhr) int64 70 80 89 98 106 112 121 ... 74 66 61 58 57 55 vmax_land_kt (fhr) int64 70 67 83 92 100 107 116 ... 27 27 27 27 27 27 vmax_lgem_kt (fhr) int64 70 70 85 94 102 120 127 ... 27 27 27 27 27 27 storm_type (fhr) .. GENERATED FROM PYTHON SOURCE LINES 86-87 Let's say we want to make a plot of several metrics that affect a storm's intensity: .. GENERATED FROM PYTHON SOURCE LINES 87-114 .. code-block:: default # Create figure fig,ax = plt.subplots(figsize=(9,6), dpi=200) ax.set_facecolor('#f6f6f6') ax.grid() # Plot variables ax.plot(ships.fhr, ships.shear_kt, color='blue', label='Shear (kt)') ax.plot(ships.fhr, ships.sst_c, color='red', label='SSTs (C)') ax.plot(ships.fhr, ships['700_500_rh'], color='green', label='700-500mb RH (%)') ax.set_ylabel('Shear, SST, RH') # Add twin axes for wind speed ax2 = ax.twinx() ax2.plot(ships.fhr, ships.vmax_land_kt, color='k', linewidth=2.5) ax2.set_ylabel('Wind Speed (kt)') # Format and label x-axis ax.set_xticks(range(0,ships.fhr[-1]+1,24)) ax.set_xlabel('Forecast Hour') # Add legend and title ax.legend() ax.set_title(f"SHIPS Forecast for {ships.attrs['storm_name']}", loc='left', fontsize=14, fontweight='bold') ax.set_title(f"Initialized: {ships.attrs['forecast_init'].strftime('%H%M UTC %d %b %Y')}", loc='right', fontsize=10) .. image-sg:: /examples/images/sphx_glr_ships_002.png :alt: SHIPS Forecast for IDA, Initialized: 1800 UTC 27 Aug 2021 :srcset: /examples/images/sphx_glr_ships_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Text(1.0, 1.0, 'Initialized: 1800 UTC 27 Aug 2021') .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 3.759 seconds) .. _sphx_glr_download_examples_ships.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: ships.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: ships.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_