climind.plotters package

The plotters module contains the code for plotting datasets. The plotting code itself is in plot_types which has functions for plotting TimeSeries data of varying time resolutions and also GridAnnual data. The plots all return a string which is the caption of the plot. The plots follow a template, with the following inputs:

  • out_dir

  • list of data sets

  • image filename

  • title for the plot

plot_utils contains a set of functions which support the plotting code including calculation of trends, ranks, setting tick marks, building captions and so on.

Submodules

climind.plotters.plot_types module

climind.plotters.plot_types.accumulate(in_array)

Calculate the accumulated mean for an array so that the nth value is the mean of the first n values in the input array.

Parameters

in_array

climind.plotters.plot_types.add_data_sets(axis, all_datasets: List[Union[TimeSeriesAnnual, TimeSeriesMonthly, TimeSeriesIrregular]], dark: bool = False) List[int]

Given a list of data sets, plot each one on the provided axis.

Parameters
  • axis (Matplotlib axis) – Set of Matplotlib axes for plotting on

  • all_datasets (List[Union[TimeSeriesAnnual, TimeSeriesMonthly, TimeSeriesIrregular]]) – list of data sets to be plotted on the axes

  • dark (bool) – Set to True to plot in the dark style (charcoal background, light coloured lines)

Returns

List of the zorder of the plotted data sets

Return type

List[int]

climind.plotters.plot_types.add_labels(axis, dataset: Union[TimeSeriesAnnual, TimeSeriesMonthly, TimeSeriesIrregular]) str

Add labels to the x and y axes

Parameters
Returns

Units of the y-axis

Return type

str

climind.plotters.plot_types.after_plot(zords: List[int], ds: Union[TimeSeriesAnnual, TimeSeriesMonthly, TimeSeriesIrregular], title: str) None

Add fancy stuff to the plots after all the data lines have been plotted.

Parameters
  • zords (List[int]) – List of the zorders of the data sets

  • ds (Union[TimeSeriesAnnual, TimeSeriesMonthly, TimeSeriesIrregular]) – Example dataset of the datasets plotted, used to determine where to plot the legend and the climatology period

  • title (str) – Title for the plot

Return type

None

climind.plotters.plot_types.antarctic_sea_ice_plot(out_dir: Path, all_datasets: List[TimeSeriesMonthly], image_filename: str, _) str

Generate figure showing the February and September Antarctic sea ice extent anomalies for the input datasets.

Parameters
  • out_dir (Path) – Directory to which the image will be written

  • all_datasets (List[TimeSeriesMonthly]) – List of data sets of type TimeSeriesMonthly to be plotted

  • image_filename (str) – File name for the image, should end in .png.

Returns

Caption for the figure

Return type

str

climind.plotters.plot_types.arctic_sea_ice_plot(out_dir: Path, all_datasets: List[TimeSeriesMonthly], image_filename: str, _) str

Generate figure showing the March and September sea ice extent anomalies for the input datasets.

Parameters
  • out_dir (Path) – Directory to which the image will be written

  • all_datasets (List[TimeSeriesMonthly]) – List of data sets of type TimeSeriesMonthly to be plotted

  • image_filename (str) – File name for the image, should end in .png.

Returns

Caption for the figure

Return type

str

climind.plotters.plot_types.cherry_plot(out_dir: Path, all_datasets: List[Union[TimeSeriesAnnual, TimeSeriesMonthly, TimeSeriesIrregular]], image_filename: str, title: str) str
climind.plotters.plot_types.dark_plot(out_dir: Path, all_datasets: List[Union[TimeSeriesAnnual, TimeSeriesMonthly, TimeSeriesIrregular]], image_filename: str, title: str) str

Plot the data sets in the dark style - charcoal background with light coloured lines. Tron like.

Parameters
  • out_dir (Path) – Directory to which the plot will be written

  • all_datasets (List[Union[TimeSeriesAnnual, TimeSeriesMonthly, TimeSeriesIrregular]]) – List of datasets to be plotted

  • image_filename (str) – Name for the file to be written. Should end with .png

  • title (str) – Title for the plot

