Meteographica.weathermap

This package contains utility functions to simplify making weather-maps. The idea is to get data cubes loaded by Meteorographica.data and plot them as contour plots, colour maps and the like. So there is one function to take a data cube and add it to a Cartopy map as a contour plot; another for a colour map, and so on.

It is probably best illustrated by example.


Meteorographica.weathermap.add_grid(ax, linestyle='-', linewidth_minor=0.2, linewidth_major=0.5, color=(0, 0.3, 0, 0.3), zorder=0, sep_major=2, sep_minor=0.5)[source]

Add a lat-lon grid to the map.

Actually plots two grids, a minor grid at a narrow spacing with thin lines, and a major grid at a wider spacing with thicker lines. Note that the grids only cover the latitude range -85 to 85, because the line spacings become too small very close to the poles on a rotated grid.

Parameters:
  • ax (cartopy.mpl.geoaxes.GeoAxes) – Axes on which to draw.
  • linestyle (str, optional) – See matplotlib.lines.Line2D.set_linestyle(). Defaults to ‘-‘.
  • linewidth_minor (float, optional) – Line width for minor grid. Defaults to 0.2.
  • linewidth_major (float, optional) – Line width for major grid. Defaults to 0.5.
  • color (see matplotlib.colors, optional) – Grid colour. Defaults to (0,0.30,0,0.3).
  • sep_minor (float, optional) – Separation, in degrees, of the minor grid lines. Defaults to 0.5.
  • sep_major (float, optional) – Separation, in degrees, of the major grid lines. Defaults to 2.0.
  • zorder (float, optional) – Standard matplotlib parameter determining which things are plotted on top (high zorder), and which underneath (low zorder), Defaults to 0 - at the bottom.
Returns:

Nothing - adds the grid to the plot as a side effect.


Meteorographica.weathermap.allocate_vector_points(initial_points=None, lat_range=(-90, 90), lon_range=(-180, 180), scale=5.0, random_state=None, max_points=10000)[source]

Allocate even coverage of points over a 2d space - for wind vectors.

WARNING This function is broken/unfinished - do not use.

To plot wind vectors in a video, we need an even coverage that moves with the wind. So we need a function that will take a set of wind-vector locations and keep their coverage fairly even, by removing any that have got too close together, and seeding new ones to fill any holes in the coverage.

Parameters:
  • points (initial) – None (default) or the output from a previous run of this function (see return value).
  • lat_range (list, optional) – The latitude range to cover with points. Defaults to (-90,90).
  • lon_range (list, optional) – The longitude range to cover with points. Defaults to (-180,180).
  • scale (float) – Characteristic separation between points (in degrees).
  • random_state (None|:obj:int`|:obj:`numpy.random.RandomState) – Random number generation seed, see sklearn.utils.check_random_state().
  • max_points (int, optional) – Maximum number of points to allocate, defaults to 10,000.
Returns:

Dictionary with components ‘Longitude’, ‘Latitude’, (both arrays of float) and ‘Age’ (array of int). The first two give the positions of each point, and ther last counts how many times each point has been updated by this function.

Return type:

dict

Raises:

StandardError – if max_points is too small - more points than this are needed to cover the region.


Meteorographica.weathermap.fetch_backgrounds()[source]

Fetch plot background data from Natural Earth.

Cartopy uses background images from Natural Earth for things like continent outlines on world maps - Meteorographica folows it in this. This function downloads some Natural Earth data (continent backgrounds) and modifies it to make ocean regions transparent for easy use in map plots.

You should only have to run this function once as part of the set-up of this module.

Requires three utility functions to be available: wget, unzip, and imagemagick convert. It will create map background files in the directory specified by the CARTOPY_USER_BACKGROUNDS environment variable which should have been set during the installation of Cartopy.

Raises:StandardError – Environment variable ‘CARTOPY_USER_BACKGROUNDS’ is not set

Meteorographica.weathermap.plot_cmesh(ax, pe, resolution=0.25, cmap=<matplotlib.colors.LinearSegmentedColormap object>, zorder=4)[source]

Plots a variable as a colour map.

This is the same as matplotlib.axes.Axes.pcolorfast(), except that it takes an iris.cube.Cube instead of an array of colour values, and its colour defaults are chosen for plots of precipitation rate.

Parameters:
  • ax (cartopy.mpl.geoaxes.GeoAxes) – Axes on which to draw.
  • pe (iris.cube.Cube) – Variable to plot.
  • resolution (float, optional) – What lat:lon resolution (in degrees) to interpolate pe.data to before plotting. Defaults to 0.25.
  • cmap (matplotlib.colors.LinearSegmentedColormap) – Mapping of pe.data to plot colour. Defaults to green semi-transparent.
  • zorder (float, optional) – Standard matplotlib parameter determining which things are plotted on top (high zorder), and which underneath (low zorder), Defaults to 4.
