pygmi.rsense.transforms#

Transforms such as PCA and MNF.

Classes#

MNF

GUI to perform MNF transform.

PCA

GUI to perform PCA transform.

Functions#

get_noise(x2d, mask[, noisetype, piter])

Calculate noise dataset from original data.

mnf_calc(idat, *[, ncmps, noisetxt, showlog, piter, ...])

MNF Calculation.

pca_calc(idat[, ncmps, showlog, piter, fwdonly])

PCA Calculation.

pca_calc_fitlist(flist[, ncmps, showlog, piter, fwdonly])

PCA Calculation with using list of files in common fit.

blockwise_cov(A)

Blockwise covariance.

blockwise_dot(A, B[, max_elements])

Compute the dot product of two matrices in a block-wise fashion.

standardise_signs(u, vh)

Standardize the signs of U and Vh matrices from SVD.

Module Contents#

class pygmi.rsense.transforms.MNF(parent=None)#

Bases: pygmi.misc.BasicModule

GUI to perform MNF transform.

Parameters:

parent – Reference to the parent routine. The default is None.

setupui()#

Set up UI.

settings(nodialog=False)#

Entry point into item.

Parameters:

nodialog (bool) – Run settings without a dialog. The default is False.

Returns:

True if successful, False otherwise.

Return type:

bool

changeoutput()#

Change the interface to reflect whether full calculation is needed.

saveproj()#

Save project data from class.

acceptall()#

Accept option.

Updates self.outdata, which is used as input to other modules.

Returns:

True if successful, False otherwise.

Return type:

bool

class pygmi.rsense.transforms.PCA(parent=None)#

Bases: pygmi.misc.BasicModule

GUI to perform PCA transform.

Parameters:

parent – Reference to the parent routine. The default is None.

setupui()#

Set up UI.

settings(nodialog=False)#

Entry point into item.

Parameters:

nodialog (bool) – Run settings without a dialog. The default is False.

Returns:

True if successful, False otherwise.

Return type:

bool

changeoutput()#

Change the interface to reflect whether full calculation is needed.

saveproj()#

Save project data from class.

acceptall()#

Accept option.

Updates self.outdata, which is used as input to other modules.

Returns:

True if successful, False otherwise.

Return type:

bool

pygmi.rsense.transforms.get_noise(x2d, mask, noisetype='', piter=iter)#

Calculate noise dataset from original data.

Parameters:
  • x2d (numpy array) – Input array, of dimension (MxNxChannels).

  • mask (numpy array) – mask of dimension (MxN).

  • noisetype (str, optional) – Noise type to calculate. Can be ‘diagonal’, ‘hv average’ or ‘’. The default is ‘’.

  • piter (function, optional) – Iteration function, used for progress bars. The default is iter.

Returns:

W array.

Return type:

ndarray

pygmi.rsense.transforms.mnf_calc(idat, *, ncmps=None, noisetxt='hv average', showlog=print, piter=iter, fwdonly=True)#

MNF Calculation.

Parameters:
  • idat (list[pygmi.raster.datatypes.Data]) – List of PyGMI Data.

  • ncmps (int | None) – Number of components to use for filtering. The default is None (meaning all).

  • noisetxt (str) – Noise type. Can be ‘diagonal’, ‘hv average’ or ‘quad’. The default is ‘hv average’.

  • showlog (collections.abc.Callable[..., None]) – Function for printing text. The default is print.

  • piter (collections.abc.Iterable) – Iteration function, used for progress bars. The default is iter.

  • fwdonly (bool) – Option to perform forward calculation only. The default is True.

Returns:

  • odata (list of Data) – Output list of PyGMI Data. Can be forward or inverse transformed data.

  • ev (ndarray) – Explained variance, from PCA.

Return type:

tuple[list[pygmi.raster.datatypes.Data], numpy.typing.NDArray]

pygmi.rsense.transforms.pca_calc(idat, ncmps=None, showlog=print, piter=iter, fwdonly=True)#

PCA Calculation.

Parameters:
  • idat (list[pygmi.raster.datatypes.Data]) – List of PyGMI Data.

  • ncmps (int | None) – Number of components to use for filtering. The default is None. (meaning all).

  • showlog (collections.abc.Callable[..., None]) – Function for printing text. The default is print.

  • piter (collections.abc.Iterable) – Iteration function, used for progress bars. The default is iter.

  • fwdonly (bool) – Option to perform forward calculation only. The default is True.

Returns:

  • odata (list of Data) – Output list of PyGMI Data. Can be forward or inverse transformed data.

  • ev (ndarray) – Explained variance, from PCA.

Return type:

tuple[list[pygmi.raster.datatypes.Data], numpy.typing.NDArray]

pygmi.rsense.transforms.pca_calc_fitlist(flist, ncmps=None, showlog=print, piter=iter, fwdonly=True)#

PCA Calculation with using list of files in common fit.

Parameters:
  • flist (list[pygmi.raster.datatypes.Data]) – List of PyGMI Data. Can be 2D for multiple files.

  • ncmps (int | None) – Number of components to use for filtering. The default is None (meaning all).

  • showlog (collections.abc.Callable[..., None]) – Function for printing text. The default is print.

  • piter (collections.abc.Iterable) – Iteration function, used for progress bars. The default is iter.

  • fwdonly (bool) – Option to perform forward calculation only. The default is True.

Returns:

  • odata (list of Data) – Output list of PyGMI Data.Can be forward or inverse transformed data.

  • ev (ndarray) – Explained variance, from PCA.

Return type:

tuple[list[pygmi.raster.datatypes.Data], numpy.typing.NDArray]

pygmi.rsense.transforms.blockwise_cov(A)#

Blockwise covariance.

Parameters:

A (numpy.typing.NDArray) – Matrix.

Returns:

Covariance matrix.

Return type:

ndarray

pygmi.rsense.transforms.blockwise_dot(A, B, max_elements=2**27)#

Compute the dot product of two matrices in a block-wise fashion.

Only blocks of A with a maximum size of max_elements will be processed simultaneously.

from : https://stackoverflow.com/questions/20983882/efficient-dot-products-of-large-memory-mapped-arrays

Parameters:
  • A (numpy.typing.NDArray) – MxN matrix.

  • B (numpy.typing.NDArray) – NxO matrix.

  • max_elements (int) – Maximum number of elements in a block. The default is int(2**27).

Returns:

Output dot product.

Return type:

ndarray

pygmi.rsense.transforms.standardise_signs(u, vh)#

Standardize the signs of U and Vh matrices from SVD.

Ensures the largest absolute value in each column of U is positive.

Parameters:
  • u (numpy.typing.NDArray) – U matrix from SVD.

  • vh (numpy.typing.NDArray) – Vh matrix from SVD.

Returns:

  • u_std (ndarray) – Standardized U matrix.

  • vh_std (ndarray) – Standardized Vh matrix.

Return type:

tuple[numpy.typing.NDArray, numpy.typing.NDArray]