erlab.accessors.utils

Functions

either_dict_or_kwargs(pos_kwargs, kw_kwargs, ...)

is_dict_like(value)

Classes

ERLabDataArrayAccessor(xarray_obj)

Base class for accessors.

ERLabDatasetAccessor(xarray_obj)

Base class for accessors.

InteractiveDataArrayAccessor(xarray_obj)

xarray.DataArray.qshow accessor for interactive visualization.

InteractiveDatasetAccessor(xarray_obj)

xarray.Dataset.qshow accessor for interactive visualization.

PlotAccessor(xarray_obj)

xarray.DataArray.qplot accessor for plotting data.

SelectionAccessor(xarray_obj)

xarray.DataArray.qsel accessor for convenient selection and averaging.

class erlab.accessors.utils.InteractiveDataArrayAccessor(xarray_obj)[source]

Bases: ERLabDataArrayAccessor

xarray.DataArray.qshow accessor for interactive visualization.

__call__(*args, **kwargs)[source]

Visualize the data interactively.

Chooses the appropriate interactive visualization method based on the number of dimensions in the data.

Parameters:
  • *args – Positional arguments passed onto the interactive visualization function.

  • **kwargs – Keyword arguments passed onto the interactive visualization function.

hvplot(*args, **kwargs)[source]

hvplot-based interactive visualization.

Parameters:
  • *args – Positional arguments passed onto DataArray.hvplot().

  • **kwargs – Keyword arguments passed onto DataArray.hvplot().

Raises:

ImportError – If hvplot is not installed.

itool(*args, **kwargs)[source]

Shortcut for itool.

Parameters:
  • *args – Positional arguments passed onto itool.

  • **kwargs – Keyword arguments passed onto itool.

class erlab.accessors.utils.InteractiveDatasetAccessor(xarray_obj)[source]

Bases: ERLabDatasetAccessor

xarray.Dataset.qshow accessor for interactive visualization.

__call__(*args, **kwargs)[source]

Visualize the data interactively.

Chooses the appropriate interactive visualization method based on the data variables.

Parameters:
  • *args – Positional arguments passed onto the interactive visualization function.

  • **kwargs – Keyword arguments passed onto the interactive visualization function.

fit(plot_components=False)[source]

Interactive visualization of fit results.

Parameters:

plot_components (bool) – If True, plot the components of the fit. Default is False. Requires the Dataset to have a modelfit_results variable.

Returns:

A panel containing the interactive visualization.

Return type:

panel.Column

hvplot(*args, **kwargs)[source]

hvplot-based interactive visualization.

Parameters:
  • *args – Positional arguments passed onto Dataset.hvplot().

  • **kwargs – Keyword arguments passed onto Dataset.hvplot().

Raises:

ImportError – If hvplot is not installed.

itool(*args, **kwargs)[source]

Shortcut for itool.

Parameters:
  • *args – Positional arguments passed onto itool.

  • **kwargs – Keyword arguments passed onto itool.

class erlab.accessors.utils.PlotAccessor(xarray_obj)[source]

Bases: ERLabDataArrayAccessor

xarray.DataArray.qplot accessor for plotting data.

__call__(*args, **kwargs)[source]

Plot the data.

If a 2D data array is provided, it is plotted using plot_array. Otherwise, it is equivalent to calling xarray.DataArray.plot().

Parameters:
  • *args – Positional arguments to be passed to the plotting function.

  • **kwargs – Keyword arguments to be passed to the plotting function.

class erlab.accessors.utils.SelectionAccessor(xarray_obj)[source]

Bases: ERLabDataArrayAccessor

xarray.DataArray.qsel accessor for convenient selection and averaging.

__call__(indexers=None, *, verbose=False, **indexers_kwargs)[source]

Select and average data along specified dimensions.

Parameters:
  • indexers (Mapping[Hashable, float | slice] | None) –

    Dictionary specifying the dimensions and their values or slices. Position along a dimension can be specified in three ways:

    • As a scalar value: alpha=-1.2

      If no width is specified, the data is selected along the nearest value. It is equivalent to xarray.DataArray.sel with method='nearest'.

    • As a value and width: alpha=5, alpha_width=0.5

      The data is averaged over a slice of width alpha_width, centered at alpha.

    • As a slice: alpha=slice(-10, 10)

      The data is selected over the specified slice. No averaging is performed.

    One of indexers or indexers_kwargs must be provided.

  • verbose (bool) – If True, print information about the selected data and averaging process. Default is False.

  • **indexers_kwargs – The keyword arguments form of indexers. One of indexers or indexers_kwargs must be provided.

Returns:

The selected and averaged data.

Return type:

xarray.DataArray

Raises:

ValueError – If a specified dimension is not present in the data.