ACID_code_v2.LSD
- class ACID_code_v2.LSD(Data: object | None = None)[source]
Class containing all useful functions for performing least-squares deconvolution. This does not simultaneously fit continuum and perform LSD (which ACID does). It is used for the initial parameters of the ACID mcmc run and for obtaining final profiles. It can also be used as a standalone LSD implementation.
Initialises the LSD class, optionally with a Data instance to take parameters from.
- Parameters:
Data (object | None, optional) – A data instance to draw parameters and configs from, by default None
- run_LSD(wavelengths: ACID_code_v2.utils.Array1D, flux: ACID_code_v2.utils.Array1D, errors: ACID_code_v2.utils.Array1D, sn: Scalar | Array1D, linelist=None, velocities: Array1D | None = None, verbose: IntLike | None = None, alpha: Array2D | None = None)[source]
Runs the LSD algorithm to extract the average line profile from the observed spectrum.
- Parameters:
wavelengths (np.ndarray) – Array of wavelengths of the observed spectrum in Angstroms
flux (np.ndarray) – Array of flux values corresponding to the wavelengths (in linear space, and should be continuum normalized)
errors (np.ndarray) – Array of error values corresponding to the flux
sn (float | int) – Signal-to-noise ratio of the observed spectrum
linelist (str | dict, optional) – Path to the linelist file or a dictionary containing ‘wavelengths’ and ‘depths’. If the class was not initialised with an Acid instance, this is required, by default None
velocities (np.ndarray, optional) – Array of velocities corresponding to the observed spectrum. If the class was not initialised with an Acid instance, this is required, by default None
verbose (int | None, optional) – Verbosity level, if None, uses the class default of 2. See the Acid class for more information about verbosity integer levels, by default None
alpha (np.ndarray, optional) – Precomputed alpha matrix, if already calculated and you want to skip directly to the Cholesky decomposition and solving for the profile, by default None
- sn_clip(wavelengths_linelist, depths_linelist, sn)[source]
Applies a signal-to-noise cut to the linelist, removing lines shallower than 1/(3*sn).
- Parameters:
wavelengths_linelist (np.ndarray) – Wavelengths from the linelist
depths_linelist (np.ndarray) – Depths from the linelist
sn (float) – Signal-to-noise ratio threshold
- Returns:
np.ndarray – Clipped wavelengths from the linelist
np.ndarray – Clipped depths from the linelist
- calc_alpha(wavelengths: ACID_code_v2.utils.Array1D, wavelengths_linelist: ACID_code_v2.utils.Array1D, depths_linelist: ACID_code_v2.utils.Array1D, velocities: Array1D | None = None, verbose: IntLike | None = None)[source]
Calculates the alpha matrix given flux and errors in OD space, and a line_list in OD space. Note that if this function is called without using run_LSD, there is no selection of lines deeper than 1/(3*sn). If you still wish to do this, it needs to be done in linear space with the sn_clip function before converting to OD space.
- Parameters:
wavelengths (np.ndarray) – Array of wavelengths of the observed spectrum in optical depth space
wavelengths_linelist (np.ndarray) – Array of wavelengths from the linelist in optical depth space
depths_linelist (np.ndarray) – Array of depths from the linelist in optical depth space
velocities (np.ndarray, optional) – Array of velocities, needs to either be initialised by class with Acid instance, or input here, by default None
verbose (int | None, optional) – Verbosity level, uses the class default of 2 if None, by default None
- static calc_cholesky(alpha: ACID_code_v2.utils.Array2D, error: ACID_code_v2.utils.Array1D, **kwargs)[source]
Calculates the LHS Cholesky factorisation matrix given the alpha matrix and flux errors (in optical depth space)
- Parameters:
alpha (np.ndarray) – The precomputed alpha matrix
error (np.ndarray) – Flux errors in optical depth space
**kwargs (dict, optional) – Additional keyword arguments to pass to scipy.linalg.cho_factor. Overwrite_a=False is already set by default, do not pass this as a kwarg.
- Returns:
c_factor – Cholesky factorisation matrix and lower/upper flag, to be put straight into solve_z as c_factor
- Return type:
tuple
- static solve_z(alpha, flux, error, c_factor, return_error: bool = True, return_cov: bool = False, **kwargs)[source]
Solves for the LSD profile and its errors using the Cholesky factors.
- Parameters:
alpha (np.ndarray) – The precomputed alpha matrix
flux (np.ndarray) – The observed flux values in optical depth space
error (np.ndarray) – The flux errors in optical depth space
c_factor (tuple) – Cholesky factorisation matrix and lower/upper flag, to be put straight into scipy.linalg.cho_solve as c_factor
return_error (bool, optional) – Whether to calculate and return the profile errors along with the profile, by default True
return_cov (bool, optional) – Whether to return the full covariance matrix instead of just the errors, by default False
**kwargs (dict, optional) – Additional keyword arguments to pass to both scipy.linalg.cho_solve calls (one for the profile, one for the covariance matrix) Overwrite_b=False is already set by default, do not pass this as a kwarg.
- Returns:
profile, profile_errors, cov_z – LSD profile and its errors (if return_error is True) and covariance matrix (if return_cov is True)
- Return type:
tuple