Returns:

See matplotlib.axes.Axes.pcolorfast() - also adds the image to the plot.


Meteorographica.weathermap.plot_contour(ax, pe, resolution=0.25, levels=None, colors='black', linewidths=0.5, alpha=1, fontsize=12, zorder=4, label=False)[source]

Plots a variable as a contour plot.

This is the same as matplotlib.axes.Axes.contour(), except that it takes an iris.cube.Cube instead of an array of values, and its defaults are chosen for plots of mean-sea-level pressure.

Parameters:
  • ax (cartopy.mpl.geoaxes.GeoAxes) – Axes on which to draw.
  • pe (iris.cube.Cube) – Variable to plot.
  • resolution (float, optional) – What lat:lon resolution (in degrees) to interpolate pe.data to before plotting. Defaults to 0.25.
  • colors (see matplotlib.colors, optional) –
  • linewidths (float, optional) – Line width for contour lines. Defaults to 0.5.
  • alpha (float, optional) – Colour alpha blend. Defaults to 1 (opaque).
  • fontsize (int, optional) – Font size for contour labels. Defaults to 12.
  • zorder (float, optional) – Standard matplotlib parameter determining which things are plotted on top (high zorder), and which underneath (low zorder), Defaults to 4.
  • label (bool, optional) – Label contour lines? Defaults to False.
Returns:

See matplotlib.axes.Axes.contour() - also adds the lines to the plot.


Meteorographica.weathermap.plot_contour_spread(ax, prmsl, resolution=0.25, cmap=<matplotlib.colors.LinearSegmentedColormap object>, levels=array([ 870, 880, 890, 900, 910, 920, 930, 940, 950, 960, 970, 980, 990, 1000, 1010, 1020, 1030, 1040]), scale=1, offset=0, threshold=0.05, line_threshold=None, colors='black', linewidths=0.5, alpha=1, fontsize=12, label=False, zorder=4)[source]

Plots a variable as a contour plot, but includes an uncertainty range.

Parameters:
  • ax (cartopy.mpl.geoaxes.GeoAxes) – Axes on which to draw.
  • prmsl (iris.cube.Cube) – Variable to plot.
  • resolution (float, optional) – What lat:lon resolution (in degrees) to interpolate pe.data to before plotting. Defaults to 0.25.
  • cmap (matplotlib.colors.LinearSegmentedColormap) – Colour for uncertainty ranges. Defaults to blue semi-transparent.
  • scale (float, optional) – Scaling factor for variable standard deviation. Defaults to 1.
  • offset (float, optional) – Offset for variable standard deviation. Defaults to 0.
  • threshold (float, optional) – Ranges shown are regions where the probability that a contour line passes through the region is greater than this. Defaults to 0.05 (5%).
  • line_threshold – Only draw contours where the local standard deviation is less than this. Defaults to None - draw contours everywhere.
Returns:

See matplotlib.axes.Axes.contour() - also adds the lines to the plot.


Meteorographica.weathermap.plot_label(ax, label, color='black', facecolor='white', x_fraction=0.98, y_fraction=0.02, horizontalalignment='right', verticalalignment='bottom', fontsize=12, zorder=5.5)[source]

Add a text label to the plot

Parameters:
  • ax (cartopy.mpl.geoaxes.GeoAxes) – Axes on which to draw.
  • color (see matplotlib.colors, optional) – Text colour of the label. Defaults to ‘black’.
  • facecolor (see matplotlib.colors, optional) – Background colour of the label. Defaults to ‘white’.
  • x_fraction (float, optional) – X position of the label (fraction of axes). Defaults to 0.98.
  • y_fraction (float, optional) – Y position of the label (fraction of axes). Defaults to 0.02.
  • horizontalalignment (str, optional) – How is the label justified to the x position (right|left|center)?. Defaults to ‘right’.
  • verticalalignment (str, optional) – How is the label justified to the y position (top|bottom|center)?. Defaults to ‘bottom’.
  • fontsize (int, optional) – Size of the text to use. Defaults to 12.
  • zorder (float, optional) – Standard matplotlib parameter determining which things are plotted on top (high zorder), and which underneath (low zorder), Defaults to 5.5.
Returns:

Nothing - adds the label points to the plot.


Meteorographica.weathermap.plot_obs(ax, obs, obs_projection=<cartopy.crs.PlateCarree object>, lat_label='Latitude', lon_label='Longitude', radius=0.1, facecolor='yellow', edgecolor='black', alpha=0.85, zorder=2.5)[source]

