erlab.accessors.general¶
Defines miscellaneous accessors for general data manipulation and visualization.
Classes
|
|
|
|
|
|
|
|
|
|
- class erlab.accessors.general.InfoDataArrayAccessor(xarray_obj)[source]¶
Bases:
ERLabDataArrayAccessorxarray.DataArray.qinfoaccessor for displaying information about the data.
- class erlab.accessors.general.InteractiveDataArrayAccessor(xarray_obj)[source]¶
Bases:
ERLabDataArrayAccessorxarray.DataArray.qshowaccessor 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.
- itool(*args, **kwargs)[source]¶
Shortcut for
erlab.interactive.imagetool.itool().
- hvplot(*args, **kwargs)[source]¶
hvplot-based interactive visualization.
This method is a convenience wrapper that handles importing
hvplot.- Parameters:
*args – Positional arguments passed onto
DataArray.hvplot.**kwargs – Keyword arguments passed onto
DataArray.hvplot.
- Raises:
If hvplot is not installed.
- class erlab.accessors.general.InteractiveDatasetAccessor(xarray_obj)[source]¶
Bases:
ERLabDatasetAccessorxarray.Dataset.qshowaccessor 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.
- itool(*args, **kwargs)[source]¶
Shortcut for
erlab.interactive.imagetool.itool().
- hvplot(*args, **kwargs)[source]¶
hvplot-based interactive visualization.
This method is a convenience wrapper that handles importing
hvplot.- Parameters:
*args – Positional arguments passed onto
Dataset.hvplot.**kwargs – Keyword arguments passed onto
Dataset.hvplot.
- Raises:
If hvplot is not installed.
- fit(plot_components=False, data_var=None)[source]¶
Interactive visualization of fit results.
- Parameters:
plot_components (
bool, default:False) – IfTrue, plot the components of the fit. Default isFalse. Requires the Dataset to have amodelfit_resultsvariable.data_var (
str|None, default:None) – The name of the data variable to visualize. Required only if the Dataset contains fits across multiple data variables.
- Returns:
panel.layout.Column– A panel containing the interactive visualization.
- class erlab.accessors.general.PlotAccessor(xarray_obj)[source]¶
Bases:
ERLabDataArrayAccessorxarray.DataArray.qplotaccessor for plotting data.- __call__(*args, **kwargs)[source]¶
Plot the data.
Plots two-dimensional data using
plot_array. For non-two-dimensional data, the method falls back toxarray.DataArray.plot().Also sets fancy labels using
fancy_labels.- Parameters:
*args – Positional arguments to be passed to the plotting function.
**kwargs – Keyword arguments to be passed to the plotting function.
- class erlab.accessors.general.SelectionAccessor(xarray_obj)[source]¶
Bases:
ERLabDataArrayAccessorxarray.DataArray.qselaccessor for convenient selection and aggregation.- __call__(indexers=None, *, func='mean', **indexers_kwargs)[source]¶
Select and aggregate data along specified dimensions.
- Parameters:
indexers (
Mapping[Hashable,float|slice] |None, default:None) –Dictionary specifying the dimensions and their values or slices. Position along a dimension can be specified in three ways:
As a scalar value or a collection of scalar values:
alpha=-1.2oralpha=[-1.2, 0.0, 1.2]:If no width is specified, the data is selected along the nearest value for each element. It is equivalent to calling
xarray.DataArray.sel()withmethod='nearest'. When a collection is provided, multiple selections are made and concatenated along the dimension. In this case, the width may also be provided as a collection with the same length.As a value and width:
alpha=5, alpha_width=0.5The data is aggregated over a slice of width
alpha_width, centered atalpha. Ifalphais a collection, the data is aggregated over multiple slices and concatenated along the dimension.As a slice:
alpha=slice(-10, 10)The data is selected over the specified slice. No averaging is performed. This is equivalent to calling
xarray.DataArray.sel()with a slice.
One of
indexersorindexers_kwargsmust be provided.**indexers_kwargs – The keyword arguments form of
indexers. One ofindexersorindexers_kwargsmust be provided.func (
{"mean", "min", "max", "sum"}, optional) – Function used when qsel aggregates over width-based selections. Must be one of"mean","min","max", or"sum"."mean"by default. This argument only affects reduced data; reduced numeric coordinates are still represented by their mean.
- Returns:
DataArray– The selected and aggregated data.
Note
Unlike
xarray.DataArray.sel(), this method treats all dimensions without coordinates as equivalent to having coordinates assigned from 0 ton-1, wherenis the size of the dimension. For example:da = xr.DataArray(np.random.rand(10), dims=("x",)) da.sel(x=slice(2, 3)) # This works da.sel(x=slice(2.0, 3.0)) # This raises a TypeError da.qsel(x=slice(2.0, 3.0)) # This works
- mean(dim=None)[source]¶
Return the mean over dimensions while keeping their coordinates.
Dimensions removed from the data are retained as scalar coordinates with the mean of their coordinate values. Numeric coordinates that depend on reduced dimensions are averaged as well.
- min(dim=None)[source]¶
Return the minimum over dimensions while keeping their coordinates.
Data values are reduced with
xarray.DataArray.min(). Dimensions removed from the data are retained as scalar coordinates with the mean of their coordinate values. Numeric coordinates that depend on reduced dimensions are averaged as well.
- max(dim=None)[source]¶
Return the maximum over dimensions while keeping their coordinates.
Data values are reduced with
xarray.DataArray.max(). Dimensions removed from the data are retained as scalar coordinates with the mean of their coordinate values. Numeric coordinates that depend on reduced dimensions are averaged as well.
- sum(dim=None)[source]¶
Return the sum over dimensions while keeping their coordinates.
Data values are reduced with
xarray.DataArray.sum(). Dimensions removed from the data are retained as scalar coordinates with the mean of their coordinate values. Numeric coordinates that depend on reduced dimensions are averaged as well.
- around(radius, *, boundary=True, invert=False, drop=False, average=True, **sel_kw)[source]¶
Average data within a specified radius of a specified point.
For instance, consider an ARPES map with dimensions
'kx','ky', and'eV'. Providing'kx'and'ky'points will average the data within a cylindrical region centered at that point. The radius of the cylinder is specified byradius.If different radii are given for
kxandky, the region will be elliptic.- Parameters:
radius (
float|dict[Hashable,float]) – The radius of the region. If a single number, the same radius is used for all dimensions. If a dictionary, keys must be valid dimension names and the values are the radii for the corresponding dimensions.boundary (
bool, default:True) – Whether to consider points on the boundary to be inside the mask. Default isTrue.invert (
bool, default:False) – IfTrue, invert the mask so that points inside are masked and points outside are kept. This is applied after the mask is created.drop (
bool, default:False) – IfTrue, drop coordinate labels along dims for which all values are masked. This argument is ignored ifaverage=True.average (
bool, default:True) – IfTrue, return the mean value of the data within the region. IfFalse, return the masked data.**sel_kw – The center of the spherical region. Must be a mapping of valid dimension names to coordinate values.
- Returns:
DataArray– The mean value of the data within the region ifaverage=True, else the masked data.- Return type:
Note
Depending on the radius and dimensions provided, the mask will be hyperellipsoid in the dimensions specified in
sel_kw.