dvas.plots package

Copyright (c) 2020-2022 MeteoSwiss, contributors listed in AUTHORS.

Distributed under the terms of the GNU General Public License v3.0 or later.

SPDX-License-Identifier: GPL-3.0-or-later

Submodules

dvas.plots.dtas module

Copyright (c) 2020-2022 MeteoSwiss, contributors listed in AUTHORS.

Distributed under the terms of the GNU General Public License v3.0 or later.

SPDX-License-Identifier: GPL-3.0-or-later

Module contents: Plotting functions related to the delta submodule.

dvas.plots.dtas.dtas(dta_prfs, k_lvl=1, label='mid', **kwargs)

Makes a plot comparing different Delta profiles with their associated combined working measurement standard.

All profiles must imperatively be fully synchronized. It is also assumed that they have all been build using the same working standard, i.e. they all have the same errors !

Parameters:
  • dta_prfs (dvas.data.data.MultiDeltaProfile) – the Delta profiles

  • k_lvl (int|float, optional) – k-level for the uncertainty. Defaults to 1.

  • label (str, optional) – label of the plot legend. Defaults to ‘mid’.

  • **kwargs – these get fed to the dvas.plots.utils.fancy_savefig() routine.

Returns:

matplotlib.pyplot.figure – the figure instance

dvas.plots.gdps module

Copyright (c) 2020-2022 MeteoSwiss, contributors listed in AUTHORS.

Distributed under the terms of the GNU General Public License v3.0 or later.

SPDX-License-Identifier: GPL-3.0-or-later

Module contents: Plotting functions related to the gruan submodule.

dvas.plots.gdps.gdps_vs_cws(gdp_prfs, cws_prf, k_lvl=1, label='mid', **kwargs)

Makes a plot comparing different GDPs with their associated combined working measurement standard.

All profiles must imperatively be fully synchronized.

Parameters:
  • gdp_prfs (dvas.data.data.MultiGDPProfile) – the GDPs

  • cws_prf (dvas.data.data.MultiCWSProfile) – the combined working standards, for example generated by dvas.tools.gruan.combine_gdps().

  • k_lvl (int|float, optional) – k-level for the uncertainty. Defaults to 1.

  • label (str, optional) – label of the plot legend. Defaults to ‘mid’.

  • **kwargs – these get fed to the dvas.plots.utils.fancy_savefig() routine.

Returns:

matplotlib.pyplot.figure – the figure instance

dvas.plots.gdps.uc_budget(gdp_prfs, cws_prf, k_lvl=1, label='mid', **kwargs)

Makes a plot of the uncertainty budget of GDPs and (as an option) associated CWS.

All profiles must imperatively be fully synchronized. Don’t try fancy things …

Parameters:
  • gdp_prfs (dvas.data.data.MultiGDPProfile) – the GDPs

  • cws_prf (dvas.data.data.MultiCWSProfile) – the combined working standards, for example generated by dvas.tools.gruan.combine_gdps(). Defaults to None.

  • k_lvl (int|float, optional) – k-level for the uncertainty. Defaults to 1.

  • label (str, optional) – label of the plot legend. Defaults to ‘mid’.

  • **kwargs – these get fed to the dvas.plots.utils.fancy_savefig() routine.

Returns:

matplotlib.pyplot.figure – the figure instance

dvas.plots.gdps.plot_ks_test(df, alpha, unit=None, left_label=None, right_label=None, **kwargs)

Creates a diagnostic plot for the KS test.

Parameters:
  • df (pd.DataFrame) – a very special DataFrame, generated inside dvas.tools.gdps.stats.get_incomptibility().

  • alpha (float) – significance level used for the flags. Must be 0 <= alpha <= 1. Required for setting up the colorbar properly.

  • unit (str, optional) – the unit of the variable displayed. Defaults to None.

  • left_label (str, optional) – top-left plot label. Defaults to None.

  • right_label (str, optional) – top-right plot label. Defaults to None.

  • **kwargs – these get fed to the dvas.plots.utils.fancy_savefig() routine.

Returns:

matplotlib.pyplot.figure – the figure instance

dvas.plots.plots module

Copyright (c) 2020-2022 MeteoSwiss, contributors listed in AUTHORS.

Distributed under the terms of the GNU General Public License v3.0 or later.

SPDX-License-Identifier: GPL-3.0-or-later

Module contents: Primary plotting functions of dvas.

dvas.plots.plots.multiprf(prfs, index='alt', label='mid', uc=None, k_lvl=1, rel_to=None, expose=None, **kwargs)

