6. PCA Subtraction

pcassie.pca_subtraction.convert_range_to_indices(wave, start, end)[source]

Convert a wavelength range to indices.

Parameters:
  • wave (array) – 1d wavelength grid.

  • start (float) – Starting wavelength value you want to crop to.

  • end (float) – Ending wavelength value you want to crop to.

  • Returns

  • --------

  • int – Index of the starting wavelength.

  • int – Index of the ending wavelength.

pcassie.pca_subtraction.preprocess(spectra)[source]

Normalize by the median spectrum, subtract the median at each wavelength, and divide each spectrum by its own standard deviation.

Parameters:

spectra (array) – 2d spectral flux grid.

Returns:

Median subtracted, standard deviation divided 2d spectral flux grid.

Return type:

array

pcassie.pca_subtraction.compute_covariance_matrix(data)[source]

Compute the covariance matrix using NumPy (faster than pandas).

Parameters:

data (array) – 2d spectral array. Used after PCA analysis to the Time Domain or Wavelength Domain.

Returns:

Covariance matrix.

Return type:

array

pcassie.pca_subtraction.explained_variance(eigenvalues)[source]

Calculate explained variance ratio.

Parameters:

eigenvalues (array) – 1d array of eigenvalues.

Returns:

Explained variance value for each eigenvalue.

Return type:

array

pcassie.pca_subtraction.remove_components(data, eigenvectors, first_comps=0, last_comps=0, verbose=False)[source]

Remove specified principal components from the data.

Parameters: data: array

2d flux array.

eigenvectors: array

2d eigenvectors. Refer to pca_subtraction.compute_eigenvalues_and_vectors_jax.

first_comps: int, optional

Index of first components (eigenvectors) to remove.

last_comps: int, optional

Index of last components (eigenvectors) to remove.

verbose: boolean

Refer to utility_functions.debug_print.

Returns:

2d flux array after removing the first_comps and last_comps.

Return type:

array

pcassie.pca_subtraction.pca_subtraction(spectra, start_idx, end_idx, first_comps=0, last_comps=0, eighcalc='numba', pre=False, verbose=False)[source]

Perform PCA subtraction in a wavelength slice from start_idx to end_idx.

Parameters:
  • (np.ndarray) (spectra)

  • (int) (last_comps)

  • (int)

  • (int)

  • (int)

  • (bool) (pre)

  • Returns – (tdm_result, wdm_result): PCA-subtracted arrays.