pwspy.dataTypes.ICBase

class pwspy.dataTypes.ICBase(data, index, dtype=<class 'numpy.float32'>)[source]

Bases: abc.ABC

A class to handle the data operations common to PWS related image cubes. Does not contain any file specific functionality. uses the generic index attribute which can be overridden by derived classes to be wavelength, wavenumber, time, etc.

Parameters
  • data (np.ndarray) – A 3-dimensional array containing the data the dimensions should be [Y, X, Z] where X and Y are the spatial coordinates of the image and Z corresponds to the index dimension, e.g. wavelength, wavenumber, time, etc.

  • index (tuple(Number)) – A tuple containing the values of the index for the data. This could be a tuple of wavelength values, times (in the case of Dyanmics), etc.

  • dtype (type) – the data type that the data should be stored as. The default is numpy.float32.

classmethod decodeHdf(d)[source]

Load a new instance of ICBase from an h5py.Dataset

Parameters

d (Dataset) – The dataset that the ICBase has been saved to

Returns

(data: The 3D array of data, index: A tuple containing the index)

Return type

A tuple containing

filterDust(sigma, pixelSize)[source]

Blurs the data cube in the X and Y dimensions. Often used to remove the effects of dust on a normalization.

Parameters
  • sigma (float) – This specifies the radius of the gaussian filter used for blurring. The units of the value are determined by pixelSize

  • pixelSize (float) – The pixel size in microns. Settings this to 1 will effectively causes sigma to be in units of pixels rather than microns.

getMeanSpectra(mask=None)[source]

Calculate the average spectra within a region of the data.

Parameters

mask (Union[Roi, ndarray, None]) – An optional other.Roi or boolean numpy array used to select pixels from the X and Y dimensions of the data array. If left as None then the full data array will be used as the region.

Return type

Tuple[ndarray, ndarray]

Returns

The average spectra within the region, the standard deviation of the spectra within the region

plotMean()[source]
Return type

Tuple[Figure, Axes]

Returns

A figure and attached axes plotting the mean of the data along the index axis.

corresponds to the mean reflectance in most cases.

selIndex(start, stop)[source]
Parameters
  • start (Optional[float]) – The beginning value of the index in the new object. Pass None to include everything.

  • stop (Optional[float]) – The ending value of the index in the new object. Pass None to include everything.

Return type

Tuple[ndarray, Sequence]

Returns

A new instance of ICBase with only data from start to stop in the index.

selectLassoROI(displayIndex=None, clim=None)[source]

Allow the user to draw a freehand ROI on an image of the acquisition.

Parameters

displayIndex (Optional[int]) – Display a particular z-slice of the array for mask drawing. If None then the mean along Z is displayed.

Return type

Roi

Returns

An array of vertices of the polygon drawn.

selectRectangleROI(displayIndex=None)[source]

Allow the user to draw a rectangular ROI on an image of the acquisition.

Parameters

displayIndex (int) – is used to display a particular z-slice for mask drawing. If None then the mean along Z is displayed. Returns an array of vertices of the rectangle.

Returns

An array of the 4 XY vertices of the rectangle.

Return type

np.ndarray

toHdfDataset(g, name, fixedPointCompression=True, compression=None)[source]

Save the data of this class to a new HDF dataset.

Parameters
  • g (h5py.Group) – the parent HDF Group of the new dataset.

  • name (str) – the name of the new HDF dataset in group g.

  • fixedPointCompression (bool) – if True then save the data in a special 16bit fixed-point format. Testing has shown that this has a maximum conversion error of 1.4e-3 percent. Saving is ~10% faster but requires only 50% the hard drive space.

  • compression (Optional[str]) – The value of this argument will be passed to h5py.create_dataset for numpy arrays. See h5py documentation for available options.

Returns

This is the the same h5py.Group that was passed in a g. It should now have a new dataset by the name of ‘name’

Return type

h5py.Group

property index: Tuple[float, ...]

Returns: The values of the datacube’s index

Return type

Tuple[float, ...]