Plot flight variables in time series format

University of Wyoming flight data


In [13]:
# Load the needed packages
import numpy as np
import matplotlib.pyplot as plt

import awot
from awot.graph.common import create_basemap
from awot.graph import FlightLevel

%matplotlib inline

Supply user information


In [2]:
# Set the project name
Project="DYNAMO"
# Set the path for data file
flname="/Users/guy/data/king_air/copemed2013/flight/20130806.c1.nc"

Set up some characteristics for plotting.

  • Use Cylindrical Equidistant Area map projection.
  • Set the spacing of the barbs and X-axis time step for labels.
  • Set the start and end times for subsetting.

In [3]:
proj = 'cea'
Wbarb_Spacing = 300 # Spacing of wind barbs along flight path (sec)

# Choose the X-axis time step (in seconds) where major labels will be
XlabStride = 3600

# Should landmarks be plotted? [If yes, then modify the section below
Lmarks=True

# Optional variables that can be included with AWOT
# Start and end times for track in Datetime instance format
start_time = "2013-08-06 00:00:00"
end_time = "2013-08-06 23:50:00"

corners = [-6.,49.,-3.,53.]

Read in flight data


In [4]:
fl = awot.io.read_netcdf(fname=flname, platform='uwka')


Using 'time' to make AWOT time variable

Create the track figure for this flight


In [14]:
fig, ax = plt.subplots(1, 1, figsize=(9, 9))

bm = create_basemap(corners=corners, proj=proj, resolution='l', area_thresh=1.,ax=ax)

# Instantiate the Flight plotting routines
flp = FlightLevel(fl, basemap=bm)
flp.plot_trackmap(
#                 start_time=start_time, end_time=end_time,
                 color_by_altitude=True, track_cmap='spectral',
                 min_altitude=50., max_altitude= 4000.,
                 addlegend=True, addtitle=True)


Let's query the flight dictionary to see what fields we have


In [6]:
fl.keys()


Out[6]:
['mixing_ratio',
 'swbottom',
 'pcasp_mean_diam',
 'pressure_altitude',
 'thetae',
 'irtop',
 'irbottom',
 'pcasp_num',
 'Uwind',
 'pitch',
 'pcasp_conc',
 'latitudinal_wind',
 'pcasp_surf_area_conc',
 'tas',
 'temperature',
 'wind_spd',
 'altitude',
 'true_heading',
 'platform',
 'flight_number',
 'co2_conc',
 'lwc',
 'h2o_conc',
 'ias',
 'Vwind',
 'swtop',
 'conc_cpc',
 'topo',
 'pressure',
 'thetad',
 'roll_angle',
 'Wwind',
 'longitudinal_wind',
 'dewpoint_temperature',
 'wind_dir',
 'latitude',
 'longitude',
 'pcasp_vol_conc',
 'project',
 'relative_humidity',
 'time',
 'turb']

Create figure and produce a multi-panel times series plot


In [7]:
fig, (ax1, ax2, ax3, ax4) = plt.subplots(4, 1, figsize=(9, 9))

flp.plot_timeseries('altitude', color='k', marker='o', msize=1.5, lw=2,
                    date_format='%H:%M', tz=None, xdate=True,
#                    date_minor_string='minute', other_major_ticks=None, other_minor_ticks=None,
#                    other_min=None, other_max=None, 
#                    start_time=start_time, end_time=end_time,
#                    title=None, xlab=' ', ylab=' ', 
                    ax=ax1)

flp.plot_timeseries('thetae', color='b', ax=ax2, ylab=r"${\Theta}$$_{e}$ [K]")
flp.plot_timeseries('pressure', color='k', ax=ax3)
flp.plot_timeseries('Wwind', color='r', ax=ax4, ylab="Vertical Wind")


We can also add the distance along a flight track from the following. Look at the docstrings for help, as the keys are optional and the software will search for a matching variable.


In [8]:
tg = awot.util.calc_ground_distance(fl, method='great circle', add_to_dict=True)
ta =awot.util.calc_air_distance(fl, airspeed_key='tas', add_to_dict=True)
print(fl['altitude']['data'].shape, fl['track_distance_air']['data'].shape, fl['track_distance_ground']['data'].shape)


((10350,), (10350,), (10350,))

Let's make sure that the new dictionaries were added. track_distance_ground and track_distance_air


In [9]:
fl.keys()


Out[9]:
['mixing_ratio',
 'swbottom',
 'pcasp_mean_diam',
 'pressure_altitude',
 'thetae',
 'irtop',
 'irbottom',
 'pcasp_num',
 'Uwind',
 'pitch',
 'pcasp_conc',
 'latitudinal_wind',
 'pcasp_surf_area_conc',
 'track_distance_air',
 'tas',
 'temperature',
 'track_distance_ground',
 'wind_spd',
 'altitude',
 'true_heading',
 'platform',
 'flight_number',
 'co2_conc',
 'lwc',
 'h2o_conc',
 'ias',
 'Vwind',
 'swtop',
 'conc_cpc',
 'topo',
 'pressure',
 'thetad',
 'roll_angle',
 'Wwind',
 'longitudinal_wind',
 'dewpoint_temperature',
 'wind_dir',
 'latitude',
 'longitude',
 'pcasp_vol_conc',
 'project',
 'relative_humidity',
 'time',
 'turb']

In [10]:
print(fl['track_distance_air']['data'].min(), fl['track_distance_air']['data'].max())
print(fl['track_distance_ground']['data'].min(), fl['track_distance_ground']['data'].max())


(0.0, 847829.94569778442)
(0.0, 849508.92042264563)

Plot the data as a function of distance traveled in the air


In [12]:
fig, (ax1, ax2, ax3, ax4) = plt.subplots(4, 1, figsize=(9, 9))

flp.plot_trackseries('altitude', plot_km=True, color='k', ls='-', lw=2, 
                     ylab='Height [m]', ax=ax1)
flp.plot_trackseries('thetae', plot_km=True, track_key='track_distance_air', color='b', ls='-', 
                     ylab=r"${\Theta}$$_{e}$ [K]", ax=ax2)
flp.plot_trackseries('pressure', plot_km=True, track_key='track_distance_air', color='g', ls='-',
                     ylab='P [hpa]',ax=ax3)
flp.plot_trackseries('Wwind', plot_km=True, track_key='track_distance_air', color='r', ls='-',
                     ylab="W [m/s]", ax=ax4)


Plot the data as a function of distance traveled over the ground


In [13]:
fig, (ax1, ax2, ax3, ax4) = plt.subplots(4, 1, figsize=(9, 9))

flp.plot_trackseries('altitude', plot_km=True, track_key='track_distance_ground', color='k', ls='-', lw=2, 
                     ylab='Height [m]', ax=ax1)
flp.plot_trackseries('thetae', plot_km=True, track_key='track_distance_ground', color='b', ls='-', 
                     ylab=r"${\Theta}$$_{e}$ [K]", ax=ax2)
flp.plot_trackseries('pressure', plot_km=True, track_key='track_distance_ground', color='g', ls='-',
                     ylab='P [hpa]',ax=ax3)
flp.plot_trackseries('Wwind', plot_km=True, track_key='track_distance_ground', color='r', ls='-',
                     ylab="W [m/s]", ax=ax4)



In [ ]: