pyMeteo documentation¶
Contents:
Skew-T/Log-P plotting, meteorology and interfacing with CM1
This package provides routines for plotting Skew-T/Log-P diagrams and working with CM1 output. For contributions, please submit pull requests to https://github.com/cwebster2/pymeteo. Please report bugs using the github issue tracker at https://github.com/cwebster2/pymeteo/issues.
Skew-t/Log-p Plotting¶
This module allows plotting Skew-T/Log-P diagrams and hodographs from arrays of data with helper functions to plot directly from CM1 output files in either Grads or HDF5 format and also from sounding data text files in the format used for WRF and CM1 initialization.
This module also has code to produce rudimentary analysis of the soundings data. Currently this is limited to CAPE (surface and most unstable), CIN, wind shear, storm relative helicity, lifted index and a rough estimate of storm motion based on the Bunkers (2000) method.
Plotting¶
High level plotting functions¶
plot_cm1h5()
– plots skewt from CM1 generated hdf5 files processed by ingest_cm1plot_cm1()
– plots skewt from CM1 generated GRaDS style outputplot_wrf()
– plots skewt from WRF generated NetCDF outputplot_sounding_data()
– plots skewt from CM1/WRF input sounding filesplot_sounding_data_uwyo()
– plots skewt from uwyo sounding data (file or online)
These functions are called by command line scripts provided to make plotting from data files easy. You can invoke these through command line scripts as:
# From tabular sounding data (e.g. WRF or CM1 intial sounding data)
$ skewt tabular -f sounding.dat skewt.pdf
# From GrADS stlye CM1 output
$ skewt cm1 -p . -d cm1out -x 0 -y 0 skewt-cm1.pdf
# From HDF5 CM1 output
$ skewt cm1hdf -f model-data.h5 -x 0 -y 0 skewt.pdf
# From WRF output
$ skewt wrf -f wrfout.nc --lat 30 --lon -80 -t 0 skewt.pdf
# From University of Wyoming data file
$ skewt uwyo -f uwyo-data.dat skewt.pdf
# From University of Wyming website data (live)
$ skewt uwyoweb --station 72251 skewt.pdf
plot()
– generic high level plot function
import numpy as np
import pymeteo.skewt as skewt
# prepare 1D arrays height (z), pressure (p), potential temperature (th),
# water vapor mixing ratio (qv), winds (u and v) all of the same length.
skewt.plot(None, z, th, p, qv, u, v, 'skewt.pdf')
Variables affecting the plot output¶
These variables affect the skewness of the plot and the bounds of the plot
skew_angle
– skewness
These variables affect the lines plotted on the skew-t
These variables affect the plotting of the lines above
These variables affect the plotting style of skewt data
Functions to draw isolines¶
If you are manually plotting skew-t data, these functions can be used to draw various lines on your plot. These are used by the high level plotting functions.
Module reference¶
- pymeteo.skewt.Tmax = 40.0¶
Sets the right boundary of the plot. Temperature at 1000 mb (C)
- pymeteo.skewt.Tmin = -40.0¶
Sets the left boundary of the plot. Temperature at 1000 mb (C)
- pymeteo.skewt.dp = 5000.0¶
The delta pressure used in calculating adiabats
- pymeteo.skewt.draw_dry_adiabat(axes)¶
Plot dry adiabats on axes
- Parameters:
axes (
matplotlib.axes
) – The axes to draw on
This function calculates dry adiabats and plots these lines. Adiabats are calculated every 10 K
- pymeteo.skewt.draw_isobars(axes)¶
Plot isobars on axes
- Parameters:
axes (
matplotlib.axes
) – The axes to draw on
This function draws isobars at intervals of 2*dp.
- pymeteo.skewt.draw_isotherms(axes)¶
Plot isotherms on axes
- Parameters:
axes (
matplotlib.axes
) – The axes to draw on
This function draws isotherms every 10 C.
- pymeteo.skewt.draw_moist_adiabat(axes)¶
Plot moist adiabats on axes
- Parameters:
axes (
matplotlib.axes
) – The axes to draw on
This function calculates moist adiabats and plots these lines. Adiabats are calculated for values of T at 1000mb from -15 to 45 C every 5 C between -15 and 10 C and every 2.5 C between 12.5 and 45 C.
- pymeteo.skewt.draw_water_mix_ratio(axes)¶
Plot lines of constant water vapor mixing ratio on axes
- Parameters:
axes (
matplotlib.axes
) – The axes to draw on
This function calculates isolines of constant water vapor mixing ratio and plots these lines. Values of w calculated are given by the list variable w.
- pymeteo.skewt.dry_adiabats = array([-40, -30, -20, -10, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200])¶
List of dry adiabats to plot on the skew-t. In degrees C
- pymeteo.skewt.isobars = array([100000., 95000., 90000., 85000., 80000., 75000., 70000., 65000., 60000., 55000., 50000., 45000., 40000., 35000., 30000., 25000., 20000., 15000., 10000.])¶
List of isobars to plot on the skew-t. In Pascals
- pymeteo.skewt.isotherms = array([-150, -140, -130, -120, -110, -100, -90, -80, -70, -60, -50, -40, -30, -20, -10, 0, 10, 20, 30, 40, 50])¶
List of isotherms to plot on the skew-t. In degrees C
- pymeteo.skewt.label_std_heights(axes)¶
Plot heights of standard pressure levels
- Paramter axes:
The axes to draw on
- pymeteo.skewt.lc_major = 'grey'¶
Line color of ‘major’ lines. E.g. Lines plotted at 10 C intervals or 50 mb intervals
- pymeteo.skewt.lc_minor = 'lightgrey'¶
Line color of ‘minor’ lines. E.g. Lines not plotted at the major intervals
- pymeteo.skewt.linecolor_Parcel_T = 'red'¶
Line color of lifted surface parcel temperature profile
- pymeteo.skewt.linecolor_T = 'black'¶
Line color of environmental temperature profile
- pymeteo.skewt.linecolor_Td = 'green'¶
Line color of environmental dew-point temperature profile
- pymeteo.skewt.linecolor_Tve = 'black'¶
Line color of environmental virtual temperature profile
- pymeteo.skewt.linecolor_Tvp = 'red'¶
Line color of lifted surface parcel virtual temperature profile
- pymeteo.skewt.linecolor_Twb = 'blue'¶
Line color of environmental wet-bulb temperature profile
- pymeteo.skewt.linestyle_Tve = '--'¶
Line style of environmental virtual temperature profile
- pymeteo.skewt.linestyle_Tvp = '--'¶
Line style of lifted surface parcel virtual temperature profile
- pymeteo.skewt.linewidth_Parcel_T = 1.0¶
Line width of lifted surface parcel temperature profile
- pymeteo.skewt.linewidth_T = 1.5¶
Line width of environmental temperature profile
- pymeteo.skewt.linewidth_Td = 1.5¶
Line width of environmental dew-point temperature profile
- pymeteo.skewt.linewidth_Tve = 0.7¶
Line width of environmental virtual temperature profile
- pymeteo.skewt.linewidth_Tvp = 0.7¶
Line width of lifted surface parcel virtual temperature profile
- pymeteo.skewt.linewidth_Twb = 0.5¶
Line width of environmental wet-bulb temperature profile
- pymeteo.skewt.lw_major = 0.6¶
Line width of ‘major’ lines. E.g. Lines plotted at 10 C intervals or 50 mb intervals
- pymeteo.skewt.lw_minor = 0.25¶
Line width of ‘minor’ lines. E.g. Lines not plotted at the major intervals
- pymeteo.skewt.mixing_ratios = [0.2, 0.4, 0.8, 1, 2, 3, 4, 6, 8, 10, 14, 18, 24, 32, 40]¶
List of water vapor mixing ratio lines to plot. In g/kg
- pymeteo.skewt.moist_adiabats = array([-15., -10., -5., 0., 5., 10., 12., 14., 16., 18., 20., 22., 24., 26., 28., 30., 32., 34., 36., 38., 40., 42., 44.])¶
List of moist adiabats to plot on the skew-t. In degrees C
- pymeteo.skewt.pbot = 105000.0¶
Sets the bottom boundary of the plot. Pressure (Pa)
- pymeteo.skewt.plevs = array([105000., 100000., 95000., 90000., 85000., 80000., 75000., 70000., 65000., 60000., 55000., 50000., 45000., 40000., 35000., 30000., 25000., 20000., 15000., 10000.])¶
List of pressure levels to do calculations on
- pymeteo.skewt.plot(loc, z, th, p, qv, u, v, output, time=None, title=None)¶
Plots Skew-T/Log-P diagrapms with hodograph
The helper functions above facilitate loading data from various formats and then call this function. If you have data in another format or arrays of data in python already, then this is the function you want to use.
- Parameters:
loc – Location string
z – z grid mesh (1D)
time – Time string
th – Potential temperature at z points
p – Pressure at z points
qv – Water vapor mixing ratio at z points
u – u winds at z points
v – v winds at z points
title – Title for plot
output – Filename to save plot to
- pymeteo.skewt.plot_cm1(path, filename, xi, yi, output)¶
Plot skewt from a Grads format CM1 output file
- Parameters:
_path – Path to CM1 dataset
_filename – Filename of dataset
x1 – X gridpoint to plot SkewT
y1 – Y gridpoint to plot SkewT
output – Filename to save skewt plot
This function plots a skewt from a CM1 output file. This routine uses winds interpolated to the scalar gridpoints.
- pymeteo.skewt.plot_cm1h5(filename, xi, yi, output)¶
Plots a skewt from an HDF5 file.
- Parameters:
To use this function the HDF5 file must have the following variables:
xh – x scalar grid locations
yh – y scalar grid locations
z – z grid locations
time – timestep of file data (scalar)
th – potential temperature (K)
thpert – potential temperature perturbation (K)
prs – pressure (Pa)
u – u wind speed (m/s)
v – v wind speed (m/s)
qv – water vapor mixing ratio (kg/kg)
The names of these variables correspond to default naming by CM1 using HDF5 output.
- pymeteo.skewt.plot_hodo_axes(axes)¶
Plot hodograph axes
This will plot range arcs and labels for a hodograph plot
- pymeteo.skewt.plot_hodograph(axes, z, u, v)¶
Plot Hodograph data
This plots u and v winds vs height on a hodograph.
- Parameters:
z – height values (1D array)
u – U component of wind at z heights (1D array)
v – V component of wind at z heights (1D array)
- Paramter axes:
The axes instance to draw on
- pymeteo.skewt.plot_legend(axes)¶
Plot skew-t legend
- pymeteo.skewt.plot_sounding(axes, z, th, p, qv, u=None, v=None)¶
Plot sounding data
This plots temperature, dewpoint and wind data on a Skew-T/Log-P plot. This will also plot derived values such as wetbulb temperature and label the surface based LCL, LFC and EL.
- Parameters:
z – height values (1D array)
th – potential temperature at z heights (1D array)
p – pressure at z heights (1D array)
qv – water vapor mixing ratio at z heights (1D array)
u – U component of wind at z heights (1D array)
v – V component of wind at z heights (1D array)
- Paramter axes:
The axes instance to draw on
- pymeteo.skewt.plot_sounding_axes(axes)¶
Plots Skew-T/Log-P axes
This will plot isotherms, isobars, dry and moist adiabats, lines of constant water vapor mixing ratio, labels and setup the y axes to be reversed.
- Paramter axes:
The axes to draw on
- pymeteo.skewt.plot_sounding_data(filename, output)¶
Plot SkewT from a WRF / CM1 compatible sounding data file
- Parameters:
The datafile is the same format as used in sounding initalization files for WRF and CM1.
The format is: 1 line header with surface pressure (mb), theta (K) and qv (g/kg) n number of lines with z (m), theta (K), qv (g/kg), u (m/s), v(m/s)
- pymeteo.skewt.plot_sounding_data_csv(filename, output)¶
Plot SkewT from a CSV sounding data file
- Parameters:
The datafile format is CSV with the following columns:
pressure (mb)
height (m)
temperature (C)
dew point (C)
wind direction (degrees)
wind speed (m/s)
Missing values should be filled with the value -9999.00
- pymeteo.skewt.plot_sounding_data_uwyo(filename, output, stationID=0, date=None)¶
Plot SkewT from University of Wyoming sounding data
- Parameters:
If filename is not None then this function will plot data from that file. If filename is None and stationID is non-zero, then this will request a sounding datafile from http://weather.uwyo.edu for the specified date. If date is None then the requested sounding will be the most recent sounding taken at either 12Z or 00Z.
- pymeteo.skewt.plot_wrf(filename, lat, lon, time, output)¶
Plots a skewt from an WRF NetCDF output file.
- Parameters:
This function assumes the NetCDF file was produce by the WRF model. If another program produces the file but names variables in the same manner as the WRF model, this function should work for that dat as well.
The variables using in the wrfout.nc data are: - Times ? - U(Time, bottom_top, south_north, west_east_stag) - V(Time, bottom_top, south_north_stag, west_east) - T(Time, bottom_top, south_north, west_east) Theta perturbation - P(Time, bottom_top, south_north, west_east) Pres perturbation - PB(Time, bottom_top, south_north, west_east) pres base state - QVAPOR(Time, bottom_top, south_north, west_east)
PH(Time, bottom_top_stag, south_north, west_east)
PHB(Time, bottom_top_stag, south_north, west_east) Z = (((PH(k)+PH(k+1)) / 2) + ((PHB(k)+(PHB(k+1)) / 2) / 9.81
TH2(Time, south_north, west_east) – 2m pot temp
PSFC(Time, south_north, west_east) – surface pres
U10(Time, south_north, west_east) – 10m U
V10(Time, south_north, west_east) – 10m V
XTIME(Time) – minutes since start of sim
XLAT, XLONG, XLAT_U/V, XLONG_U/V
Start_date
Need time, theta, pressure
- pymeteo.skewt.ptickbot = 100000.0¶
Lowest elevated pressure level to be labelled in the plot (Pa)
- pymeteo.skewt.pticktop = 10000.0¶
Highest elevated pressure level to be labelled in the plot (Pa)
- pymeteo.skewt.ptop = 10000.0¶
Sets the top boundary of the plot. Pressure (Pa)
- pymeteo.skewt.skew(p)¶
Puts the skew in skew-T
- Parameters:
p – pressure level of the point.
This calculates the skew of the T axis for a point to plot. This assumes a logarithmic y axes and uses the variable :py:data:skew_angle to determine the skew. This is the magic that turns a cartesian plot into a Skew-T/Log-p plot.
- pymeteo.skewt.skew_angle = 37.5¶
This defines the skewness of the T axis
- pymeteo.skewt.tickdp = 10000¶
The spacing between pressure labels in the plot (Pa)
Interfacining with CM1¶
Class to read GRaDS style CM1 model output data
- class pymeteo.cm1.read_grads.CM1(_CM1__path, _CM1__datasetname)¶
Class that implements reading CM1 model data
- Parameters:
path – path to CM1 data files
datasetname – the CM1 data files basename
- dimT = 0¶
T grid dimension (1D)
- dimX = 0¶
X grid dimension (1D)
- dimY = 0¶
Y grid dimension (1D)
- dimZ = 0¶
Z grid dimension (1D)
- dt = 0¶
timestep between time levels
- nt = 0¶
number of time levels in the dataset
- nv = 0¶
number of variables in the dataset
- nx = 0¶
gridpoints in the x direction
- ny = 0¶
gridpoints in the y direction
- nz = 0¶
gridpoints in the z direction
- read3d(time, varname)¶
Reads a 3D variable from the dataset
- Parameters:
time – the timelevel to read
varname – the variable name to read
- Reaturns:
3D array containing the variable at the time
Dynamics¶
This module provides routine thermodynamic functions
- pymeteo.dynamics.mean_wind(_u, _v, _z, zbot, ztop)¶
Calculates the mean wind in the layer between zbot and ztop
- Parameters:
_u – U winds (1D vector in z)
_u – V winds (1D vector in z)
_z – z heights (1D vector in z)
zbot – Bottom of the layer
ztop – Top of the layer
- pymeteo.dynamics.shear(_u, _v, _z, zbot, ztop)¶
Calculates the shear in the layer between zbot and ztop
- Parameters:
_u – U winds (1D vector in z)
_u – V winds (1D vector in z)
_z – z heights (1D vector in z)
zbot – Bottom of the layer
ztop – Top of the layer
- pymeteo.dynamics.srh(_u, _v, _z, zbot, ztop, cx, cy)¶
Calculates the storm relative helicity in the layer between zbot and ztop
- Parameters:
_u – U winds (1D vector in z)
_u – V winds (1D vector in z)
_z – z heights (1D vector in z)
zbot – Bottom of the layer
ztop – Top of the layer
cx – u component of storm motion
cy – v component of storm motion
- pymeteo.dynamics.uv_to_deg(u, v)¶
transforms u, v, to direction, maginutide
- Parameters:
u – u wind component
v – v wind component
- Returns:
wind direction and magnitude
- pymeteo.dynamics.wind_deg_to_uv(direction, speed)¶
Converts direction and speed into u,v wind
- Parameters:
direction – wind direction (mathmatical angle)
speed – wind magnitude
- Returns:
u and v wind components
Thermodynamic routines¶
- pymeteo.thermo.T(theta, p)¶
Convert Potential Temperature \(\theta\) to Temperature
- Parameters:
theta – Potential temperature (K)
p – Pressure (Pa)
- Returns:
Temperature (K)
Meteorological constants¶
This module provides constants used in the rest of the package