|
14 | 14 | air weather service guide.
|
15 | 15 | """
|
16 | 16 |
|
17 |
| -from datetime import datetime |
18 | 17 |
|
19 | 18 | import matplotlib.pyplot as plt
|
20 | 19 | from mpl_toolkits.axes_grid1.inset_locator import inset_axes
|
21 |
| - |
| 20 | +import numpy as np |
| 21 | +import pandas as pd |
22 | 22 | import metpy.calc as mpcalc
|
23 |
| -from metpy.io import get_upper_air_data |
24 |
| -from metpy.io.upperair import UseSampleData |
| 23 | +from metpy.cbook import get_test_data |
25 | 24 | from metpy.plots import Hodograph, SkewT
|
| 25 | +from metpy.units import units |
26 | 26 |
|
27 | 27 | #########################################################################
|
28 | 28 | # Getting Data
|
|
31 | 31 | # Upper air data can be obtained using the siphon package, but for this tutorial we will use
|
32 | 32 | # some of MetPy's sample data. This event is the Veterans Day tornado outbreak in 2002.
|
33 | 33 |
|
34 |
| -with UseSampleData(): # Only needed to use our local sample data |
35 |
| - dataset = get_upper_air_data(datetime(2002, 11, 11, 0), 'BNA') |
| 34 | +col_names = ['pressure', 'height', 'temperature', 'dewpoint', 'direction', 'speed'] |
| 35 | + |
| 36 | +df = pd.read_fwf(get_test_data('nov11_sounding.txt', as_file_obj=False), |
| 37 | + skiprows=5, usecols=[0, 1, 2, 3, 6, 7], names=col_names) |
| 38 | + |
| 39 | +df['u_wind'], df['v_wind'] = mpcalc.get_wind_components(df['speed'], |
| 40 | + np.deg2rad(df['direction'])) |
| 41 | + |
| 42 | +# Drop any rows with all NaN values for T, Td, winds |
| 43 | +df = df.dropna(subset=('temperature', 'dewpoint', 'direction', 'speed', |
| 44 | + 'u_wind', 'v_wind'), how='all').reset_index(drop=True) |
36 | 45 |
|
37 | 46 | ##########################################################################
|
38 | 47 |
|
39 |
| -# We will pull the data out of the example dataset into individual variables. |
| 48 | +# We will pull the data out of the example dataset into individual variables and |
| 49 | +# assign units. |
40 | 50 |
|
41 |
| -p = dataset.variables['pressure'][:] |
42 |
| -T = dataset.variables['temperature'][:] |
43 |
| -Td = dataset.variables['dewpoint'][:] |
44 |
| -u = dataset.variables['u_wind'][:] |
45 |
| -v = dataset.variables['v_wind'][:] |
46 |
| -wind_speed = dataset.variables['speed'][:] |
| 51 | +p = df['pressure'].values * units.hPa |
| 52 | +T = df['temperature'].values * units.degC |
| 53 | +Td = df['dewpoint'].values * units.degC |
| 54 | +wind_speed = df['speed'].values * units.knots |
| 55 | +wind_dir = df['direction'].values * units.degrees |
| 56 | +u, v = mpcalc.get_wind_components(wind_speed, wind_dir) |
47 | 57 |
|
48 | 58 | ##########################################################################
|
49 | 59 | # Thermodynamic Calculations
|
|
0 commit comments