pyadapt.extras

This section describes modules and functions found within the extras part of the repository. It is there mainly as a way to declutter the source code... but probably will stay there.

ops

pyadapt.extras.ops.to_pydatetime(t, u)

Convert time array to python datetime objects

Parameters:
  • t (array) – time array from netCDF file
  • u (str) – units for the time array
Returns:

numpy array of datetime.datetime objects the same shape as the input time array

skew-t

pyadapt.extras.skewt.plot_profile(fig, ax, t, p, c='r', label='', skew=100.0)

Plots a temperature profile on the supplied axes

Parameters:
  • fig – the figure generated by skewt_axes()
  • ax – the skew-t axis generated by skewt_axes()
  • t – temperature profile (untransformed)
  • p – pressure profile
  • c – the color of the line to plot
  • label – label for the legend
  • skew – skewness of the skew-t grid
Returns fig:

the skew-t figure

Returns ax:

the skew-t axis after plotting

pyadapt.extras.skewt.plot_wind(fig, bx, mask, u, v, a, skip=50)

Plots a wind profile on the supplied axes

Parameters:
  • fig – the figure generated by skewt_axes()
  • bx – the wind profile axis generated by skewt_axes()
  • mask – mask of booleans for limiting the vertical extent
  • u – U component of the wind
  • v – V component of the wind
  • a – altitude corresponding to each of the U,V values
  • skip – skipping factor for thinning out the wind barbs
pyadapt.extras.skewt.skewfactor(p, skew, ref=1000.0)

Calculates the skew factor for a given pressure and skewness

Parameters:
  • p (float or array of float) – pressure
  • skew (float) – skewness of the plot
  • ref (float) – reference pressure level. keep it at 1000.
Returns skewfactor:
 

skewness of the skew-t plot

pyadapt.extras.skewt.skewt_axes(tmin=-40, tmax=30, ptop=550.0, pbot=1050.0, skew=100.0, figsize=(10, 10))

Creates axes for the skew-t and wind profile plot.

Parameters:
  • tmin (float) – Minimum temperature (c) along 1000 hPa
  • tmax (float) – Maximum temperature (c) along 1000 hPa
  • ptop (float) – Pressure (hPa) for the top of the figure
  • pbot (float) – Pressure (hPa) for the bottom of the figure
  • skew (float) – Skewness of the plot (larger number, more skew)
  • figsize (tuple(int, int)) – size of the figure

Note

pbot should be larger (lower) or equal to 1000 hPa for best results.

Returns fig:figure reference
Returns ax:axis reference for the skew-t
Returns bx:axis reference for the wind profile

This skew-t axis generator is a little different than some of the more complex routines out there. In this case, coordinates on the grid are transformed for ease of plotting.

  • pbot and ptop are transformed into -1*log10(p) units so that pbot is on the bottom and ptop is on top, and that the spacing of the pressure grid is in log space (but the axes are linear).
  • tmin and tmax are used to define the temperature range at the reference pressure of 1000 hPa. Plotting the temperatures requires transforming the value down to the reference level based on the pressure and skewness associated with the temperature.

Isobars, isotherms, and dry adiabats are computed as a grid which fills the axis space and are then contoured.

For plotting of the actual sounding data, the input temperature and pressure must be transformed using the same method as the underlying grid, and so must be passed into the transform_profile() method, but that should all get handled by the plot_profile() method.

pyadapt.extras.skewt.transform_profile(temperature, pressure, skew=100.0)

Transforms a temperature profile using its pressure and skewness

Parameters:
  • temperature (float or array(floats)) – temperature profile or single value
  • pressure (float or array(floats)) – pressure for associated temperature
  • skew (float) – skewness of the skew-t
Returns temp:

the transformed temperature value

Returns pres:

the transformed pressure value

windrose

Note

This is not my module. The windrose module is authored by Lionel Roubeyre. Its version number is 1.4

class pyadapt.extras.windrose.WindroseAxes(*args, **kwargs)

Create a windrose axes

bar(dir, var, **kwargs)

Plot a windrose in bar mode. For each var bins and for each sector, a colored bar will be draw on the axes.

Mandatory:
  • dir : 1D array - directions the wind blows from, North centred
  • var : 1D array - values of the variable to compute. Typically the wind speeds
Optional:
  • nsector: integer - number of sectors used to compute the windrose table. If not set, nsectors=16, then each sector will be 360/16=22.5°, and the resulting computed table will be aligned with the cardinals points.
  • bins : 1D array or integer- number of bins, or a sequence of bins variable. If not set, bins=6 between min(var) and max(var).
  • blowto : bool. If True, the windrose will be pi rotated, to show where the wind blow to (usefull for pollutant rose).
  • colors : string or tuple - one string color (‘k’ or ‘black’), in this case all bins will be plotted in this color; a tuple of matplotlib color args (string, float, rgb, etc), different levels will be plotted in different colors in the order specified.
  • cmap : a cm Colormap instance from matplotlib.cm. - if cmap == None and colors == None, a default Colormap is used.
  • edgecolor : string - The string color each edge bar will be plotted. Default : no edgecolor
  • opening : float - between 0.0 and 1.0, to control the space between each sector (1.0 for no space)
box(dir, var, **kwargs)

Plot a windrose in proportional bar mode. For each var bins and for each sector, a colored bar will be draw on the axes.

