crikit.preprocess package

Submodules

crikit.preprocess.crop module

Created on Tue Jun 21 14:28:49 2016

@author: chc

class crikit.preprocess.crop.ZeroColumn(first_or_last=0, zero_col=None)[source]

Bases: object

Set first or last column that is not all 0’s to 0.

Parameters
  • first_or_last (int, optional (default = 0 [first])) – Find first (= 0) or last (= -1)

  • zero_col (int, optional (default = None)) – Zero a specified column

_calc(data, ret_obj)[source]
calculate(data)[source]
transform(data)[source]
class crikit.preprocess.crop.ZeroRow(first_or_last=0, zero_row=None)[source]

Bases: object

Set first or last row that is not all 0’s to 0.

Parameters
  • first_or_last (int, optional (default = 0 [first])) – Find first (= 0) or last (= -1)

  • zero_row (int, optional (default = None)) – Zero a specified row

_calc(data, ret_obj)[source]
calculate(data)[source]
transform(data)[source]

crikit.preprocess.denoise module

Denoising

Created on Fri Apr 22 23:55:22 2016

@author: chc

class crikit.preprocess.denoise.SVDDecompose(rng=None)[source]

Bases: object

Compute the SVD of a signal (just wraps numpy.linalg.svd) i.e., decompose the input into components.

Parameters
  • data (ndarray (2D or 3D)) – Input array.

  • rng (ndarray (1D), optional) – Range of pixels to perform operation over.

Returns

U, s, Vh

Return type

ndarray, ndarray, ndarray

Notes

Undarray (2D)

U-component from SVD decomposition (spatial componenet with crikit)

Vhndarray (2D)

Vh-component from SVD decomposition (spectral componenet with crikit). NOTE: this is the Hermitial/conjugate transpose of the normal V-component in SVD

sndarray (1D)

Diagonal elements of S-matrix describing the relative contributions of each singular value

Sndarray (2D)

S-matrix derived from s

References

_calc(data, ret_obj)[source]

Calculate SVD (wrap numpy SVD).

calculate(data)[source]

Calculate SVD and return U, s, and Vh.

class crikit.preprocess.denoise.SVDRecompose(rng=None)[source]

Bases: object

Reconstruct the original data using the SVD components. The reconstructed signal shape is 2D (or if provided) or matches data_obj.

Parameters
  • U (ndarray (2D)) – U-component from SVD decomposition (spatial componenet with crikit)

  • s (ndarray (1D)) – Diagonal elements of S-matrix describing the relative contributions of each singular value

  • Vh (ndarray (2D)) – Vh-component from SVD decomposition (spectral componenet with crikit). NOTE: this is the Hermitial/conjugate transpose of the normal V-component in SVD

  • data (ndarray (2D or 3D)) – Original data (for overwrite if selected).

  • rng (ndarray (1D), optional) – Range of pixels to perform operation over.

  • overwrite (bool, optional (default=True)) – Overwrite the original data in data_obj

Returns

  • ndarray (2D or 3D) – Recomposed data (U*S*Vh). If data_obj is not None, returned object shape matches data_obj. Else 2D.

  • None – Returns None if overwrite is True and overwrites input data_obj.

Notes

Sndarray (2D)

S-matrix derived from s

References

_calc(U, s, Vh, ret_obj)[source]

Perform data reconstruction from U*S*Vh with selected s-values.

_set_s_keep(s, svs)[source]

Set the singular value vector (s_keep) based on svs list/ndarray

calculate(data, U, s, Vh, svs=None)[source]
transform(data, U, s, Vh, svs=None)[source]

crikit.preprocess.standardize module

Standardization

Created on Thu Apr 14 08:53:08 2016

@author: chc

class crikit.preprocess.standardize.Anscombe(gauss_std, gauss_mean=0.0, poisson_multi=1.0, rng=None)[source]

Bases: object

Implement the generalized forward Anscombe transformation.

Signal : \(X\)

Mean of Gaussian noise : \(<g>\)

Standard deviation of Gaussian noise : \(\sigma_g\)

Noise of type ‘type’ : \(N_{type}\)

Poisson noise multiplier : \(\alpha\)

Model : \(X = \alpha*N_{Poisson}\{X\} + N_{Gauss}\{<g>, \sigma_g\},\)

Parameters
  • data (ndarray.) – Signal with mixed Gaussian and Poisson noise to transform.

  • gauss_std (float) – Standard deviation of Gaussian noise. \(\sigma_g\) in model.

  • poisson_multi (float, optional (default=1.0)) – A multiplier that scales the effect of the Poisson noise. \(\alpha\) in model.

  • gauss_mean (float, optional (default=0.0)) – Mean Gaussian noise level. \(<g>\) in model.

  • rng (ndarray (1D), optional) – Range of pixels to perform operation over.

  • overwrite (bool, optional (default=True)) –

Returns

  • ndarray – Altered data if overwrite is False

  • None – Return None if overwrite is True

See also

  • See the docstring of ./algorithms/anscombe for more information.

References

[1] M. Mäkitalo and A. Foi, “Optimal inversion of the generalized Anscombe transformation for Poisson-Gaussian noise”, IEEE Trans. Image Process., doi:10.1109/TIP.2012.2202675

[2] J.L. Starck, F. Murtagh, and A. Bijaoui, Image Processing and Data Analysis, Cambridge University Press, Cambridge, 1998)

[3] C. H. Camp Jr, Y. J. Lee, and M. T. Cicerone, “Quantitative, comparable coherent anti-Stokes Raman scattering (CARS) spectroscopy: Correcting errors in phase retrieval,” Journal of Raman Spectroscopy 47, 408-415 (2016). arXiv:1507.06543.

