arctichoke.plot.labels_and_titles

Functions

make_title(dataset[, add_source_id, ...])

Create a title for the dataset for use in plots.

make_label(dataset[, var, add_name, add_units])

Create a label for the specified variable in the given dataset for use in plots.

Module Contents

arctichoke.plot.labels_and_titles.make_title(dataset: str, [str], xarray.Dataset, add_source_id: bool = True, add_experiment_id: bool = True, add_variant_label: bool = True, add_time_stamp: bool = True, **kwargs)

Create a title for the dataset for use in plots.

Assemble a title to be used in plots for this dataset based on the specified attributes.

Parameters:
  • dataset (str, list of str, xarray.Dataset) – The dataset for which to make a title.

  • add_source_id (bool, optional) – Whether to add the source ID to the title. Default is True.

  • add_experiment_id (bool, optional) – Whether to add the eperiment ID to the title. Default is True.

  • add_variant_label (bool, optional) – Whether to add the variant label to the title. Default is True.

  • add_time_stamp (bool, optional) – Whether to add the time stamp to the title. This is only done if the given dataset only has one time value. Default is True.

Returns:

dataset_title – The title for the dataset.

Return type:

str

Examples

>>> from arctichoke.plot.labes_and_titles import make_title
>>> example_file = '/arctichoke_data/bergybits/data/CMIP6/HighResMIP/EC-Earth-Consortium/EC-Earth3P-HR/hist-1950/r1i1p2f1/SImon/siconc/gn/v20181212/siconc_SImon_EC-Earth3P-HR_hist-1950_r1i1p2f1_gn_200001-200012.nc'
>>> make_title(example_file)
'EC-Earth3P-HR hist-1950 r1i1p1f1 '
>>> import xarray as xr
>>> example_xr = xr.open_dataset(example_file).isel(time=6)
>>> make_title(example_xr)
'EC-Earth3P-HR hist-1950 r1i1p1f1 2000-07-16T12:00:00.000000000 '
arctichoke.plot.labels_and_titles.make_label(dataset: str, [str], xarray.DataArray, xarray.Dataset, var: str = None, add_name: bool = True, add_units: bool = True, **kwargs)

Create a label for the specified variable in the given dataset for use in plots.

Assemble a label to be used in plots on axes or colorbars for the specified variable in the given dataset based on the specified attributes.

Parameters:
  • dataset (str, list of str, xarray.DataArray, xarray.Dataset) – The dataset for which to make a label.

  • var (str, None, optional) – The variable in dataset for which to make a label. This is required if dataset is an xarray.Dataset. Default is None.

  • add_name (bool, optional) – Whether to add the variable name to the label. Default is True.

  • add_units (bool, optional) – Whether to add the units to the label. Default is True.

Returns:

dataset_label – The label for the dataset.

Return type:

str

Examples

>>> from arctichoke.plot.labes_and_titles import make_label
>>> example_file = '/arctichoke_data/bergybits/data/CMIP6/HighResMIP/EC-Earth-Consortium/EC-Earth3P-HR/hist-1950/r1i1p2f1/SImon/siconc/gn/v20181212/siconc_SImon_EC-Earth3P-HR_hist-1950_r1i1p2f1_gn_200001-200012.nc'
>>> make_label(example_file, 'siconc')
'Sea Ice Area Fraction (Ocean Grid) (%) '