Plot observations as points.

Parameters:
  • ax (cartopy.mpl.geoaxes.GeoAxes) – Axes on which to draw.
  • obs (dict) – Dictionary containing obs positions.
  • obs_projection (cartopy.crs.CRS, optional) – Projection in which observations latitudes and longitudes are defined. Default is cartopy.crs.PlateCarree.
  • lat_label (str, optional) – Key, in the obs dictionary, of the latitude data. Defaults to ‘Latitude’.
  • lon_label (str, optional) – Key, in the obs dictionary, of the longitude data. Defaults to ‘Longitude’.
  • radius (float, optional) – Radius of circle marking each ob. (degrees). Defaults to 1.
  • facecolor (see matplotlib.colors, optional) – Main colour of the circle to be plotted for each ob. Defaults to ‘yellow’.
  • edgecolor (see matplotlib.colors, optional) – Border colour of the circle to be plotted for each ob. Defaults to ‘black’.
  • alpha (float, optional) – Alpha value for facecolor and edgecolor. Defaults to 0.85. Will be multiplied by the observation weight if present.
  • zorder (float, optional) – Standard matplotlib parameter determining which things are plotted on top (high zorder), and which underneath (low zorder), Defaults to 2.5.
Returns:

Nothing - adds the obs. points to the plot.


Meteorographica.weathermap.plot_quiver(ax, ue, ve, points=None, scale=None, resolution=1, color=(0, 0, 0, 0.25), headwidth=1, random_state=None, max_points=10000, zorder=5)[source]

Plots a pair of variables as a 2d field of arrows.

This is the same as matplotlib.axes.Axes.quiver(), except that it takes iris.cube.Cube as arguments instead of a set of vectors, and its defaults are chosen for plots of 10m wind.

WARNING This function is under development - in particular the argument names are badly chosen and will need to be changed.

Parameters:
  • ax (cartopy.mpl.geoaxes.GeoAxes) – Axes on which to draw.
  • ue (iris.cube.Cube) – meridional value of variable to plot.
  • ve (iris.cube.Cube) – zonal value of variable to plot.
  • resolution (float, optional) – What lat:lon resolution (in degrees) to interpolate [uv]e.data to before plotting. Defaults to 1.
  • colors (see matplotlib.colors, optional) vector colour. Defaults to (0,0,0,0.25) –
  • headwidth (float, optional) – Controls arraw shape. Defaults to 1.
  • random_state (None|:obj:int`|:obj:`numpy.random.RandomState) – Random number generation seed, see sklearn.utils.check_random_state().
  • max_points (int, optional) – Maximum number of vectors to allocate, defaults to 10,000.
  • zorder (float, optional) – Standard matplotlib parameter determining which things are plotted on top (high zorder), and which underneath (low zorder), Defaults to 5.
Returns:

See matplotlib.axes.Axes.quiver() - also adds the vectors to the plot.


Meteorographica.weathermap.plot_wind_and_temperature(ax, ue, ve, t2, points=None, scale=None, resolution=1, color=(0, 0, 0, 0.25), headwidth=1, random_state=None, max_points=10000, zorder=5)[source]

Plots a pair of variables as a 2d field of arrows, coloured according to a third variable.

This is the same as matplotlib.axes.Axes.quiver(), except that it takes iris.cube.Cube as arguments instead of a set of vectors, and its defaults are chosen for plots of 10m wind.

WARNING This function does not yet work - don’t use it..

Parameters:
  • ax (cartopy.mpl.geoaxes.GeoAxes) – Axes on which to draw.
  • ue (iris.cube.Cube) – meridional value of variable to plot.
  • ve (iris.cube.Cube) – zonal value of variable to plot.
  • t2 (iris.cube.Cube) – variable to use to select arrow colour.
  • resolution (float, optional) – What lat:lon resolution (in degrees) to interpolate [uv]e.data to before plotting. Defaults to 1.
  • colors (see matplotlib.colors, optional) vector colour. Defaults to (0,0,0,0.25) –
  • headwidth (float, optional) – Controls arrow shape. Defaults to 1.
  • random_state (None|:obj:int`|:obj:`numpy.random.RandomState) – Random number generation seed, see sklearn.utils.check_random_state().
  • max_points (int, optional) – Maximum number of vectors to allocate, defaults to 10,000.
  • zorder (float, optional) – Standard matplotlib parameter determining which things are plotted on top (high zorder), and which underneath (low zorder), Defaults to 5.
Returns:

See matplotlib.axes.Axes.quiver() - also adds the vectors to the plot.