ACID_code.Profiles
- class ACID_code.Profiles(velocities: ACID_code.Array1D = None, flux: ACID_code.Array1D = None, flux_err: ACID_code.Array1D = None, cov_matrix: ACID_code.Array2D = None, data: Data = None)[source]
A class for fitting spectral line profiles to Voigt, Gaussian, and Lorentzian models.
Initializes the Profiles class with velocity, flux, and optional flux error data.
- Parameters:
velocities (
Array1D, optional) – The velocity values corresponding to the spectral line profile. Must be provided if no data instance is passed, by default None.flux (
Array1D, optional) – The flux values of the spectral line profile Must be provided if no data instance is passed, by default None.flux_err (
Array1D, optional) – The errors associated with the flux values, by default None. If not input, they won’t be used in the fitting process.cov_matrix (
Array2D, optional) – The covariance matrix associated with the flux values, by default None. If not input, it won’t be used in the fitting process. Inputting this overrides the errors when fitting.data (
Data, optional) – A data instance to draw velocities, flux, flux errors, and covariance matrix. Will raise an exception if they do not exist within the class. Must be provided if all four of the above inputs were not passed, by default None.
- plot_fit(model: str | None = 'voigt', return_fig=False, **kwargs) tuple | None[source]
Plots the original data and the fitted profile if available.
- Parameters:
model (
str | None, optional) – The type of model to plot. String options are ‘voigt’, ‘gaussian’, ‘lorentzian’, ‘none’, or ‘all’. Choosing ‘none’ or None will plot whichever models have already been fitted for, by default ‘all’.return_fig (
bool, optional) – Whether to return the (fig, ax) tuple and not call plt.show(). If False, calls plt.show() and returns None. By default False.**kwargs (
dict) – Additional keyword arguments to pass to the fitting functions if the models have not been fitted yet.
- Returns:
If return_fig is True, returns the (fig, ax) tuple. Otherwise, returns None.
- Return type:
tuple | None
- fit_voigt(x=None, y=None, yerr=None, cov_matrix=None, p0=None, **kwargs) tuple[source]
Fits a Voigt profile to the given data.
- Parameters:
x (
array_like, optional) – The x values of the data. If None, uses self.velocities.y (
array_like, optional) – The y values of the data. If None, uses self.flux.yerr (
array_like, optional) – The y errors of the data. If None, uses self.flux_err.cov_matrix (
np.ndarray, optional) – The covariance matrix associated with the flux values. If None, uses self.cov_matrix.p0 (
list, optional) – Initial guess for the parameters [amplitude, centre, sigma, gamma, offset], by default None.**kwargs (
dict) – Additional keyword arguments to pass to curve_fit.
- Returns:
A tuple containing the optimal parameters and the covariance matrix.
- Return type:
tuple
- fit_gaussian(x=None, y=None, yerr=None, cov_matrix=None, p0=None, **kwargs) tuple[source]
Fits a Gaussian profile to the given data.
- Parameters:
x (
array_like, optional) – The x values of the data. If None, uses self.velocities.y (
array_like, optional) – The y values of the data. If None, uses self.flux.yerr (
array_like, optional) – The y errors of the data. If None, uses self.flux_err.cov_matrix (
np.ndarray, optional) – The covariance matrix associated with the flux values. If None, uses self.cov_matrix.p0 (
list, optional) – Initial guess for the parameters [amplitude, mean, stddev], by default None.**kwargs (
dict) – Additional keyword arguments to pass to curve_fit.
- Returns:
A tuple containing the optimal parameters and the covariance matrix.
- Return type:
tuple
- fit_lorentzian(x=None, y=None, yerr=None, cov_matrix=None, p0=None, **kwargs) tuple[source]
Fits a Lorentzian profile to the given data.
- Parameters:
x (
array_like, optional) – The x values of the data. If None, uses self.velocities.y (
array_like, optional) – The y values of the data. If None, uses self.flux.yerr (
array_like, optional) – The y errors of the data. If None, uses self.flux_err.cov_matrix (
np.ndarray, optional) – The covariance matrix associated with the flux values. If None, uses self.cov_matrix.p0 (
list, optional) – Initial guess for the parameters [amplitude, centre, gamma, offset], by default None.**kwargs (
dict) – Additional keyword arguments to pass to curve_fit.
- Returns:
A tuple containing the optimal parameters and the covariance matrix.
- Return type:
tuple
- static voigt_func(x, amplitude, centre, sigma, gamma, offset=0) ACID_code.Array1D[source]
Calculates the Voigt profile at given x values.
- Parameters:
x (
array_like) – The x values where the Voigt profile is evaluated.amplitude (
float) – The amplitude of the Voigt profile.centre (
float) – The center position of the Voigt profile.sigma (
float) – The Gaussian standard deviation.gamma (
float) – The Lorentzian half-width at half-maximum.offset (
float, optional) – The continuum offset, by default 0.
- Returns:
The Voigt profile evaluated at the input x values.
- Return type:
array_like
- static gaussian_func(x, amplitude, mean, stddev, offset=0) ACID_code.Array1D[source]
Calculates the Gaussian profile at given x values.
- Parameters:
x (
array_like) – The x values where the Gaussian profile is evaluated.amplitude (
float) – The amplitude of the Gaussian profile.mean (
float) – The mean (center) of the Gaussian profile.stddev (
float) – The standard deviation of the Gaussian profile.offset (
float, optional) – The continuum offset, by default 0.
- Returns:
The Gaussian profile evaluated at the input x values.
- Return type:
array_like
- static lorentzian_func(x, amplitude, centre, gamma, offset=0) ACID_code.Array1D[source]
Calculates the Lorentzian profile at given x values.
- Parameters:
x (
array_like) – The x values where the Lorentzian profile is evaluated.amplitude (
float) – The amplitude of the Lorentzian profile.centre (
float) – The center position of the Lorentzian profile.gamma (
float) – The half-width at half-maximum.offset (
float, optional) – The continuum offset, by default 0.
- Returns:
The Lorentzian profile evaluated at the input x values.
- Return type:
array_like