Image#
- class hsi.HSImage#
A generic HS image object.
- __add__(value, /)#
Return self+value.
- __getitem__(key, /)#
Return self[key].
- __mul__(value, /)#
Return self*value.
- __new__(**kwargs)#
- __radd__(value, /)#
Return value+self.
- __repr__()#
Return repr(self).
- __rmul__(value, /)#
Return value*self.
- __rsub__(value, /)#
Return value-self.
- __rtruediv__(value, /)#
Return value/self.
- __sub__(value, /)#
Return self-value.
- __truediv__(value, /)#
Return self/value.
- add(rhs, /)#
Add other image to this image, possibly using broadcasting.
Broadcasting is used for the argument if it is not of the same shape as the base image. Broadcasting uses the ndarray/numpy broadcasting rules.
- apply(func, *args, **kwargs)#
- as_dtype(dtype, /)#
Convert the image to the specified type.
- binning(bin_size, axis, /)#
Perform software binning along the specified axis.
- clip(min, max, /)#
Clamp values to the provided interval.
- Parameters:
min (float) – Minimum value in output.
max (float) – Maximum value in output.
- Returns:
Image where all values are in the interval (min, max).
- Return type:
- div(rhs, /)#
Divide other image with this image, possibly using broadcasting.
Broadcasting is used for the argument if it is not of the same shape as the base image. Broadcasting uses the ndarray/numpy broadcasting rules.
- dot(operand, axis, /)#
Perform matrix-vector or matrix-matrix multiplication between this image and an array.
The multiplication is performed over the specified axis. For example, if we have an LxSxB image multiplied by an MxN matrix on the bands axis, M=B and the result will be an LxSxN image.
If the operand is a vector, the output is always of size 1 along the axis. For example, an LxSxB image multiplied by an M vector over the sample axis produces an Lx1xB result.
- ensure_dtype(dtype)#
Efficiently convert to the target dtype if necessary.
- static from_numpy(array, interleave=Ellipsis, /)#
Create new in-memory image from a NumPy array.
Note that the array memory is always copied. The meaning of each axis is determined by the interleave parameter.
- Parameters:
array (ndarray) – The input array.
interleave (Interleave) – The interleave format to use for the image.
- Returns:
An in-memory image that can be efficiently accessed.
- Return type:
- static from_numpy_with_header(array, header, /)#
Create new in-memory image from a NumPy array and header.
Note that the array memory is always copied. The meaning of each axis is determined by the interleave parameter.
- mean_axis(axis, /)#
Calculate the mean over the specified axis.
- mul(rhs, /)#
Multiply other image with this image, possibly using broadcasting.
Broadcasting is used for the argument if it is not of the same shape as the base image. Broadcasting uses the ndarray/numpy broadcasting rules.
- nan_to_num(num, /)#
Nan to Num
- plane_axis(index, axis)#
Get a single plane along a specified axis.
- Parameters:
int (index) – The index to retrieve.
axis (Axis) – The axis to index along.
- Returns:
A two-dimensional array representing an axis-aligned plane in the data cube.
- Return type:
ndarray
- plane_axis_crop(index, axis, crop)#
Get a single plane along a specified axis with cropping.
Dont use this method. Instead, slice the cube and then use `plane_axis`
- Parameters:
int (index) – The index to retrieve.
axis (Axis) – The axis to index along.
crop (Crop) – Crop info.
- Returns:
A two-dimensional array representing an axis-aligned plane in the data cube.
- Return type:
ndarray
- resolve()#
Resolve the underlying operations to an in-memory representation.
- Returns:
An in-memory image that can be efficiently accessed.
- Return type:
- resolve_iter()#
- select(indices, /)#
Select a spatial subset of spectral samples.
Useful for random samples - not efficient for contiguous access.
- Parameters:
indices (Union[ndarray, list[list], list[tuple]]) – Coordinates to sample in Nx2 format, where N is the number of coordinates. The numbers must be integers.
- Returns:
The samples as a Lx1xB image where L=len(indices) and B is the number of bands in the input image. The output is always flattened in this manner.
- Return type:
- select_mask(mask, /)#
Select a spatial subset of spectral samples using a mask array.
Useful for random samples - not efficient for contiguous access.
- Parameters:
indices (Union[ndarray, list[list], list[tuple]]) – Coordinates to sample in Nx2 format, where N is the number of coordinates. The numbers must be integers.
- Returns:
The samples as a Lx1xB image where L=len(indices) and B is the number of bands in the input image. The output is always flattened in this manner.
- Return type:
- std_axis(axis, /)#
Calculate the standard deviation over the specified axis.
- sub(rhs, /)#
Subtract other image from this image, possibly using broadcasting.
Broadcasting is used for the argument if it is not of the same shape as the base image. Broadcasting uses the ndarray/numpy broadcasting rules.
- sum_axis(axis, /)#
Calculate the sum over the specified axis.
- to_interleave(interleave, block_size=Ellipsis, /)#
Efficiently change the interleave format using buffering.
- Parameters:
interleave (hsi.Interleave) – The target interleave.
- Returns:
A new lazy image with the interleave change operation added.
- Return type:
- to_numpy()#
Convert the image to NumPy.
If the image is defined as a series of calculations, they are naturally resolved when this method is called.
- Returns:
The datacube in the image’s interleave format.
- Return type:
np.ndarray
- to_numpy_with_interleave(interleave)#
Convert the image to NumPy with the specified interleave format.
If the image is defined as a series of calculations, they are naturally resolved when this method is called.
- Parameters:
interleave (Interleave) – Desired interleave format.
- Returns:
The datacube in the specified interleave format.
- Return type:
np.ndarray
- to_numpy_with_permute(interleave)#
Convert the image to NumPy with the specified interleave format without moving the data.
This method is more memory efficient than to_numpy_with_interleave but may lead to less efficient access from NumPy.
If the image is defined as a series of calculations, they are naturally resolved when this method is called.
- Parameters:
interleave (Interleave) – Desired interleave format.
- Returns:
The datacube in the specified interleave format.
- Return type:
np.ndarray
- ufunc(func)#
Apply generic Python function on a plane-by-plane basis.
This method is a very primitive way for Python code to be integrated into the library. The provided function must take a single 2d array as input and return a 2d array as output.
The function must produce the same output size for all inputs of the same size! But it does not have to be the same as the input size. This is because all the returned planes must be able to be stacked into a 3d cube again at some point.
The method is applied by the library on a plane-by-plane basis in the cube. The ordering depends on the interleave, so this means that the function will have to take this into account if it is important. For BSQ files, each plane will be a band, for BIL/BIP, each plane will be a line.
- Parameters:
func (Callable[[ndarray], ndarray]) – A Python function that takes and returns a 2d NumPy array. The size must be the same for all inputs of a specific size.
- var_axis(axis, /)#
Calculate the variance over the specified axis.
- with_header(header, /)#
Attach a new header to the image. This method can be dangerous to use, since the new header isn’t checked for consistency.
- __module__ = 'builtins'#