Dataset: Reference

Stores data in a custom class and generates attributes for other modules

class hypers._process.Dataset(data)

Dataset data structure

Attributes:
data: np.ndarray

The raw hyperspectral data

shape: tuple

Shape of the hyperspectral data

ndim: int

Number of dimensions of the data (3 or 4)

n_features: int

Number of spectral bands

n_samples: int

Total number of pixels

mean_spectrum: np.ndarray

An array of the mean spectrum of the data

mean_image: np.ndarray

An array of the mean image of the data

image: np.ndarray

An array of the image averaged over the specified spectral bands

spectrum: np.ndarray

An array of the spectrum averaged over the specified pixels

smoothing: str

Smoothing to use. Can be either:

  • savitzky_golay
  • gaussian

Default is ‘savitzky_golay’.

Methods

abundance(spectra[, plot, return_arrs]) Abundance map with least-squares fitting
cluster(mdl[, decomposed, pca_comps, plot, …]) Cluster data
decompose(mdl[, plot, return_arrs]) Decompose data
flatten() Returns flattened array
mixture(mdl[, plot, return_arrs]) Gaussian mixture models
normalize([norm]) Normalize the hyperspectral data
preprocess(mdl) Preprocess data
robust_scale([with_centering, with_scaling, …]) Standardize the hyperspectral data (robust from outliers)
scale([with_mean, with_std]) Standardize the hyperspectral data
scree([plot, return_arrs]) Returns PCA scree
smoothen(**kwargs) Smoothen the hyperspectral data
update() Update the stored data and class properties
vca([n_components, plot, return_arrs]) Vertex component analysis
view() Open the hyperspectral viewer GUI
abundance(spectra, plot=False, return_arrs=True)

Abundance map with least-squares fitting

Parameters:
spectra: np.ndarray

Spectra to perform fitting with

plot: bool

If True, will return an image of the abundance map

return_arrs: bool

If True, will return an array of the abundance map

Returns:
im: np.ndarray

An array of the abundance map

Return type:ndarray
cluster(mdl, decomposed=False, pca_comps=4, plot=False, return_arrs=True)

Cluster data

Parameters:
mdl: ClusterType

Accepts a scikit-learn cluster class

decomposed: bool

Whether to perform PCA on the data prior to clustering

pca_comps: int

If decomposed=True, this specifies the number of principal components to use

plot: bool

If True, will return a plot of the labels/spectra of the clusters

return_arrs: bool

If True, will return the arrays of the labels/spectra of the clusters

Returns:
ims: np.ndarray

An array of the labels (size: x, y, (z))

specs: np.ndarray

An array of spectra (size: spectra, n_clusters)

Return type:Tuple[ndarray, ndarray]
decompose(mdl, plot=False, return_arrs=True)

Decompose data

Parameters:
mdl: DecomposeType

Accepts a scikit-learn decomposition class

plot: bool

If True, will return a plot of the images/spectra of the components

return_arrs: bool

If True, will return the arrays of the images/spectra

Returns:
ims: np.ndarray

An array of images (size: x, y, (z), n_components)

specs: np.ndarray

An array of spectra (size: spectra, n_components)

Return type:Tuple[ndarray, ndarray]
flatten()

Returns flattened array

Returns:
x_flat: np.ndarray

Flattened 2d array of the stored hyperspectral data

Return type:ndarray
mixture(mdl, plot=False, return_arrs=True)

Gaussian mixture models

Parameters:
mdl: MixtureType

Accepts a scikit-learn mixture class

plot: bool

If True, will return a plot of the labels/spectra of the components

return_arrs: bool

If True, will return the arrays of the labels/spectra of the components

Returns:
labels: np.ndarray

An array of the labels

spectra: np.ndarray

An array of the spectra of the components

Return type:Tuple[ndarray, ndarray]
normalize(norm='l2')

Normalize the hyperspectral data

Parameters:
norm: str (‘l1’, ‘l2’, ‘max’)

The norm to use to normalize each spectrum.

Return type:None
preprocess(mdl)

Preprocess data

Parameters:
mdl: PreprocessType

Accepts a scikit-learn preprocessing class

Return type:None
robust_scale(with_centering=True, with_scaling=True, quantile_range=(25.0, 75.0))

Standardize the hyperspectral data (robust from outliers)

Parameters:
with_centering: bool

If True, center the data before scaling

with_scaling: bool

If True, scale the data to unit variance

quantile_range: tuple

Quantile range used.

Return type:None
scale(with_mean=True, with_std=True)

Standardize the hyperspectral data

Parameters:
with_mean: bool

If True, center the data before scaling

with_std: bool

If True, scale the data to unit variance

Return type:None
scree(plot=False, return_arrs=True)

Returns PCA scree

Parameters:
plot: bool

If True, will plot the array

return_arrs: bool

If True, will return the array

Returns:
scree: np.ndarray

An array of the PCA scree

Return type:ndarray
smoothen(**kwargs)

Smoothen the hyperspectral data

Parameters:
**kwargs

Keyword arguments for either of the following (depending on what the smoothing attribute has been set to):

  • scipy.signal.savgol_filter
  • scipy.ndimage.filters.gaussian_filter
Return type:None
update()

Update the stored data and class properties

Return type:None
vca(n_components=4, plot=False, return_arrs=True)

Vertex component analysis

Parameters:
n_components: int

Number of pure components to find

plot: bool

If True, will return a plot of the pure spectra

return_arrs: bool

If True, will return an array of the pure spectra and a list of tuples of the coordinates of the pure pixels

Returns:
spectra: np.ndarray

An array of the spectra of the pure pixels

coords: np.ndarray

A list of tuples of the coordinates of the pure pixels

Return type:Tuple[ndarray, List[int]]
view()

Open the hyperspectral viewer GUI

Return type:None