Returns

Caption for the figure

Return type

str

climind.plotters.plot_types.dashboard_map(out_dir: Path, all_datasets: List[GridAnnual], image_filename: str, title: str) str
climind.plotters.plot_types.dashboard_map_generic(out_dir: Path, all_datasets: List[GridAnnual], image_filename: str, title: str, grid_type: str, region: Optional[list] = None) str

Plot generic style map for the dashboard. Type must be one of “mean”, “rank”, or “unc”.

Parameters
  • out_dir (Path) – Output directory to which the image will be written

  • all_datasets (List[GridAnnual]) – List of GridAnnual datasets to be plotted

  • image_filename (str) – Filename for output file

  • title (str) – Title for the plot

  • grid_type (str) – Indicates how the datasets in the input list should be combined, ‘mean’, ‘rank’ or ‘unc’

  • region (list) – four member list specifying the western, eastern, southern, and northern extents of the region to be plotted.

Returns

Caption for the figure

Return type

str

climind.plotters.plot_types.dashboard_map_single(out_dir: Path, all_datasets: List[GridAnnual], image_filename: str, title: str) str
climind.plotters.plot_types.dashboard_rank_map(out_dir: Path, all_datasets: List[GridAnnual], image_filename: str, title: str) str
climind.plotters.plot_types.dashboard_uncertainty_map(out_dir: Path, all_datasets: List[GridAnnual], image_filename: str, title: str) str
climind.plotters.plot_types.decade_plot(out_dir: Path, all_datasets: List[TimeSeriesAnnual], image_filename: str, title: str) str

Decadal plot

Parameters
  • out_dir (Path) – Path of the directory to which the image will be written

  • all_datasets (List[TimeSeriesAnnual]) – List of datasets of type TimeSeriesAnnual to be plotted.

  • image_filename (str) – Name for the image file, should end in .png

  • title (str) – Title for the image, will appear at the top of the figure

Returns

Caption for the figure

Return type

str

climind.plotters.plot_types.equivalence(key)
climind.plotters.plot_types.get_levels_and_palette(variable: str)
climind.plotters.plot_types.marine_heatwave_plot(out_dir: Path, all_datasets: List[TimeSeriesAnnual], image_filename: str, _) str

Marine heatwave and coldspell plot, which shows the ocean area affected by marine heatwaves and coldspells annually since the early 1980s

Parameters
  • out_dir (Path) – Path of the directory to which the image will be written

  • all_datasets (List[TimeSeriesAnnual]) – List of data sets of type TimeSeriesAnnual to plot

  • image_filename (str) – File name for the image, should end in .png

Returns

Caption for the figure

Return type

str

climind.plotters.plot_types.monthly_plot(out_dir: Path, all_datasets: List[TimeSeriesMonthly], image_filename: str, title: str) str

Create the standard monthly plot

Parameters
  • out_dir (Path) – Path of directory to which the image will be written

  • all_datasets (List[TimeSeriesMonthly]) – List of datasets of type TimeSeriesMonthly to plot

  • image_filename (str) – File name for the image

  • title (str) – Title which will appear at the top of the figure.

Returns

Caption for the figure

Return type

str

climind.plotters.plot_types.neat_plot(out_dir: Path, all_datasets: List[Union[TimeSeriesAnnual, TimeSeriesMonthly, TimeSeriesIrregular]], image_filename: str, title: str, dark: bool = False) str

Create the standard annual plot

Parameters
  • out_dir (Path) – Directory to which the figure will be written

  • all_datasets (List[Union[TimeSeriesAnnual, TimeSeriesMonthly, TimeSeriesIrregular]]) – list of datasets to be plotted

  • image_filename (str) – filename for the figure. Must end in .png

  • title (str) – title for the plot

  • dark (bool) – set to True to plot using a dark background

Returns

Caption for the figure is returned

Return type

str

climind.plotters.plot_types.nice_map(dataset: xarray.Dataset, image_filename: Path, title: str, var: str = 'tas_mean') None