Plots the content of a MultiProfile instance.

Parameters:
  • prfs (MultiProfile|MultiRSProfile|MultiGDPprofile) – MultiProfile instance to plot

  • index (str, optional) – reference variables for the plots, either ‘_idx’, ‘tdt’ or ‘alt’. Defaults to ‘alt’.

  • label (str, optional) – name of the label for each curve, that will be fed to prfs.get_info(label). Defaults to ‘mid’.

  • uc (str, optional) – which uncertainty to plot, if any. Can be one of [‘ucs’, ‘uct’, ‘ucu’, ‘uc_tot’]. Defaults to None.

  • k_lvl (int|float, optional) – k-level for the uncertainty, if uc is not None. Defaults to 1.

  • rel_to (int, optional) – if set, will plot the differences with respect to prfs[rel_to]. Defaults to None. If set, the profiles MUST have been synchronized beforehand !

  • expose (int, optional) – if set, only profile[expose] will be plotted in color. This is meant to “anonymize” the plot with respect to a specific profile. Defaults to None. If set, the labels of all the profiles will still appear !

  • **kwargs – these get fed to the dvas.plots.utils.fancy_savefig() routine.

Returns:

matplotlib.pyplot.figure – the figure instance

dvas.plots.utils module

Copyright (c) 2020-2023 MeteoSwiss, contributors listed in AUTHORS.

Distributed under the terms of the GNU General Public License v3.0 or later.

SPDX-License-Identifier: GPL-3.0-or-later

Module contents: Utility functions and parameters for plotting in dvas.

dvas.plots.utils.WIDTH_ONECOL = 6.92

Width of a 1-column plot [inches], to fit in scientific articles when scaled by 50%

Type:

float

dvas.plots.utils.WIDTH_TWOCOL = 14.16

Width of a 2-column plot [inches], to fit in scientific articles when scaled by 50%

Type:

float

dvas.plots.utils.PLOT_STYLES = {'base': 'base.mplstyle', 'latex': 'latex.mplstyle', 'nolatex': 'nolatex.mplstyle'}

The name of the different dvas matplotlib style sheets

Type:

dict

dvas.plots.utils.CLRS = {'cmap_1': [(0, '#000000'), (0, '#051729'), (0.5, '#4c88b3'), (1, '#dbd7cc'), (1, '#ffffff')], 'cws_1': '#323232', 'nan_1': '#7d7d7d', 'ref_1': 'crimson', 'set_1': ['#4c88b3', '#b34c88', '#88b34c', '#d15f56', '#7d70b4', '#00a7a0', '#bf8a31', '#d0d424', '#b3b3b3', '#575757']}

dvas core colors for the cmap, the color cycler, and NaNs.

Type:

dict

dvas.plots.utils.CMAP_1 = <matplotlib.colors.LinearSegmentedColormap object>

the default dvas colormap 1

Type:

matplotlib.colors.LinearSegmentedColormap

dvas.plots.utils.CMAP_1_R = <matplotlib.colors.LinearSegmentedColormap object>

the default dvas colormap 1 reversed

Type:

matplotlib.colors.LinearSegmentedColormap

dvas.plots.utils.PLOT_FMTS = ['png']

The default file extensions to save the plots into.

Type:

list[str]

dvas.plots.utils.UNIT_LABELS = {'K': 'K$^{\\circ}$', 'degree': '$^{\\circ}$', 'hPa': 'hPa', 'm': 'm', 'm s-1': 'm s$^{-1}$', 'percent': '\\%'}

matches the GDP units name to their (better) plot format

Type:

dict

dvas.plots.utils.set_mplstyle(style='base')

Set the DVAS plotting style. ‘base’ contains all the generic commands. ‘latex’ enables the use of a system-wide LaTeX engine. ‘nolatex’ disables it.

Parameters:

name (str | dict, optional) – A style specification. Defaults to ‘base’. Valid options are:

  • str: One of [‘base’, ‘nolatex’, ‘latex’] defined inside DVAS.

  • dict: Dictionary with valid key/value pairs for matplotlib.rcParams.

Caution

Specifying the ‘latex’ style requires a working system-wide LaTeX installation. Specifying ‘nolatex’ enables the default matplotlib LaTeX.

Note

Users willing to override/enhance the default ‘base’ style can do so by feeding a dict of valid rcParams codes to this function.

dvas.plots.utils.add_sec_axis(ax, xvals, new_xvals, offset=-0.1, which='x')

Adds a secondary x-axis to the figure.