Mandatory:
  • dir : 1D array - directions the wind blows from, North centred
  • var : 1D array - values of the variable to compute. Typically the wind speeds
Optional:
  • nsector: integer - number of sectors used to compute the windrose table. If not set, nsectors=16, then each sector will be 360/16=22.5°, and the resulting computed table will be aligned with the cardinals points.

  • bins : 1D array or integer- number of bins, or a sequence of bins variable. If not set, bins=6 between min(var) and max(var).

  • blowto : bool. If True, the windrose will be pi rotated, to show where the wind blow to (usefull for pollutant rose).

  • colors : string or tuple - one string color (‘k’ or ‘black’), in this case all bins will be plotted in this color; a tuple of matplotlib color args (string, float, rgb, etc), different levels will be plotted in different colors in the order specified.

  • cmap : a cm Colormap instance from matplotlib.cm.
    • if cmap == None and colors == None, a default Colormap is used.
  • edgecolor : string - The string color each edge bar will be plotted. Default : no edgecolor

cla()

Clear the current axes

contour(dir, var, **kwargs)

Plot a windrose in linear mode. For each var bins, a line will be draw on the axes, a segment between each sector (center to center). Each line can be formated (color, width, ...) like with standard plot pylab command.

Mandatory:
  • dir : 1D array - directions the wind blows from, North centred
  • var : 1D array - values of the variable to compute. Typically the wind speeds
Optional:
  • nsector: integer - number of sectors used to compute the windrose table. If not set, nsectors=16, then each sector will be 360/16=22.5°, and the resulting computed table will be aligned with the cardinals points.

  • bins : 1D array or integer- number of bins, or a sequence of bins variable. If not set, bins=6, then

    >>> bins=linspace(min(var), max(var), 6)
    
  • blowto : bool. If True, the windrose will be pi rotated, to show where the wind blow to (usefull for pollutant rose).

  • colors : string or tuple - one string color (‘k’ or ‘black’), in this case all bins will be plotted in this color; a tuple of matplotlib color args (string, float, rgb, etc), different levels will be plotted in different colors in the order specified.

  • cmap : a cm Colormap instance from matplotlib.cm. - if cmap == None and colors == None, a default Colormap is used.

others kwargs : see help(pylab.plot)

contourf(dir, var, **kwargs)

Plot a windrose in filled mode. For each var bins, a line will be draw on the axes, a segment between each sector (center to center). Each line can be formated (color, width, ...) like with standard plot pylab command.

Mandatory:
  • dir : 1D array - directions the wind blows from, North centred
  • var : 1D array - values of the variable to compute. Typically the wind speeds
Optional:
  • nsector: integer - number of sectors used to compute the windrose table. If not set, nsectors=16, then each sector will be 360/16=22.5°, and the resulting computed table will be aligned with the cardinals points.

  • bins : 1D array or integer- number of bins, or a sequence of bins variable. If not set, bins=6, then

    >>> bins=linspace(min(var), max(var), 6)
    
  • blowto : bool. If True, the windrose will be pi rotated, to show where the wind blow to (usefull for pollutant rose).

  • colors : string or tuple - one string color (‘k’ or ‘black’), in this case all bins will be plotted in this color; a tuple of matplotlib color args (string, float, rgb, etc), different levels will be plotted in different colors in the order specified.

  • cmap : a cm Colormap instance from matplotlib.cm. - if cmap == None and colors == None, a default Colormap is used.

others kwargs : see help(pylab.plot)

legend(loc='lower left', **kwargs)

Sets the legend location and her properties. The location codes are:

'best'         : 0,
'upper right'  : 1,
'upper left'   : 2,
'lower left'   : 3,
'lower right'  : 4,
'right'        : 5,
'center left'  : 6,
'center right' : 7,
'lower center' : 8,
'upper center' : 9,
'center'       : 10,

If none of these are suitable, loc can be a 2-tuple giving x,y in axes coords, ie,

loc = (0, 1) is left top loc = (0.5, 0.5) is center, center

and so on. The following kwargs are supported:

isaxes=True           # whether this is an axes legend
prop = FontProperties(size='smaller')  # the font property
pad = 0.2             # the fractional whitespace inside the legend border
shadow                # if True, draw a shadow behind legend
labelsep = 0.005     # the vertical space between the legend entries
handlelen = 0.05     # the length of the legend lines
handletextsep = 0.02 # the space between the legend line and legend text
axespad = 0.02       # the border between the axes and legend edge
set_radii_angle(**kwargs)

Set the radii labels angle

pyadapt.extras.windrose.clean(dir, var)

Remove masked values in the two arrays, where if a direction data is masked, the var data will also be removed in the cleaning process (and vice-versa)

pyadapt.extras.windrose.histogram(dir, var, bins, nsector, normed=False, blowto=False)

Returns an array where, for each sector of wind (centred on the north), we have the number of time the wind comes with a particular var (speed, polluant concentration, ...).

  • dir : 1D array - directions the wind blows from, North centred
  • var : 1D array - values of the variable to compute. Typically the wind speeds
  • bins : list - list of var category against we’re going to compute the table
  • nsector : integer - number of sectors
  • normed : boolean - The resulting table is normed in percent or not.
  • blowto : boolean - Normaly a windrose is computed with directions as wind blows from. If true, the table will be reversed (usefull for pollutantrose)

Table Of Contents

Previous topic

pyadapt.datastreams

This Page