_calc(data, ret_obj)[source]
calculate(data)[source]

Generalized Anscombe transform (Return copy).

Parameters

data (ndarray) – Input data.

Returns

Returns Anscombe-transformed data (or None if fails)

Return type

ndarray

transform(data)[source]

Generalized Anscombe transform (Overwrite data).

Parameters

data (ndarray) – Input data.

Returns

Returns the success state (True=success)

Return type

bool

class crikit.preprocess.standardize.AnscombeInverse(gauss_std, gauss_mean=0.0, poisson_multi=1.0, rng=None)[source]

Bases: object

Applies an exact, unbiased inverse of the generalized Anscombe variance-stabilizing transformation assuming a mixed Poisson-Gaussian noise model as:

Signal : \(X\)

Mean of Gaussian noise : \(<g>\)

Standard deviation of Gaussian noise : \(\sigma_g\)

Noise of type ‘type’ : \(N_{type}\)

Poisson noise multiplier : \(\alpha\)

Model : \(X = \alpha*N_{Poisson}\{X\} + N_{Gauss}\{<g>, \sigma_g\},\)

Parameters
  • data (Spectrum (or subclass) object or ndarray.) – Signal with mixed Gaussian and Poisson noise to transform.

  • gauss_std (float) – Standard deviation of Gaussian noise. \(\sigma_g\) in model.

  • poisson_multi (float, optional (default=1.0)) – A multiplier that scales the effect of the Poisson noise. \(\alpha\) in model.

  • gauss_mean (float, optional (default=0.0)) – Mean Gaussian noise level. \(<g>\) in model.

  • rng (ndarray (1D), optional) – Range of pixels to perform operation over.

  • overwrite (bool, optional (default=True)) –

See also

  • See the docstring of ./algorithms/anscombe for more information.

References

[1] M. Mäkitalo and A. Foi, “Optimal inversion of the generalized Anscombe transformation for Poisson-Gaussian noise”, IEEE Trans. Image Process., doi:10.1109/TIP.2012.2202675

[2] J.L. Starck, F. Murtagh, and A. Bijaoui, Image Processing and Data Analysis, Cambridge University Press, Cambridge, 1998)

[3] C. H. Camp Jr, Y. J. Lee, and M. T. Cicerone, “Quantitative, comparable coherent anti-Stokes Raman scattering (CARS) spectroscopy: Correcting errors in phase retrieval,” Journal of Raman Spectroscopy 47, 408-415 (2016). arXiv:1507.06543.

_calc(data, ret_obj)[source]
calculate(data)[source]

Generalized Inverse Anscombe transform (Return copy).

Parameters

data (ndarray) – Input data.

Returns

Returns Anscombe-transformed data (or None if fails)

Return type

ndarray

transform(data)[source]

Generalized Inverse Anscombe transform (Overwrite data).

Parameters

data (ndarray) – Input data.

Returns

Returns the success state (True=success)

Return type

bool

crikit.preprocess.subtract_baseline module

Subtract baseline

Created on Sat May 28 00:41:41 2016

@author: chc

class crikit.preprocess.subtract_baseline.SubtractBaselineALS(smoothness_param=1, asym_param=0.01, redux=10, order=2, rng=None, fix_end_points=False, fix_rng=None, fix_const=1, max_iter=100, min_diff=1e-05, use_imag=True, **kwargs)[source]

Bases: object

Subtract baseline using asymmetric least squares algorithm

Parameters
  • smoothness_param (float, optional (default=1.0)) – Smoothness parameter aka ‘lambda’

  • asym_param (float, optional (default=1e-2)) – Asymmetry parameter aka ‘p’

  • redux_factor (int, optional (default=10)) – Down-sampling factor (more down-sampling leads to faster detrending, but with more chance of non-optimal detrending)

  • rng (ndarray (1D), optional (default=None)) – Range in pixels to perform action over

  • use_imag (bool, optional (default=True)) – If spectrum(a) are complex-values, use the imaginary portion?

_calc(data, ret_obj, **kwargs)[source]
calculate(data, **kwargs)[source]
transform(data, **kwargs)[source]

crikit.preprocess.subtract_dark module

Subtract mean value (optionally, over a range from all spectrum/spectra/hsi)

Note: If dark > 1D, averaged – even if data has same shape.

class crikit.preprocess.subtract_dark.SubtractDark(dark)[source]

Bases: object

_calc(data, ret_obj)[source]
calculate(data)[source]

Subtract dark spectrum (return copy).

Parameters

data (ndarray) – Data from which dark is subtracted.

Returns

Returns data with dark subtracted (or None if fails)

Return type

ndarray

transform(data)[source]

Subtract dark spectrum (overwrite original data).

Parameters

data (ndarray) – Data from which dark is subtracted.

Returns

Returns the success state (True=success)

Return type

bool

crikit.preprocess.subtract_mean module

Subtract mean value (optionally, over a range from all spectrum/spectra/hsi)

Created on Thu May 26 14:31:39 2016

@author: chc

class crikit.preprocess.subtract_mean.SubtractMeanOverRange(rng=None)[source]

Bases: object

_calc(data, ret_obj)[source]
calculate(data)[source]

Subtract the mean intensity over a pixel range (rng). (Return copy).

Parameters

data (ndarray) – Input data.

Returns

Returns data with mean subtracted (or None if fails)

Return type

ndarray

transform(data)[source]

Subtract the mean intensity over a pixel range (rng). (Overwrite data).

Parameters

data (ndarray) – Input data.

Returns

Returns the success state (True=success)

Return type

bool

Module contents