Plot a nice looking map (relatively speaking) of the last field in an xarray dataset.

Parameters
  • dataset (xarray.Dataset) – Data set to be plotted

  • image_filename (Path) – Name for output file

  • title (str) – Title for the plot

  • var (str) – Variabel to plot from the dataset

Return type

None

climind.plotters.plot_types.plot_map_by_year_and_month(dataset: GridMonthly, year: int, month: int, image_filename: Path, title: str, var: str = 'tas_mean') None

Plot map for specified year and month

Parameters
  • dataset (GridMonthly) – GridMonthly to be plotted

  • year (int) – Year to be plotted

  • month (int) – Month in year to be plotted

  • image_filename (Path) – Path to output file

  • title (str) – Title for the plot

  • var (str) – Variable to be plotted

Return type

None

climind.plotters.plot_types.preindustrial_summary_plot(out_dir: Path, in_all_datasets: List[TimeSeriesAnnual], image_filename: str, title: str) str
climind.plotters.plot_types.quick_and_dirty_map(dataset: xarray.Dataset, image_filename: Path) None

Quick and very rough map plotter which plots the last field in an xarray Dataset

Parameters
  • dataset (xarray.Dataset) – xarray Dataset to be plotted.

  • image_filename (Path) – Path for the output file

Return type

None

climind.plotters.plot_types.regional_dashboard_map(out_dir: Path, all_datasets: List[GridAnnual], image_filename: str, title: str, west=None, east=None, south=None, north=None) str
climind.plotters.plot_types.regional_dashboard_uncertainty_map(out_dir: Path, all_datasets: List[GridAnnual], image_filename: str, title: str, west=None, east=None, south=None, north=None) str
climind.plotters.plot_types.set_xaxis(axis) Tuple[float, float, numpy.ndarray]

Work out the extents of the x axis and the tick values

Parameters

axis (Matplotlib axis) – The axis on which everything is being plotted

Returns

The lowest and highest points on the y axis and an array of tick values for the major ticks on the y axis.

Return type

Tuple[float, float, np.ndarray]

climind.plotters.plot_types.set_yaxis(axis, dataset: Union[TimeSeriesAnnual, TimeSeriesMonthly, TimeSeriesIrregular]) Tuple[float, float, numpy.ndarray]

Work out the extents of the y axis and the tick values

Parameters
Returns

The lowest and highest points on the y axis and an array of tick values for the major ticks on the y axis.

Return type

Tuple[float, float, np.ndarray]

climind.plotters.plot_types.show_premade_image(out_dir: Path, in_all_datasets: List[TimeSeriesAnnual], image_filename: str, title: str, original_filename: str = '', caption: str = '')
climind.plotters.plot_types.trends_plot(out_dir: Path, in_all_datasets: List[TimeSeriesAnnual], image_filename: str, title: str, order: list = []) str

Trend figure which shows the mean and range of the trends from the input data sets over four 30-year periods: 1901-1930, 1931-1960, 1961-1990 and 1991-present. This is set up to work with WMO RA and Africa Subregion timeseries.

Parameters
  • out_dir (Path) – Path of the directory to which the figure will be written

  • in_all_datasets (List[TimeSeriesAnnual]) – List of data sets of type TimeSeriesAnnual to be plotted

  • image_filename (str) – File name for the output figure

  • title (str) – Title of the figure, appears at the top of the figure

  • order (list) – The order in which the variables will be plotted, from left to right, in each sub-block

Returns

Caption for the figure

Return type

str

climind.plotters.plot_types.wave_plot(out_dir: Path, dataset: TimeSeriesMonthly, image_filename) None

Wave plot with month on the x-axis from January to December and each year shown as a separate line showing the cumulative average for the year-to-date for that year.

Parameters
  • out_dir (Path) – Path to the directory to which the image will be written.

  • dataset (TimeSeriesMonthly) – TimeSeriesMonthly to plot.

  • image_filename (str) – Name of the image file to be written.

Return type

None

climind.plotters.plot_utils module

