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: ndarray | None = None, c_factor: tuple | None = None, residual_masks: ndarray | None = None, nanmask: ndarray | None = None, initial_profile: ndarray | None = None, initial_profile_errors: ndarray | None = None, poly_inputs: ndarray | None = None, initial_model_inputs: ndarray | None = None, model_inputs: ndarray | None = None, initial_state: ndarray | None = None, nwalkers: int | None = None, ndim: int | None = None, profiles: list | None = None, combined_profile: list | None = None, continuum_model: ndarray | None = None, forward_model: ndarray | None = None, forward_errors: ndarray | None = None, forward_x: ndarray | 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: ndarray | None
The alpha vector used in the linear model, used for solving the linear system in MCMC
- c_factor: tuple | None
Tuple generated by np.cho_factor, used for solving the linear system in MCMC
- residual_masks: ndarray | None
Boolean 1D mask on “combined” grid, used in final process_results step
- nanmask: ndarray | None
Boolean 1D mask on “combined” grid, used to mask out NaN values in combined spectra
- initial_profile: ndarray | None
Initial profile generated in residual masking
- initial_profile_errors: ndarray | None
Corresponding errors for the initial profile
- poly_inputs: ndarray | None
Polynomial inputs for just the continuum model
- initial_model_inputs: ndarray | None
The initial_model_inputs if needed for debugging, only set after model_inputs is modified in residual masking
- model_inputs: ndarray | None
The concatenated array of initial profile and poly coefficients, used as input to emcee
- initial_state: ndarray | None
The initial state of the MCMC walkers, used for resuming and debugging
- 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
The list to store all frames of the MCMC sampling, has dimensions (nframes, 3, nvel), where the 3 indexes are the profile, error, and covariance matrix
- combined_profile: list | None
The list to store the combined frame of the MCMC sampling, has dimensions (3, nvel)
- continuum_model: ndarray | None
The final fitted continuum model and errors
- forward_model: ndarray | None
The forward model using the final profile, alpha matrix, and continuum model
- forward_errors: ndarray | None
Errors on the above forward model, usually not needed
- forward_x: ndarray | None
The x-axis for the above forward model, which is just the combined wavelength grid, and set in Result.process_results
- 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 (
tupleorlist, 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:
tupleorNone
- 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 (
strorNone, 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 (
strorNone, 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:
- 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