BokehSynthetic#

class dtcg.interface.plotting.BokehSynthetic[source]#

Bases: BokehCryotempo

Methods

__init__()

add_curve_to_figures(figures, data, key[, ...])

Add Holoviews curve to a list of figures.

check_holoviews()

Check holoviews is installed to prevent silent failures.

decode_datacube(datacube)

Get a dataset decoded into CF conventions.

get_all_palettes()

Get all valid preset colour palettes.

get_color_palette(name)

Get a preset palette.

get_date_mask(dataframe, start_date, end_date)

Get a mask for all data between a start and end date.

get_default_opts()

Default options for Bokeh figures.

get_eolis_dates(ds)

Get time index of an EOLIS dataset.

get_eolis_mean_dh(ds)

Get time series of mean elevation change from EOLIS data.

get_help_button(text[, position, add_colors])

Get an interactive help button from a list of fields.

get_hover_tool([mode, tooltips, attachment])

Get the hover tool attribute.

get_label_from_oggm_model(key)

Get a plot label for a given OGGM model type.

get_mean_by_doy(dataframe)

Get mean by day of year.

get_mean_smb_by_doy_from_elevation(df, ...)

Get mean specific mass balance by day of year from elevation.

get_percentage_difference(a, b)

Get the percentage difference between two numerical values.

get_sine_data(size[, scaling])

get_smb_from_elevation_change(elevation, area)

Get specific mass balance from elevation change.

get_synthetic_data(year[, scale_offset])

get_title(title[, suffix, timestamp, location])

Get a title including optional parameters.

get_tooltip_format([tooltips])

Get a tooltip formatter from the tooltips attribute.

initialise_formatting(figure)

Initialise default formatting for Bokeh figures.

plot_cryotempo_comparison(smb[, years, ...])

Plot daily SMB for a specific year and geodetic mean.

plot_eolis_smb(datacube[, glacier_area, ...])

Plot daily specific mass balance from EOLIS data.

plot_eolis_timeseries(datacube[, ...])

Plot mean and standard deviation of elevation change from EOLIS data.

plot_mb_comparison(smb[, years, ...])

Plot daily SMB for a specific year and geodetic mean.

plot_synthetic_data(title, label[, ...])

set_defaults(updated_options)

Set and overwrite default options for Bokeh figures.

set_formatting_kwargs(figure, **kwargs)

Set kwargs for generic formatting.

set_hover_date_tooltips(y_name[, x_name, ...])

Set hover tool tooltips for time series.

set_hover_tool([mode])

Set the hover tool attribute.

set_overlay_options(overlay, xlabel, ylabel, ...)

Set plot options for Holoviews overlays.

set_tooltips(tooltips[, mode])

Set the tooltips attribute and update the hover tool.

to_layout(overlay[, cols, sizing_mode, ...])

Convert overlay to layout.

__init__()[source]#
add_curve_to_figures(
figures,
data,
key,
label='',
line_width=0.8,
**kwargs,
)#

Add Holoviews curve to a list of figures.

Parameters:
  • figures (list) – Holoviews figures.

  • data (dict) – 1D data to plot as a Curve.

  • key (str) – Key used to access the correct data in data.

  • label (str, optional) – Label used for the figure which will appear in the legend.

  • line_width (float, default 0.8) – The curve’s line width.

  • kwargs – Extra arguments passed to hv.Curve().

Returns:

Holoviews figures.

Return type:

list[hv.Curve]

check_holoviews()#

Check holoviews is installed to prevent silent failures.

Raises:

ImportError – If Holoviews is not installed.

Return type:

None

decode_datacube(datacube)#

Get a dataset decoded into CF conventions.

This should be called after data processing to avoid changing the datacube’s metadata.

Parameters:

datacube (GeoZarrHandler or xr.Dataset) – CryoTEMPO-EOLIS observations for elevation change.

Returns:

Dataset decoded into CF conventions.

Return type:

xr.Dataset

get_all_palettes()#

Get all valid preset colour palettes.

These are custom presets and do not include those accessible via Bokeh or Holoviews.

These are:

  • brown_blue_pastel

  • brown_blue_vivid

  • hillshade_glacier

  • lines_jet_r

Returns:

Preset colour palettes.

Return type:

dict[tuple[str]]

get_color_palette(name)#

Get a preset palette.

Parameters:

name (str) – Name of palette.

Returns:

Palette of hex colours.

Return type:

list[str]

Raises:

KeyError – If no matching palette is found.

get_date_mask(
dataframe,
start_date,
end_date,
)#

Get a mask for all data between a start and end date.

Parameters:
  • dataframe (pd.DataFrame) – Dataframe for which to get the mask.

  • start_date (str) – Start date in Y-M-D format.

  • end_date (str) – End date in Y-M-D format.

Returns:

Mask for all data between the start and end date.

Return type:

np.ndarray[date]

get_default_opts()#

Default options for Bokeh figures.

Returns:

Default options for Bokeh figures. Not necessarily compatible with Holoviews or Geoviews objects.

Return type:

dict

get_eolis_dates(ds)#

Get time index of an EOLIS dataset.

