
1、introduction
This sample script illustrates how to retrieve a single storm from the HURDAT2 dataset, and make plots and analyses of this storm.
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()").
2、import packets
1import tropycal.tracks as tracks
2import datetime as dt
3import warnings
4warnings.filterwarnings('ignore')
3、HURTDAT2 Dataset
Let's start by creating an instance of a TrackDataset object. By default, this reads in the HURDAT2 dataset from the National Hurricane Center (NHC) website. For this example we'll be using the HURDAT2 dataset over the North Atlantic basin.
HURDAT data is not available for the most recent hurricane seasons. To include the latest data up through today, the "include_btk" flag would need to be set to True, which reads in preliminary best track data from the NHC website.
1hurdat_atl = tracks.TrackDataset(basin='north_atlantic',source='hurdat',include_btk=False)
4、Individual storm analysis
Individual storms can be retrieved from the dataset by calling the get_storm() function, which returns an instance of a Storm object. This can be done by either entering a tuple containing the storm name and year, or by the standard tropical cyclone ID (e.g., "AL012019").
Let's retrieve an instance of Hurricane Michael from 2018:
1storm = hurdat_atl.get_storm(('michael',2018))
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.
Retrieve a dictionary of Michael's data:
1print(storm.to_dict())
2
3output:
4{'id': 'AL142018', 'operational_id': 'AL142018', 'name': 'MICHAEL', 'year': 2018, 'season': 2018, 'basin': 'north_atlantic', 'source_info': 'NHC Hurricane Database', 'source': 'hurdat', 'date': [datetime.datetime(2018, 10, 6, 18, 0), datetime.datetime(2018, 10, 7, 0, 0), datetime.datetime(2018, 10, 7, 6, 0), datetime.datetime(2018, 10, 7, 12, 0), datetime.datetime(2018, 10, 7, 18, 0), datetime.datetime(2018, 10, 8, 0, 0), datetime.datetime(2018, 10, 8, 6, 0), datetime.datetime(2018, 10, 8, 12, 0), datetime.datetime(2018, 10, 8, 18, 0), datetime.datetime(2018, 10, 9, 0, 0), datetime.datetime(2018, 10, 9, 6, 0), datetime.datetime(2018, 10, 9, 12, 0), datetime.datetime(2018, 10, 9, 18, 0), datetime.datetime(2018, 10, 10, 0, 0), datetime.datetime(2018, 10, 10, 6, 0), datetime.datetime(2018, 10, 10, 12, 0), datetime.datetime(2018, 10, 10, 17, 30), datetime.datetime(2018, 10, 10, 18, 0), datetime.datetime(2018, 10, 11, 0, 0), datetime.datetime(2018, 10, 11, 6, 0), datetime.datetime(2018, 10, 11, 12, 0), datetime.datetime(2018, 10, 11, 18, 0), datetime.datetime(2018, 10, 12, 0, 0), datetime.datetime(2018, 10, 12, 6, 0), datetime.datetime(2018, 10, 12, 12, 0), datetime.datetime(2018, 10, 12, 18, 0), datetime.datetime(2018, 10, 13, 0, 0), datetime.datetime(2018, 10, 13, 6, 0), datetime.datetime(2018, 10, 13, 12, 0), datetime.datetime(2018, 10, 13, 18, 0), datetime.datetime(2018, 10, 14, 0, 0), datetime.datetime(2018, 10, 14, 6, 0), datetime.datetime(2018, 10, 14, 12, 0), datetime.datetime(2018, 10, 14, 18, 0), datetime.datetime(2018, 10, 15, 0, 0), datetime.datetime(2018, 10, 15, 6, 0), datetime.datetime(2018, 10, 15, 12, 0), datetime.datetime(2018, 10, 15, 18, 0)], 'extra_obs': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'special': ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'L', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''], 'type': ['LO', 'LO', 'TD', 'TS', 'TS', 'TS', 'TS', 'HU', 'HU', 'HU', 'HU', 'HU', 'HU', 'HU', 'HU', 'HU', 'HU', 'HU', 'HU', 'TS', 'TS', 'TS', 'EX', 'EX', 'EX', 'EX', 'EX', 'EX', 'EX', 'EX', 'EX', 'EX', 'EX', 'EX', 'EX', 'EX', 'EX', 'EX'], 'lat': [17.8, 18.1, 18.4, 18.8, 19.1, 19.7, 20.2, 20.9, 21.7, 22.7, 23.7, 24.6, 25.6, 26.6, 27.7, 29.0, 30.0, 30.2, 31.5, 32.8, 34.1, 35.6, 36.5, 37.3, 39.1, 41.1, 43.1, 44.8, 46.4, 47.6, 48.4, 48.8, 48.6, 47.5, 45.9, 44.4, 42.8, 41.2], 'lon': [-86.6, -86.9, -86.8, -86.4, -85.7, -85.5, -85.4, -85.1, -85.1, -85.2, -85.8, -86.2, -86.4, -86.5, -86.6, -86.3, -85.5, -85.4, -84.5, -83.2, -81.7, -80.0, -77.7, -75.0, -70.6, -66.1, -61.5, -55.7, -48.2, -40.7, -33.1, -26.1, -20.7, -16.4, -13.5, -11.4, -10.3, -10.0], 'vmax': [25, 25, 30, 35, 45, 50, 60, 65, 75, 85, 85, 90, 100, 110, 120, 125, 140, 135, 80, 50, 45, 45, 50, 60, 60, 60, 65, 65, 65, 65, 65, 65, 60, 55, 55, 50, 35, 35], 'mslp': [1006, 1004, 1004, 1003, 999, 996, 984, 982, 977, 971, 973, 968, 961, 952, 945, 934, 919, 920, 957, 979, 987, 991, 988, 983, 980, 977, 975, 975, 975, 975, 975, 975, 975, 978, 982, 989, 996, 1001], 'wmo_basin': ['north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic', 'north_atlantic'], 'ace': 12.505000000000003}
5Retrieve xarray Dataset object with Michael's data:
Retrieve xarray Dataset object with Michael's data:
1print(storm.to_xarray())
2
3output:
4<xarray.Dataset>
5Dimensions: (time: 38)
6Coordinates:
7 * time (time) datetime64[ns] 2018-10-06T18:00:00 ... 2018-10-15T18:00:00
8Data variables:
9 extra_obs (time) int64 0 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0 0
10 special (time) <U1 '' '' '' '' '' '' '' '' '' ... '' '' '' '' '' '' '' ''
11 type (time) <U2 'LO' 'LO' 'TD' 'TS' 'TS' ... 'EX' 'EX' 'EX' 'EX' 'EX'
12 lat (time) float64 17.8 18.1 18.4 18.8 19.1 ... 45.9 44.4 42.8 41.2
13 lon (time) float64 -86.6 -86.9 -86.8 -86.4 ... -11.4 -10.3 -10.0
14 vmax (time) int64 25 25 30 35 45 50 60 65 ... 65 65 60 55 55 50 35 35
15 mslp (time) int64 1006 1004 1004 1003 999 996 ... 978 982 989 996 1001
16 wmo_basin (time) <U14 'north_atlantic' ... 'north_atlantic'
17Attributes:
18 id: AL142018
19 operational_id: AL142018
20 name: MICHAEL
21 year: 2018
22 season: 2018
23 basin: north_atlantic
24 source_info: NHC Hurricane Database
25 source: hurdat
26 ace: 12.505000000000003
Retrieve pandas DataFrame object with Michael's data:
1print(storm.to_dataframe())
2 date extra_obs special type lat lon vmax mslp \
30 2018-10-06 18:00:00 0 LO 17.8 -86.6 25 1006
41 2018-10-07 00:00:00 0 LO 18.1 -86.9 25 1004
52 2018-10-07 06:00:00 0 TD 18.4 -86.8 30 1004
63 2018-10-07 12:00:00 0 TS 18.8 -86.4 35 1003
74 2018-10-07 18:00:00 0 TS 19.1 -85.7 45 999
85 2018-10-08 00:00:00 0 TS 19.7 -85.5 50 996
96 2018-10-08 06:00:00 0 TS 20.2 -85.4 60 984
107 2018-10-08 12:00:00 0 HU 20.9 -85.1 65 982
118 2018-10-08 18:00:00 0 HU 21.7 -85.1 75 977
129 2018-10-09 00:00:00 0 HU 22.7 -85.2 85 971
1310 2018-10-09 06:00:00 0 HU 23.7 -85.8 85 973
1411 2018-10-09 12:00:00 0 HU 24.6 -86.2 90 968
1512 2018-10-09 18:00:00 0 HU 25.6 -86.4 100 961
1613 2018-10-10 00:00:00 0 HU 26.6 -86.5 110 952
1714 2018-10-10 06:00:00 0 HU 27.7 -86.6 120 945
1815 2018-10-10 12:00:00 0 HU 29.0 -86.3 125 934
1916 2018-10-10 17:30:00 1 L HU 30.0 -85.5 140 919
2017 2018-10-10 18:00:00 0 HU 30.2 -85.4 135 920
2118 2018-10-11 00:00:00 0 HU 31.5 -84.5 80 957
2219 2018-10-11 06:00:00 0 TS 32.8 -83.2 50 979
2320 2018-10-11 12:00:00 0 TS 34.1 -81.7 45 987
2421 2018-10-11 18:00:00 0 TS 35.6 -80.0 45 991
2522 2018-10-12 00:00:00 0 EX 36.5 -77.7 50 988
2623 2018-10-12 06:00:00 0 EX 37.3 -75.0 60 983
2724 2018-10-12 12:00:00 0 EX 39.1 -70.6 60 980
2825 2018-10-12 18:00:00 0 EX 41.1 -66.1 60 977
2926 2018-10-13 00:00:00 0 EX 43.1 -61.5 65 975
3027 2018-10-13 06:00:00 0 EX 44.8 -55.7 65 975
3128 2018-10-13 12:00:00 0 EX 46.4 -48.2 65 975
3229 2018-10-13 18:00:00 0 EX 47.6 -40.7 65 975
3330 2018-10-14 00:00:00 0 EX 48.4 -33.1 65 975
3431 2018-10-14 06:00:00 0 EX 48.8 -26.1 65 975
3532 2018-10-14 12:00:00 0 EX 48.6 -20.7 60 975
3633 2018-10-14 18:00:00 0 EX 47.5 -16.4 55 978
3734 2018-10-15 00:00:00 0 EX 45.9 -13.5 55 982
3835 2018-10-15 06:00:00 0 EX 44.4 -11.4 50 989
3936 2018-10-15 12:00:00 0 EX 42.8 -10.3 35 996
4037 2018-10-15 18:00:00 0 EX 41.2 -10.0 35 1001
41
42 wmo_basin
430 north_atlantic
441 north_atlantic
452 north_atlantic
463 north_atlantic
474 north_atlantic
485 north_atlantic
496 north_atlantic
507 north_atlantic
518 north_atlantic
529 north_atlantic
5310 north_atlantic
5411 north_atlantic
5512 north_atlantic
5613 north_atlantic
5714 north_atlantic
5815 north_atlantic
5916 north_atlantic
6017 north_atlantic
6118 north_atlantic
6219 north_atlantic
6320 north_atlantic
6421 north_atlantic
6522 north_atlantic
6623 north_atlantic
6724 north_atlantic
6825 north_atlantic
6926 north_atlantic
7027 north_atlantic
7128 north_atlantic
7229 north_atlantic
7330 north_atlantic
7431 north_atlantic
7532 north_atlantic
7633 north_atlantic
7734 north_atlantic
7835 north_atlantic
7936 north_atlantic
8037 north_atlantic
1storm.plot(return_ax=True)

