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 averaging.- __call__(indexers=None, **indexers_kwargs)[source]¶
Select and average 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'.As a value and width:
alpha=5, alpha_width=0.5The data is averaged over a slice of width
alpha_width, centered atalpha. Ifalphais a collection, the data is averaged 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.
- Returns:
DataArray– The selected and averaged 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
- average(dim)[source]¶
Average the data along the specified dimension(s).
The difference between this method and
xarray.DataArray.mean()is that this method averages the data along the specified dimension(s) and retains the averaged coordinate. This method also implicitly averages all coordinates that depend on the averaged dimension(s) instead of dropping them.- Parameters:
dim (
str|Collection[Hashable]) – The dimension(s) along which to average the data.- Returns:
DataArray– The data averaged along the specified dimension(s).- Return type:
- around(radius, *, 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.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.- Return type:
Note
The region is defined by a spherical mask, which is generated with
erlab.analysis.mask.spherical_mask(). Depending on the radius and dimensions provided, the mask will be hyperellipsoid in the dimensions specified insel_kw.See also