climind.plotters.plot_utils.calculate_highest_year_and_values(all_datasets: List[TimeSeriesAnnual]) Tuple[List[int], List[List[float]]]

From the list of TimeSeriesAnnual get the year that ranks first in each data set. Then, for each of those years get the highest and lowest data value from all of the data sets.

Parameters

all_datasets (List[TimeSeriesAnnual]) – List of TimeSeriesAnnual data sets

Returns

The first returned element is a list of years that rank first in the data sets. The second element is a list with the same length as the first. Each element in the list is two-element list holding the lowest and highest values found in any of the datasets for the corresponding year in the first list.

Return type

Tuple[List[int], List[List[float]]]

climind.plotters.plot_utils.calculate_ranks(all_datasets: List[TimeSeriesAnnual], year: int, ascending: bool = False) Tuple[int, int]

given a set of data sets, return the min and max ranks from the data sets for a given year.

Parameters
  • all_datasets (list) – list of data sets

  • year (int) – year to calculate ranks for

  • ascending (bool) – Set to true to rank low (1st) to high (nth) rather than high (1st) to low (nth)

Returns

Return the minimum and maximum rank for the specified year in all data sets

Return type

Tuple[float, float]

given a set of data sets, return the mean, min and max trends from the data sets calculated using OLS between the chosen years.

Parameters
  • all_datasets (List[TimeSeriesAnnual]) – list of TimeSeriesAnnual data sets

  • trend_start_year (int) – first year for trend

  • trend_end_year (int) – last year for trend

Returns

returns the mean trend, minimum trend and maximum trend from the input datasets in units/decade

Return type

Tuple[float, float, float]

climind.plotters.plot_utils.calculate_values(all_datasets: List[TimeSeriesAnnual], year: int) Tuple[float, float, float]

given a set of data sets, return the mean min and max values from the data sets for specified year.

Parameters
  • all_datasets (list) – list of TimeSeriesAnnual data sets

  • year (int) – year to calculate values for

Returns

Return the mean, min and max values for the chosen year from all_datasets

Return type

Tuple[float, float, float]

climind.plotters.plot_utils.calculate_values_ipcc_style(all_datasets: List[TimeSeriesAnnual], year: int) Tuple[float, float, float]

given a set of data sets, return the mean min and max values from the data sets for specified year.

Parameters
  • all_datasets (list) – list of TimeSeriesAnnual data sets

  • year (int) – year to calculate values for

Returns

Return the mean, min and max values for the chosen year from all_datasets

Return type

Tuple[float, float, float]

climind.plotters.plot_utils.caption_builder(all_datasets: List[Union[TimeSeriesMonthly, TimeSeriesAnnual]]) str

Write a caption for the standard time series plots.

Parameters

all_datasets (List[Union[TimeSeriesMonthly, TimeSeriesAnnual]]) – List of datasets used in the plot

Returns

Caption for the collection of data sets

Return type

str

climind.plotters.plot_utils.get_first_and_last_years(all_datasets: List[Union[TimeSeriesMonthly, TimeSeriesAnnual]]) Tuple[int, int]

Extract the first and last years from a list of data sets

Parameters

all_datasets (List[Union[TimeSeriesMonthly, TimeSeriesAnnual]])) – List containing the data sets for which we want the first and last years

Returns

First and last years

Return type

Tuple[int, int]

climind.plotters.plot_utils.map_caption_builder(all_datasets: List[GridAnnual], grid_type: str) str

Write a caption for the standard map plots.

Parameters
  • all_datasets (List[Union[GridAnnual]]) – List of datasets used in the plot

  • grid_type (str) – Type is one of ‘mean’, ‘rank’ or ‘unc’.

Returns

Caption for the collection of data sets

Return type

str

climind.plotters.plot_utils.set_lo_hi_ticks(limits: list, spacing: float) Tuple[float, float, numpy.ndarray]

Given axis limits and a preferred spacing, calculate new high and low values and a set of ticks

Parameters
  • limits (list) – the lower and upper limits of the current axis

  • spacing (float) – The preferred tick spacing