1storm.plot_tors(plotPPH=True)

1#Method 1: Specify date closest to desired discussion
2disco = storm.get_nhc_discussion(forecast=dt.datetime(2018,10,7,0))
3print(disco['text'])
4
5#Method 2: Specify forecast discussion ID
6disco = storm.get_nhc_discussion(forecast=2)
7#print(disco['text']) printing this would show the same output
1ZCZC MIATCDAT4 ALL
2TTAA00 KNHC DDHHMM
3
4Potential Tropical Cyclone Fourteen Discussion Number 2
5NWS National Hurricane Center Miami FL AL142018
61000 PM CDT Sat Oct 06 2018
7
8The cloud pattern has improved in organization and surface pressures
9are gradually falling, but there is no evidence that the system is
10a tropical cyclone at this time. All indications are, however, that
11a tropical depression will likely form at any time soon. Strong wind
12shear is expected to affect the disturbance, and the SHIPS model
13only show a modest strengthening. This is in contrast to some global
14models and the HWRF, which are more aggressive in developing this
15system. Since the environment is marginally favorable, the NHC
16forecast only gradually strengthens the system at the rate of the
17intensity consensus IVCN. However, the forecast is highly uncertain
18given the solution of the global models.
19
20Since the system does not have a well-defined center, the initial
21motion is also uncertain. The best estimate is toward the north or
22360 degrees at 6 kt. Over the next 2 or 3 days, the cyclone will be
23embedded within the deep southerly flow between a strong subtropical
24ridge over the western Atlantic and a sharp mid-latitude trough
25advancing eastward over the United States. This flow pattern will
26force the system to move northward at 5 to 10 kt across the
27eastern Gulf of Mexico for the next 2 to 3 days. By day 4, the
28system should have moved inland and be weakening. It should
29then race northeastward farther inland across the eastern U.S. The
30track guidance envelope is remarkably quite tight. This increases
31the confidence in the track forecast primarily after the cyclone
32forms.
33
34Key Messages for Potential Tropical Cyclone Fourteen:
35
361. This system is producing heavy rainfall and flash flooding over
37portions of Central America, and these rains will spread over
38western Cuba and the northeastern Yucatan Peninsula of Mexico during
39the next couple of days.
40
412. The system is forecast to become a tropical storm by late
42Sunday, and tropical storm conditions are expected over portions of
43western Cuba, where a Tropical Storm Warning is in effect.
44
453. The system could bring storm surge, rainfall, and wind impacts
46to portions of the northern Gulf Coast by mid-week, although it is
47too soon to specify the exact location and magnitude of these
48impacts. Residents in these areas should monitor the progress of
49this system.
50
51
52FORECAST POSITIONS AND MAX WINDS
53
54INIT 07/0300Z 18.8N 86.6W 25 KT 30 MPH...POTENTIAL TROP CYCLONE
55 12H 07/1200Z 19.5N 86.5W 30 KT 35 MPH...TROPICAL CYCLONE
56 24H 08/0000Z 21.0N 86.2W 35 KT 40 MPH
57 36H 08/1200Z 22.3N 86.1W 40 KT 45 MPH
58 48H 09/0000Z 23.8N 86.3W 45 KT 50 MPH
59 72H 10/0000Z 27.4N 87.2W 55 KT 65 MPH
60 96H 11/0000Z 32.0N 85.0W 30 KT 35 MPH...INLAND
61120H 12/0000Z 38.5N 77.5W 30 KT 35 MPH...INLAND
62
63$$
64Forecaster Avila
65
66NNNN
NHC also archives forecast tracks, albeit in a different format than the official advisory data, so the operational forecast IDs here differ from the discussion IDs. As such, the forecast cone is not directly retrieved from NHC, but is generated using an algorithm that yields a cone closely resembling the official NHC cone.
Let's plot Michael's second forecast cone:
1storm.plot_nhc_forecast(forecast=2,return_ax=True)

