PCA Projection

Authors

John Weaver <john.weaver.astro@gmail.com>

About

Robust Principal Component Analysis projection, and tools

Based on IDL implementation by Vivienne Wild

References

[1] Connolly & Szalay (1999, AJ, 117, 2052) http://www.journals.uchicago.edu/AJ/journal/issues/v117n5/980466/980466.html [2] Lemson, “Normalized gappy PCA projection”

Known Issues

None

pygappy.pca_projection.eigenbasis(verbose=False)[source]

Returns wavelengths, eigenspectra, mean spectrum, and variance for Wild+07 PCA eigensystem.

Parameters:verbose (bool, optional) – Enable for status and debug messages. Default is ‘’False’‘.
Returns:
  • wave (ndarray) – Wavelength array of ‘float’ type.
  • spec (ndarray) – 2D array of eiegenspectra.
  • mean (ndarray) – Mean spectrum array.
  • var (ndarray) – Variance array corresponding to the mean spectrum.
pygappy.pca_projection.gappy(data, error, espec, mean, cov=None, reconstruct=False, verbose=False)[source]

Performs robust PCA projection.

Parameters:
  • data (ndarray) – 1D spectrum or 2D specta with ‘float’ type.
  • error (ndarray) – 1D or 2D corresponding 1-sigma error array. Zeros indicate masked data.
  • espec (ndarray) – 2D array of eigenspectra, possibly truncated in dimension.
  • mean (ndarray) – 1D mean spectrum of the eigenspectra.
  • cov (bool, optional) – Return covariance matrix. Default is ‘’False’‘.
  • reconstruct (bool, optional) – Fill in missing values with PCA estimation. Default is ‘’False’‘.
  • verbose (bool, optional) – Enable for status and debug messages. Default is ‘’False’‘
Returns:

  • pcs (ndrray) – 1D or 2D array of Principal Components with ‘float’ type.
  • data (ndrray) – If reconstruct enabled, 1D or 2D reconstructed spectra.
  • ccov (ndarray) – If cov enabled, 2D or 3D covariance matrices.

pygappy.pca_projection.get_class(pcs, logmass=1.0)[source]

Classifies location in PC Plane.

Parameters:
  • pcs (float or np.ndarray) – List of PC1/2 values of type float.
  • logmass (float, optional) – Log10 stellar mass, used to select suitable region patches. Default is ‘1.’, for low-mass.
Returns:

output – Classes for input pc sets.

Return type:

float or ndarray

pygappy.pca_projection.mc_errors(data, error, espec, emean, Ntrials=100, verbose=False)[source]

Performs Monte-Carlo error estimation assuming a normal distribution. The formal 1-sigma errors from the (norm)gappy cov matrix should match.

Parameters:
  • data (ndarray) – 1D spectrum or 2D specta with ‘float’ type.
  • error (ndarray) – 1D or 2D corresponding 1-sigma error array. Zeros indicate masked data.
  • espec (ndarray) – 2D array of eigenspectra, possibly truncated in dimension.
  • mean (ndarray) – 1D mean spectrum of the eigenspectra.
  • Ntrials (int, optional) – Number of trials to perform Default is 100.
  • verbose (bool, optional) – Enable for status and debug messages. Default is ‘’False’‘
Returns:

pc_errors – 1D array of Principal Component errors with ‘float’ type.

Return type:

ndrray

pygappy.pca_projection.normgappy(data, error, espec, mean, cov=False, reconstruct=False, verbose=False)[source]

Performs robust PCA projection, including normalization estimation.

Parameters:
  • data (ndarray) – 1D spectrum or 2D specta with ‘float’ type.
  • error (ndarray) – 1D or 2D corresponding 1-sigma error array. Zeros indicate masked data.
  • espec (ndarray) – 2D array of eigenspectra, possibly truncated in dimension.
  • mean (ndarray) – 1D mean spectrum of the eigenspectra.
  • cov (bool, optional) – Return covariance matrix. Default is ‘’False’‘.
  • reconstruct (bool, optional) – Fill in missing values with PCA estimation. Default is ‘’False’‘.
  • verbose (bool, optional) – Enable for status and debug messages. Default is ‘’False’‘
Returns:

  • pcs (ndrray) – 1D or 2D array of Principal Components with ‘float’ type.
  • norm (float or ndarray) – Normalization estimates.
  • data (ndrray) – If reconstruct enabled, 1D or 2D reconstructed spectra.
  • ccov (ndarray) – If cov enabled, 2D or 3D covariance matrices.