Parameters:

ds (Dataset)

Return type:

ndarray[date]

get_eolis_mean_dh(ds)#

Get time series of mean elevation change from EOLIS data.

Parameters:

ds (Dataset)

Return type:

ndarray

get_help_button(
text,
position='right',
add_colors=None,
)#

Get an interactive help button from a list of fields.

Parameters:
  • text (list[str]) – Help text.

  • position (str, default "right") – Help button position.

  • add_colors (hv.Cycle or None, default None) – Add coloured boxes next to text. Used for legend entries.

Returns:

An interactive help button that displays text on hover and click.

Return type:

bokeh.models.HelpButton

get_hover_tool(
mode='vline',
tooltips=None,
attachment='horizontal',
)#

Get the hover tool attribute.

Parameters:
  • mode (str, default "vline") – Hover mode for hover tool, e.g. “mouse”, “hline”, “vline”.

  • tooltips (list[tuple[str,str]], optional) – Hover tooltips.

  • attachment (str, default "horizontal") – Position of hover tooltip relative to cursor. Can be “horizontal”, “vertical”, “above”, or “below”.

Returns:

Hover tool with tooltips and formatter.

Return type:

bokeh.models.HoverTool

get_label_from_oggm_model(key)#

Get a plot label for a given OGGM model type.

Parameters:

key (str) – OGGM model type.

Returns:

Plot label.

Return type:

str

get_mean_by_doy(dataframe)#

Get mean by day of year.

Parameters:

dataframe (pd.DataFrame) – Time series.

Returns:

Mean indexed by day of year.

Return type:

pd.DataFrame

get_mean_smb_by_doy_from_elevation(
df,
ref_year,
glacier_area,
)#

Get mean specific mass balance by day of year from elevation.

Parameters:
  • df (pd.DataFrame) – Elevation change data.

  • ref_year (int) – Reference year.

  • glacier_area (float) – Area of glacier, km2.

Returns:

Mean specific balance by day of year.

Return type:

pd.Series

get_percentage_difference(a, b)#

Get the percentage difference between two numerical values.

\[\frac{\left | B-A \right |}{\left ( \frac{A+B}{2} \right )}\]
Parameters:
  • a (Any) – Numerical value or array of values.

  • b (Any) – Numerical value or array of values. Must have the same dimensions as a.

Returns:

Percentage difference between two numerical values.

Return type:

Any

get_smb_from_elevation_change(
elevation,
area,
ice_density=850.0,
)#

Get specific mass balance from elevation change.

Parameters:
  • elevation (array_like) – Elevation change data.

  • area (float) – Area of glacier in km2.

  • ice_density (float, default 850.0) – Density of ice.

Returns:

Specific mass balance.

Return type:

array_like

get_title(
title,
suffix='',
timestamp='',
location='',
)#

Get a title including optional parameters.

Parameters:
  • title (str) – Title of figure.

  • suffix (str) – Comment appended to returned title. Default empty string.

  • timestamp (str or datetime.datetime, optional) – Timestamp. Default empty string.

  • location (str) – Location. Default empty string.

Returns:

A title optionally including location, timestamp, and a suffix.

Return type:

str

get_tooltip_format(tooltips=None)#

Get a tooltip formatter from the tooltips attribute.

This ensures all tooltips with a format string (in curly braces) are formatted as fstrings. Skips tooltips without a format string.

Parameters:

tooltips (list[tuple[str,str]], optional.) – List of Bokeh figure tooltips.

Returns:

Tooltip field names with an associated “printf” or “datetime” value.

Return type:

dict

initialise_formatting(figure)#

Initialise default formatting for Bokeh figures.

Called separately from other plotting functions in this module to avoid overwriting on-the-fly formatting changes.

Parameters:

figure (bokeh.plotting.figure) – An unformatted Bokeh plot.

Returns:

Figure with default options applied.

Return type:

bokeh.plotting.figure

plot_cryotempo_comparison(
smb,
years=None,
glacier_name='',
geodetic_period='2000-01-01_2020-01-01',
ref_year=2015,
datacube=None,
gdir=None,
percentage_difference=False,
averaged=False,
daily=True,
)#

Plot daily SMB for a specific year and geodetic mean.

Parameters:
  • smb (dict) – Specific mass balance data for various OGGM models.

  • years (list, default None) – OGGM output years.

  • glacier_name (str, default empty string) – Name of glacier.

  • geodetic_period (str, default "2000-01-01_2020-01-01") – Period over which to take the mean daily specific mass balance.

  • ref_year (int, default 2015) – Reference year.

  • datacube (xr.DataArray, default None) – CryoTEMPO-EOLIS observations for elevation change.

  • gdir (GlacierDirectory, default None) – Glacier of interest.

  • percentage_difference (bool, default False) – If True, calculate and display the percentage difference between CryoTEMPO-EOLIS observations and modelled specific mass balance.

plot_eolis_smb(
datacube,
glacier_area=None,
years=None,
ref_year=2015,
cumulative=False,
glacier_name='',
)#

Plot daily specific mass balance from EOLIS data.