Parameters:
  • ax (matplotlib axis) – the axis to which to add the new x-axis

  • xvals (np.ndarray) – current x-axis values, spanning the full range of the plot. Must not contain NaNs.

  • new_xvals (np.ndarray) – new x-axis values. Must be able to linearly interpolate with xvals, and contain no NaN’s whatsoever.

  • offset (float, optional) – offset by which to shift the new axis. Defaults to -0.1.

  • which (str, optional) – ‘x’, or ‘y’, the axis to duplicate.

Returns:

matplotlib axis – the newly created axis.

dvas.plots.utils.fix_txt(txt, usetex=None)

Corrects any string for problematic characters before it gets added to a plot. Fixes vary depending whether on the chosen plotting style’s value of usetex in rcparams.

Parameters:
  • txt (str) – text to cleanup.

  • usetex (bool, optional) – if set, allows to override the default settings. Defaults to None.

Returns:

str – the corrected string.

dvas.plots.utils.cmap_discretize(cmap, n_cols)

Return a discrete colormap from any continuous colormap cmap.

Parameters:
  • cmap (str) – colormap name or instance.

  • n_cols (int) – number of colors.

Note

Adapted from the Scipy Cookbook.

Example

x = resize(arange(100), (5,100))
djet = cmap_discretize(cm.jet, 5)
imshow(x, cmap=djet)
dvas.plots.utils.fancy_legend(this_ax, label=None)

A custom legend routine, to take care of all the repetitive aspects for this.

Parameters:
  • this_ax (matplotlib.pyplot.axes) – the plot axes to add the legend to.

  • label (str, optional) – the legend label

dvas.plots.utils.get_edt_eid_rid(prfs)

Extract basic edt, eid, and rid info from a MultiProfile, and build a basic string with this info. Intented to be used for adding consistent info to plots.

Parameters:

prfs (Multiprofile|MultiRSProfile|MultiGDPProfile) – the MultiProfile to extract the info from.

Returns:

str – a formatted string, ready to b added to a plot or a filename.

dvas.plots.utils.add_edt_eid_rid(this_ax, prfs)

Add basic edt, eid and rid info to a plot.

Parameters:
  • this_ax (matplotlib.pyplot.axes) – the axes to add the info to.

  • prfs (Multiprofile|MultiRSProfile|MultiGDPProfile) – the MultiProfile to extract the info from.

dvas.plots.utils.add_var_and_k(ax, mid=None, var_name=None, k=None, offset=1.03)

Adds the name of the variable to the plot.

Parameters:
  • ax (matplotlib.pyplot.axis) – the axis to which the var name should be added.

  • mid (str, optional) – model id name. Defaults to None.

  • var_name (str, optional) – the variable name. Defaults to None.

  • k (int, float, optional) – k-level at which the uncertainties are shown. Defaults to None.

  • offset (float, optional) – yoffset for the label. Defaults to 1.03.

dvas.plots.utils.add_source(fig)

Add a sentence about the dvas version to a given plot.

Parameters:

fig (matplotlib.pyplot.figure) – the figure to add the text to.

dvas.plots.utils.fancy_savefig(fig, fn_core, fn_prefix=None, fn_suffix=None, fmts=None, show=None)

A custom savefig function that provides finer handling of the filename.

Parameters:
  • fig (matplotlib.figure) – the figure to save.

  • fn_core (str) – the core part of the filename.

  • fn_prefix (str, optional) – a prefix, to which fn_core will be appended with a ‘_’. Defauts to None.

  • fn_suffix (str, optional) – a suffix, that will be appended to fn_core with a ‘_’.

  • fmts (str|list of str, optional) – which formats to export the plot to, e.g.: ‘png’. Defaults to None (= as specified by dvas.plots.utils.PLOT_FMTS)

  • show (bool, optional) – whether to display the plot after saving it, or not. Defaults to None (= as specified by dvas.plots.utils.PLOT_SHOW)

dvas.plots.utils.wrap_wdir_curve(x, y)

A simple routine that alters an x-y series of angles, by breaking connections between successive points that have more than 180deg offset.

Parameters:
  • x (ndarray) – the x-values.

  • y (ndarray) – the y-values, angles in degrees in the range [0, 360]

Returns:

x, y – the altered arrays, ready to be plotted.

This routine essentially allows to remove large vertical “bars” that would otherwise be common in wind_dir plots for angles oscillating around 0=360 deg.

Note

This function is not flexible at all. It absolutely requires angles in degrees in the range [0, 360[.

dvas.plots.utils.clr_palette_demo()

A simple function to demonstrate the dvas color palette.