Now let's look at the 12th forecast for Michael.
Note that the observed track here differs from the HURDAT2 track plotted previously! This is because this plot displays the operationally analyzed location and intensity, rather than the post-storm analysis data. This is done to account for differences between HURDAT2 and operational data.
1storm.plot_nhc_forecast(forecast=12,return_ax=True)

5、IBTrACS Dataset
We can also read in IBTrACS data and use it the same way as we would use HURDAT2 data. There are caveats to using IBTrACS data, however, which are described more in depth in the :doc:../data page. We'll retrieve the global IBTrACS dataset, using the Joint Typhoon Warning Center (JTWC) data, modified with the Neumann reanalysis for southern hemisphere storms, and including a special reanalysis for Cyclone Catarina (2004) in Brazil.
Warning: By default, IBTrACS data is read in from an online source. If you're reading in the global IBTrACS dataset, this could be quite slow. For global IBTrACS, it is recommended to have the CSV file saved locally (`link to data`_), then set the flag ``ibtracs_url="local_path"``.
1ibtracs = tracks.TrackDataset(basin='all',source='ibtracs',ibtracs_mode='jtwc_neumann',catarina=True)
The functionality for handling storms in IBTrACS is the same as with using HURDAT2, the only limitation being no NHC and operational model data can be accessed when using IBTrACS as the data source.
Super Typhoon Haiyan_ (2013) was a catastrophic storm in the West Pacific basin, having made landfall in the Philippines. With estimated sustained winds of 195 mph (170 kt), it is among one of the most powerful tropical cyclones in recorded history. We can illustrate this by making a plot of Haiyan's observed track and intensity, from JTWC data:
1storm = ibtracs.get_storm(('haiyan',2013))
2storm.plot(return_ax=True)

Cyclone Catarina_ (2004) was an extremely rare hurricane-force tropical cyclone that developed in the South Atlantic basin, which normally doesn't see tropical cyclone activity, and subsequently made landfall in Brazil. The "Catarina" name is unofficial; it was not assigned a name in real time, and JTWC assigned it the ID "AL502004". Recall that when reading in the IBTrACS dataset previously, we set Catarina=True. This read in data for Cyclone Catarina from a special post-storm reanalysis from McTaggart-Cowan et al. (2006). Let's make a plot of Catarina's observed track and intensity per this reanalysis:
1storm = ibtracs.get_storm(('catarina',2004))
2storm.plot(return_ax=True)

If we were to read in IBTrACS without setting Catarina=True (which sets it to False by default) and plot the track for "AL502004", we would get a noticeably different (shorter) and weaker track.
有问题可以到QQ群里进行讨论,我们在那边等大家。
QQ群号:854684131