Parameters:
  • datacube (GeoZarrHandler) – CryoTEMPO-EOLIS observations for elevation change.

  • years (list, default None) – Range of desired measurement period in years.

  • ref_year (int, default 2015) – Reference year.

  • cumulative (bool, default False) – If True, calculate and display the cumulative sum of specific mass balance.

  • glacier_name (str, default empty string) – Name of glacier added to plot title.

Returns:

Interactive figure showing the mean and standard deviation of elevation change.

Return type:

hv.Overlay

plot_eolis_timeseries(
datacube,
glacier_area=None,
mass_balance=False,
glacier_name='',
)#

Plot mean and standard deviation of elevation change from EOLIS data.

Parameters:
  • datacube (GeoZarrHandler) – CryoTEMPO-EOLIS observations for elevation change.

  • mass_balance (bool, default False) – If True, calculate and display the specific mass balance from elevation change. Requires a valid glacier area.

  • glacier_name (str, default empty string) – Name of glacier added to plot title.

Returns:

Interactive figure showing the mean and standard deviation of elevation change.

Return type:

hv.Overlay

plot_mb_comparison(
smb,
years=None,
glacier_name='',
model_name='DailyTIModel',
geodetic_period='2000-01-01_2020-01-01',
ref_year=2015,
datacube=None,
gdir=None,
resample=False,
cumulative=False,
)#

Plot daily SMB for a specific year and geodetic mean.

Parameters:
  • smb (dict) – Specific mass balance data for various OGGM models.

  • years (list, default None) – OGGM output years.

  • glacier_name (str, default empty string) – Name of glacier.

  • geodetic_period (str, default "2000-01-01_2020-01-01") – Period over which to take the mean daily specific mass balance.

  • ref_year (int, default 2015) – Reference year.

  • datacube (xr.DataArray, default None) – CryoTEMPO-EOLIS observations for elevation change.

  • gdir (GlacierDirectory, default None) – Glacier of interest.

  • resample (bool, default False) – If True, resample observations to begin on the first day of the month.

  • cumulative (bool, default False) – If True, calculate and display the cumulative sum of specific mass balance.

  • model_name (str)

set_defaults(updated_options)#

Set and overwrite default options for Bokeh figures.

Parameters:

updated_options (dict) – New key/value pairs which will overwrite the default options.

Return type:

None

set_formatting_kwargs(figure, **kwargs)#

Set kwargs for generic formatting.

Applies annotations, titles, labels.

Parameters:
  • figure (bokeh.plotting.figure) – An unformatted Bokeh plot.

  • kwargs – Additional arguments passed to Bokeh figures.

Returns:

Figure with default options applied.

Return type:

bokeh.plotting.figure

set_hover_date_tooltips(
y_name,
x_name='Date',
x_format='$snap_x{%d %B}',
y_format='$snap_y{%.2f mm w.e.}',
)#

Set hover tool tooltips for time series.

Note these are Holoviews’ own formatting codes.

Parameters:
  • y_name (str) – Name of dependent variable.

  • x_name (str, default Date) – Name of independent variable.

  • x_format (str, default "$snap_x{%d %B}") – Annotation formatting code for the independent variable. The default will show the day and month.

  • y_format (str) – Annotation formatting code for the dependent variable. The default will show “mm w.e.”.

set_hover_tool(mode='vline')#

Set the hover tool attribute.

Parameters:

mode (str, default "vline") – Hover mode for hover tool, e.g. “mouse”, “hline”, “vline”.

set_overlay_options(
overlay,
xlabel,
ylabel,
title,
aspect=2,
legend_position='top_left',
**kwargs,
)#

Set plot options for Holoviews overlays.

Parameters:
  • overlay (hv.Overlay) – Holoviews plot.

  • xlabel (str) – X-axis label.

  • ylabel (str) – Y-axis label.

  • title (str) – Plot title.

  • aspect (int, default 2) – Aspect ratio. Currently disabled due to several Holoviews bugs.

  • legend_position (str, default "top_left") – Location of legend box.

  • kwargs – Additional parameters passed to hv.Overlay objects.

Returns:

Holoviews plot with updated options.

Return type:

hv.Overlay

set_tooltips(tooltips, mode='vline')#

Set the tooltips attribute and update the hover tool.

Parameters:
  • tooltips (list[tuple[str,str]]) – List of Bokeh figure tooltips. The tooltips should only contain printf formatters.

  • mode (str, default "vline") – Hover mode for hover tool, e.g. “mouse”, “hline”, “vline”.

Return type:

None

to_layout(
overlay,
cols=1,
sizing_mode='stretch_width',
shared_axes=False,
**kwargs,
)#

Convert overlay to layout.

Parameters:
  • overlay (list or hv.Overlay) – Either an Overlay object or a list of overlays.

  • cols (int, default 1) – Force the number of allowed columns in the layout.

  • sizing_mode (str, default "stretch_width".) – Layout responsiveness to screen dimensions.

  • shared_axes (bool, default False) – Whether the overlays should share data axes.

  • **kwargs – Extra arguments passed to hv.Layout options.

Return type:

Layout