ACID_code.Data

class ACID_code.Data(wavelengths: Dict[str, ~numpy.ndarray]=<factory>, flux: Dict[str, ~numpy.ndarray]=<factory>, errors: Dict[str, ~numpy.ndarray]=<factory>, sn: Dict[str, ~numpy.ndarray]=<factory>, alpha: Dict[str, ~numpy.ndarray]=<factory>, forward_x: Dict[str, ~numpy.ndarray]=<factory>, forward_y: Dict[str, ~numpy.ndarray]=<factory>, forward_yerr: Dict[str, ~numpy.ndarray]=<factory>, c_factor: Dict[str, tuple]=<factory>, profile: Dict[str, list]=<factory>, continuum: Dict[str, ~numpy.ndarray]=<factory>, poly_inputs: Dict[str, ~numpy.ndarray]=<factory>, nanmask: ndarray | None = None, line_mask: ndarray | None = None, sigma_mask: ndarray | None = None, pix_mask: ndarray | None = None, full_mask: ndarray | None = None, initial_state: ndarray | None = None, nwalkers: int | None = None, ndim: int | None = None, profiles: list | None = None, nsteps: int | None = 0, complete: bool = False, plotting_variables: Dict[str, ~typing.Any]=<factory>, setup_time: float | None = 0, mcmc_time: float | None = 0, results_time: float | None = 0, total_time: float | None = 0, exception: Exception | None = None, traceback: str | None = None, _sampler: EnsembleSampler | None = None, _config: Config = <factory>, _linelist: Dict[str, ~numpy.ndarray] | None=None, _velocities: ndarray | None = None)[source]

Stores necessary data for the Acid class which can be conveniently updated and saved. Allows ACID to handle data that has already been computed to avoid recalculation. This class is designed to be lightweight in memory and hence does not store the sampler as an object. This is handled in the Result class. Note that a Data class should only hold the data for ONE order or observation, but it can hold the data for multiple frames of the same order.

wavelengths: Dict[str, ndarray]

The wavelengths for each frame, stored as a dictionary with frame names as keys and 1D numpy arrays as values.

flux: Dict[str, ndarray]

The fluxes for each frame, stored as a dictionary with frame names as keys and 1D numpy arrays as values.

errors: Dict[str, ndarray]

The errors for each frame, stored as a dictionary with frame names as keys and 1D numpy arrays as values.

sn: Dict[str, ndarray]

The signal-to-noise ratio for each frame, stored as a dictionary with frame names as keys and 1D numpy arrays as values.

alpha: Dict[str, ndarray]

The alpha vector used in the linear model, used for solving the linear system in MCMC

forward_x: Dict[str, ndarray]

The forward model x-axis for each frame, used for solving the linear system in MCMC

forward_y: Dict[str, ndarray]

The forward model y-axis for each frame, used for solving the linear system in MCMC

forward_yerr: Dict[str, ndarray]

The forward model errors for each frame, used for solving the linear system in MCMC

c_factor: Dict[str, tuple]

Tuple generated by np.cho_factor, used for solving the linear system in MCMC - paired with alpha_fitting

profile: Dict[str, list]

The profile for each frame, used for solving the linear system in MCMC idx 0 is the profile, 1 is the errors, and 2 is the cov. matrix

continuum: Dict[str, ndarray]

Continuum model for each frame, used for solving the linear system in MCMC

poly_inputs: Dict[str, ndarray]

Polynomial inputs for just the above continuum (above made using np.polynomal.polyval)

nanmask: ndarray | None

Boolean 1D mask on “initial” grid, used to mask out NaN/invalid values to go from initial to the combined spectra

line_mask: ndarray | None

Boolean 1D mask on “combined” grid, obtained from the MaskingLines class

sigma_mask: ndarray | None

Boolean 1D mask on “combined” grid, used for masking out pixels with high residuals in the residual masking step

pix_mask: ndarray | None

Boolean 1D mask on “combined” grid, used for masking out pixels in the initial pixel masking step based on high SN or low SN

full_mask: ndarray | None

Boolean 1D mask on “combined” grid, that is just a combination of the three above masks

initial_state: ndarray | None

The initial state of the MCMC walkers, used for resuming and debugging

ab = None
nwalkers: int | None

The number of walkers and dimensions for the MCMC sampler, used for reshaping the samples if resuming

ndim: int | None

The number of dimensions for the MCMC sampler, used for reshaping the samples if resuming

profiles: list | None

Same as the profile and profile errors above, but for all inputted frames and for only the final result. 0 returns the same as profile[“final”] for first frame

nsteps: int | None

The number of steps taken in the MCMC sampling, used for checking convergence and for resuming

complete: bool

A flag for whether the profiles have been fully calculated to avoid recalculating

plotting_variables: Dict[str, Any]

Internal variables used for plotting the continuum_fit and the residual masks

setup_time: float | None

setup_time (float) - The time taken for initialization

mcmc_time: float | None

mcmc_time (float) - The time taken for MCMC sampling

results_time: float | None

results_time (float) - The time taken to get the final profiles

total_time: float | None

