ACID_code_v2.utils
All of the utility functions for the ACID package. Some functions may not be useful to the user.
Functions
|
Automated windowing procedure following Sokal (1989) in emcee documentation. |
|
Autocorrelation estimate using FFT from the emcee tutorial. |
|
|
|
|
|
Calculates velocity pixel size |
|
Clips the linelist to only include lines within the wavelength range of the observed spectrum. |
|
Collapses the SN of a 1D or 2D wavelength and sn array to the median of the SNs on the central 2/3 wavelengths. |
Configures the multiprocessing environment variables for optimal performance. |
|
|
Converts a list of move specifications to emcee moves. |
|
Drops any pixels where the wavelength, flux, or error is infinite or <= 0. |
|
|
|
Converts flux, errors, and linelist to optical depth. |
Calculates normalization coefficients for wavelength array |
|
|
Estimates S/N for each frame. |
|
Masks any pixels where the wavelength, flux, or error is infinite or <= 0. |
|
Calculates the next power of 2 greater than or equal to n. |
|
Converts optical depth to flux, errors, and linelist. |
|
Calculates the robust mean of the input data by excluding outliers beyond a specified number of standard deviations from the median. |
|
Sets default values in a dictionary if they are not already present. |
- ACID_code_v2.utils.convert_moves_to_emcee(moves: list[tuple])[source]
Converts a list of move specifications to emcee moves.
- Parameters:
moves (list[tuple], optional) –
A list of tuples specifying the moves for the MCMC sampler. The format tries to follow the emcee documentation as closely as possible. However, the config cannot store classes directly, so move names are used instead and converted when building the sampler.
Each tuple should have the form:
(move_name: str, fraction: float, move_kwargs: dict | None)
where:
”move_name” is the name of the emcee move. Supported variants currently include “RedBlueMove”, “StretchMove”, “WalkMove”, “KDEMove”, “DEMove”, “DESnookerMove”, “MHMove”, and “GaussianMove”. Refer to the emcee documentation for more details on each move type. Input move names are checked against the “emcee.moves” module, so other moves from that module may also work, although not all have been tested with ACID.
”fraction” is the fraction of walkers to which this move should be applied.
”move_kwargs” is an optional dictionary of keyword arguments passed to the move class initialisation.
- Returns:
A list of emcee move objects corresponding to the input specifications.
- Return type:
list
- ACID_code_v2.utils.mask_invalid(wavelengths, flux, errors, return_mask=False, verbose=0)[source]
Masks any pixels where the wavelength, flux, or error is infinite or <= 0. Replaces bad pixels with NaN, which ACID can handle.
- Parameters:
wavelengths (array_like) – The wavelength values of the spectrum.
flux (array_like) – The flux values of the spectrum.
errors (array_like) – The error values associated with the spectrum.
- Returns:
A tuple containing the cleaned wavelength, flux, and error arrays.
- Return type:
tuple
- ACID_code_v2.utils.drop_invalid(wavelengths, flux, errors, return_mask=False, verbose=0)[source]
Drops any pixels where the wavelength, flux, or error is infinite or <= 0.
- Parameters:
wavelengths (array_like) – The wavelength values of the spectrum.
flux (array_like) – The flux values of the spectrum.
errors (array_like) – The error values associated with the spectrum.
- Returns:
A tuple containing the cleaned wavelength, flux, and error arrays.
- Return type:
tuple
- ACID_code_v2.utils.clip_wavelengths(wavelengths, wavelengths_linelist, depths_linelist)[source]
Clips the linelist to only include lines within the wavelength range of the observed spectrum.
- Parameters:
wavelengths (np.ndarray) – Wavelengths of the observed spectrum
wavelengths_linelist (np.ndarray) – Wavelengths from the linelist
depths_linelist (np.ndarray) – Depths from the linelist
- Returns:
wavelengths_linelist (np.ndarray) – Clipped wavelengths from the linelist
depths_linelist (np.ndarray) – Clipped depths from the linelist
- ACID_code_v2.utils.calc_deltav(wavelengths: ACID_code_v2.utils.Array1D) ACID_code_v2.utils.Scalar[source]
Calculates velocity pixel size
Calculates the velocity pixel size for the LSD velocity grid based off the spectral wavelengths.
- Parameters:
wavelengths (np.ndarray) – Wavelengths for Acid input spectrum (in Angstroms), must be a 1D array of positive values.
- Returns:
Velocity pixel size in km/s
- Return type:
float
- ACID_code_v2.utils.guess_SNR(frame_wavelengths: Array1D | Array2D, frame_flux: Array1D | Array2D, frame_errors: Array1D | Array2D) ndarray[source]
Estimates S/N for each frame. Takes the median S/N in the central two-thirds of the wavelength range. Fully vectorized so that all the frames can be passed at once.
- Parameters:
frame_wavelengths (Array1D | Array2D) – Array/list of wavelengths for each frame.
frame_flux (Array1D | Array2D) – Array/list of flux values for each frame.
frame_errors (Array1D | Array2D) – Array/list of error values for each frame.
- Returns:
Array of estimated signal-to-noise ratios for each frame.
- Return type:
np.ndarray
- ACID_code_v2.utils.collapse_SNR(sn, wavelengths)[source]
Collapses the SN of a 1D or 2D wavelength and sn array to the median of the SNs on the central 2/3 wavelengths.
- ACID_code_v2.utils.get_normalisation_coeffs(wl: ACID_code_v2.utils.Array1D) tuple[Scalar, Scalar][source]
Calculates normalization coefficients for wavelength array
- Parameters:
wl (array_like) – Wavelength array for which normalization coefficients are calculated.
- Returns:
A tuple containing the normalization coefficients (a, b).
- Return type:
tuple
- ACID_code_v2.utils.set_dict_defaults(input_dict, default_dict)[source]
Sets default values in a dictionary if they are not already present.
- Parameters:
input_dict (dict | None) – The dictionary to set defaults in (or none if not provided).
default_dict (dict) – The dictionary containing default key-value pairs.
- Returns:
The updated dictionary with defaults set.
- Return type:
dict
- ACID_code_v2.utils.robust_mean(data: ndarray, nsig: int | float = 1, axis: int = 0) ndarray | float[source]
Calculates the robust mean of the input data by excluding outliers beyond a specified number of standard deviations from the median.
- Parameters:
data (np.ndarray) – Input data array.
nsig (int | float, optional) – Number of standard deviations to use for outlier rejection. Defaults to 1.
axis (int, optional) – Axis along which to compute the robust mean. Defaults to 0.
- Returns:
Robust mean of the input data.
- Return type:
float
- ACID_code_v2.utils.flux_to_od(flux=None, errors=None, linelist=None)[source]
Converts flux, errors, and linelist to optical depth.
- Parameters:
flux (np.ndarray) – Input flux array.
errors (np.ndarray, optional) – Input errors array. Defaults to None.
linelist (np.ndarray, optional) – Input linelist array. Defaults to None.
- Returns:
A tuple containing the flux in optical depth, errors in optical depth, and linelist in optical depth. The tuple length depends on which inputs were provided.
- Return type:
tuple
- ACID_code_v2.utils.od_to_flux(od=None, errors=None, linelist=None)[source]
Converts optical depth to flux, errors, and linelist.
- Parameters:
od (np.ndarray) – Input optical depth array.
errors (np.ndarray, optional) – Input errors array. Defaults to None.
linelist (np.ndarray, optional) – Input linelist array. Defaults to None.
- Returns:
A tuple containing the flux, errors, and linelist. The tuple length depends on which inputs were provided.
- Return type:
tuple
- ACID_code_v2.utils.configure_mp_environ(os)[source]
Configures the multiprocessing environment variables for optimal performance.
- Parameters:
os (module) – The os module to use for setting environment variables.
- ACID_code_v2.utils.next_pow_2(n)[source]
Calculates the next power of 2 greater than or equal to n.
- Parameters:
n (int) – Input number. Must be real and non-negative.
- Returns:
The next power of 2 greater than or equal to n.
- Return type:
int
- ACID_code_v2.utils.auto_window(taus: ndarray, c: float = 5.0)[source]
Automated windowing procedure following Sokal (1989) in emcee documentation. Returns the window index to use in taus[window].