MetaModel#

class mufasa.spec_models.meta_model.MetaModel(fittype, ncomp)[source]#

Bases: object

A class to store spectral model-specific information relevant to spectral modeling tasks, such as fitting.

fittype#

The identifying name for the spectral model (i.e., the type of model to fit).

Type:

str

ncomp#

The number of components within the model.

Type:

int

adoptive_snr_masking#

Whether to use adaptive SNR masking during fitting (default is True).

Type:

bool

window_hwidth#

The default half-width of the window for calculating moments.

Type:

int

central_win_hwidth#

The half-width of the intermediate window for filtering out satellite hyperfine lines. Default is None.

Type:

float or None

Texmin#

Lower excitation temperature limit in Kelvin. Default is 3.0 K.

Type:

float

Texmax#

Upper excitation temperature limit in Kelvin. Default is 40 K.

Type:

float

sigmin#

Lower velocity dispersion limit in km/s. Default is 0.07 km/s.

Type:

float

sigmax#

Upper velocity dispersion limit in km/s. Default is 2.5 km/s.

Type:

float

taumin#

Lower optical depth limit. Default is 0.1.

Type:

float

taumax#

Upper optical depth limit. Default is 30.0.

Type:

float

eps#

A small perturbation that can be used in initial guesses. Default is 0.001.

Type:

float

main_hf_moments#

Function for calculating moments for the main hyperfine component.

Type:

function

linetype#

The type of spectral line (e.g., ‘nh3’, ‘n2hp’). Set based on fittype.

Type:

str

linenames#

Names of the spectral lines being modeled. Set based on fittype.

Type:

list of str

linename#

Name of the main spectral line being modeled. Set based on fittype.

Type:

str

fitter#

The model generator function for fitting spectral components. Set based on fittype.

Type:

function

freq_dict#

Dictionary containing rest frequencies for the spectral lines. Set based on fittype.

Type:

dict

rest_value#

Rest frequency of the spectral line in Hz. Set based on fittype.

Type:

astropy.units.Quantity

voffs#

Velocity offsets for the hyperfine lines in km/s. Set based on fittype.

Type:

list of float

tau_wts#

Weights for the optical depth of hyperfine lines. Set based on fittype.

Type:

list of float

voff_at_peak#

Velocity offset at the brightest hyperfine line in km/s. Set based on fittype.

Type:

float

model_func#

The specific spectral model function used for fitting. Set based on fittype.

Type:

function

model_function(xarr, parameters, planemask=None, multithreaded=False)[source]#

Compute the spectral model for a given spectral axis and model parameters.

Parameters:
  • xarr (pyspeckit.spectrum.units.SpectroscopicAxis) – The spectral axis along which to evaluate the model function.

  • parameters (array-like) –

    The model parameters for evaluation. Can be:

    • A 1D array with shape (l,), representing a single set of parameters.

    • A 2D array with shape (l, n), where l is the number of parameters, and n is the number of spatial positions.

    • A 3D array with shape (l, m, n), where l is the number of parameters per pixel, and m and n represent the spatial dimensions. In this case, the function will evaluate the model at each (m, n) pixel specified by planemask.

  • planemask (array-like, optional) – A 2D mask array with shape (m, n) indicating the pixels to evaluate when parameters is 3D. Pixels with True in the mask will be evaluated. If None, a default mask is generated where all non-zero, finite values in parameters are considered valid.

  • multithreaded (bool, optional) – Whether to enable multithreading to evaluate pixels in parallel when parameters is 2D or 3D. Default is False.

Returns:

The evaluated spectral model values. The output shape matches the input shape of parameters:

  • If parameters is 1D, returns a 1D array of computed values.

  • If parameters is 2D, returns a 1D array with length n, containing computed values for each position.

  • If parameters is 3D, returns a 2D array with shape (m, n), containing computed values for each evaluated pixel in the masked region. Masked pixels are filled with NaN.

Return type:

np.ndarray

peakT(parameters, index_v=0, planemask=None, multithreaded=False)[source]#

Estimate the peak brightness temperature of the spectral model by evaluating the model at the spectral location (i.e., the velocity) of the brightest hyperfine line.

Note

This method only works for a single-component model, where the peak brightness is expected to be located near the brightest hyperfine line.

Parameters:
  • parameters (array-like) –

    The model parameters to evaluate, where each element corresponds to a parameter used in the spectral model. Can be:

    • A 1D array with shape (l,), representing a single set of parameters.

    • A 2D array with shape (l, n), where l is the number of parameters and n is the number of spatial positions.

    • A 3D array with shape (l, m, n), where l is the number of parameters per pixel, and m and n represent the spatial dimensions.

  • index_v (int, optional) – Index of the parameter corresponding to the velocity centroid, which is 0 for all spectral models implemented in MUFASA. Default is 0.

  • planemask (array-like, optional) – A 2D mask array with shape (m, n) indicating the pixels to evaluate when parameters is 3D. Pixels with True in the mask will be evaluated. If None, a mask is generated based on finite, non-zero values in parameters.

  • multithreaded (bool, optional) – Whether to enable multithreading to evaluate pixels in parallel when parameters is 2D or 3D. Default is False.

Returns:

An array with the peak brightness temperature for each evaluated pixel:

  • If parameters is 1D, returns a scalar representing the peak brightness temperature.

  • If parameters is 2D, returns a 1D array with length n, containing the peak brightness temperature for each position.

  • If parameters is 3D, returns a 2D array with shape (m, n), containing the peak brightness temperature for each evaluated pixel in the masked region. Masked pixels are filled with NaN.

Return type:

np.ndarray