total_time (float) - The total time for the full run

exception: Exception | None

The exception class if an error was raised during the run

traceback: str | None

The traceback string if an error was raised during the run

property sampler: EnsembleSampler | None

The ensemble sampler object used for MCMC sampling. This is stored as a class variable but when saved, only the path to the sampler is stored to avoid pickling issues.

property velocities: TypeAliasForwardRef('ACID_code.Array1D') | None

The velocity grid to perform LSD on.

property linelist: LineList | None

Returns the internally stored linelist. It has keys “wavelengths” and “depths” or index 0 and 1.

plot_linelist(min_depth: ACID_code.Scalar = 0.2, bounds: tuple | list | None = None, return_fig: bool = False) None | tuple[source]

Plots the linelist points with their corresponding depths as delta-function lines.

Parameters:
  • min_depth (Scalar, optional) – The minimum depth for plotting the linelist points. By default 0.2.

  • bounds (tuple or list, optional) – The wavelength bounds for clipping the linelist. If None, no clipping is applied.

  • return_fig (bool, optional) – If True, returns the figure and axis objects instead of displaying the plot.

Returns:

If return_fig is True, returns a tuple of (figure, axis) objects. Otherwise, returns None.

Return type:

tuple or None

property config: Config

Returns the internally stored config object, which contains the configuration of the ACID run.

set_inputs(input_wavelengths: Array1D | Array2D | None = None, input_flux: Array1D | Array2D | None = None, input_errors: Array1D | Array2D | None = None, input_sn: Array1D | Array2D | Scalar | None = None, skips: IntLike | None = None) None[source]

Sets the input data for the ACID class. This is used to initialize the data object with the raw spectra, and to validate the arguments (previously done within the ACID function). :param input_wavelengths: Wavelength array for the input spectra, by default None :type input_wavelengths: np.ndarray, optional :param input_flux: Flux array for the input spectra, by default None :type input_flux: np.ndarray, optional :param input_errors: Error array for the input spectra, by default None :type input_errors: np.ndarray, optional :param input_sn: Signal-to-noise array for the input spectra, by default None :type input_sn: np.ndarray, optional :param skips: Allows you to set and override the Config value for skips if skips is not None.

This allows the inputs to only set one in every skips pixels and is only recommended for testing. By default None, and uses the Config default value (1, no skipping).

reset() None[source]

Resets all data attributes to their default empty states, except for the array inputs, linelist, velocities, and config.

plot_continuum_fit(plot_type: str = 'masked', return_fig: bool = False, save_fig: str | None = None) None[source]

Plots the result of the continuum fitting step, showing the original spectrum, the fitted continuum, and the clipped points used for the continuum fit.

Parameters:
  • plot_type (str, optional) – The type of continuum fit to plot, either “initial” for the initial continuum fit or “masked” for the continuum fit after residual masking. Default is “masked”.

  • return_fig (bool, optional) – Whether to return the figure and axis objects instead of showing the plot, by default False.

  • save_fig (str or None, optional) – If provided, the path to save the figure. If None, the figure will not be saved. Default is None.

plot_residual_masking(save_fig: str | None = None) None[source]

Creates 3 plots to show the result of the residual masking step, showing the residuals with the sigma clipping thresholds, the masked regions, and the initial profile after masking.

Parameters:

save_fig (str or None, optional) – If provided, a directory to save the figure, will create one if it does not exist. If None, the figure will not be saved. Default is None.

save(save_path: str | None = None, sampler_path: str | None = None) None[source]

Saves the data object to a file using pickling. This will store just the dictionary of the class, not the actual class itself. The load function then will initialise a new Data class using the dictionary.

Parameters:
  • save_path (str | None) – The path to save the data object. If None, uses the path stored in the config. If That is also None, the data object will not be saved. Will attempt to create the directory for the filepath if it does not exist. The file must end with .pkl to be recognised as a pickled file.

  • sampler_path (str | None) – This is used for saving the sampler as a HDF5 file if it has not already been set up as such. If a .h5 file is provided, and the sampler is not already saved as a HDF5 file, the sampler backend is converted to a HDF5 backend and saved. If the sampler is already set up to save as a HDF5 file, this argument is ignored. If you want to move the file location, move it yourself and set Data.sampler = sampler_path to update the location in the Data object. If None, this will do nothing.

classmethod load(filename: str) Data[source]

Loads a data object from a file using pickling. This will read the dictionary from the file and then use it to initialise a new Data class.

Parameters:

filename (str) – The name of the file to load the data object from. This should be a .pkl file.

Returns:

The loaded data object.

Return type:

Data

to_dict() dict[str, Any][source]

Converts the data object to a dictionary payload for saving. This is used internally in the save method, but can also be used for debugging or other purposes.

from_dict(payload: dict[str, Any]) Data[source]

Updates the data object from a dictionary payload. This is used internally in the load method, but can also be used for debugging or other purposes.

Parameters:

payload (dict) – The dictionary payload to update the data object from. This should have the same keys as the attributes of the data class. The “config” key should be a dictionary that can be used to initialise a Config class.

property result