erlab.interactive.imagetool.slicer¶
Helper functions for fast slicing xarray.DataArray
objects.
Classes
|
Internal class used to slice a |
- class erlab.interactive.imagetool.slicer.ArraySlicer(xarray_obj)[source]¶
Bases:
QObject
Internal class used to slice a
xarray.DataArray
rapidly.Computes binned line and image profiles from multiple cursors. Also handles the data indices and the number of bins for each cursor. Automatic conversion of non-uniform dimensions are also handled here.
- Parameters:
xarray_obj (xr.DataArray) – A
xarray.DataArray
with up to 4 dimensions.- Signals:
sigIndexChanged(int, tuple)
sigBinChanged(int, tuple)
sigCursorCountChanged(int)
sigShapeChanged()
Note
The original intent of this class was a xarray accessor. This is why
ArraySlicer
does not depend on aImageSlicerArea
but rather on the underlyingxarray.DataArray
. Originally, when loading a different array, a different instance ofArraySlicer
had to be created. This was a terrible design choice since it messed up signals every time the instance was replaced. Hence, the behaviour was modified (23/06/19) so that the underlyingxarray.DataArray
ofArraySlicer
could be swapped. As a consequence, each instance ofImageSlicerArea
now corresponds to exactly one instance ofArraySlicer
, regardless of the data. In the future,ArraySlicer
might be changed so that it relies on its one-to-one correspondence withImageSlicerArea
for the signals.- static validate_array(data)[source]¶
Validate a given
xarray.DataArray
.If data has two momentum axes (
kx
andky
), set them (andeV
if exists) as the first two (or three) dimensions. Then, checks the data for non-uniform coordinates, which are converted to indices. Finally, converts the coordinates to C-contiguous float32. If input data values neither float32 nor float64, a conversion to float64 is attempted.- Parameters:
data (xarray.DataArray) – Input array with at least two dimensions.
- Returns:
The converted data.
- Return type:
- values_of_dim(dim)[source]¶
Fast equivalent of
self._obj[dim].values
.Returns the cached pointer of the underlying coordinate array, achieving a ~80x speedup. This should work most of the time since we only assume floating point values, but does require further testing. May break for future versions of
pandas
orxarray
. See Notes.- Parameters:
dim (Hashable) – Name of the dimension to get the values from.
- Return type:
Notes
Looking at the implementation, I think this may return a pandas array in some cases, but I’m not sure so I’ll just leave it this way. When something breaks, replacing with
self._obj._coords[dim]._data.array.array._ndarray
may do the trick.
- property data_vals_T: npt.NDArray[np.floating]¶