spectral_models module
Provides classes for modelling the 21-cm spectral line emitted by a SPH particle.
- class martini.spectral_models.DiracDeltaSpectrum(ncpu: int | None = None, spec_dtype: type = <class 'numpy.float64'>)[source]
Bases:
_BaseSpectrumClass implemeting a Dirac-delta model for the spectrum of the HI line.
The line is modelled as a Dirac-delta function, centered at the particle velocity.
- Parameters:
ncpu (int, optional) – Number of cpus to use for evaluation of particle spectra. Defaults to
1if not provided.spec_dtype (type, optional) – Data type of the arrays storing spectra of each particle, can be used to manage memory usage by adjusting precision.
- evaluate_spectra(source: SPHSource, datacube: DataCube, mask: slice | EllipsisType = Ellipsis) Annotated[Quantity, Unit(dimensionless)]
Evaluate the spectra.
Separated into this function so that it can be called by a parallel process pool.
- Parameters:
- Returns:
The evaluated dimensionless spectra.
- Return type:
- get_spectral_function_extra_data(source: SPHSource, datacube: DataCube, mask: slice | EllipsisType = Ellipsis, extra_data: dict[str, Quantity] | None = None) dict[str, Quantity]
Initialize extra data needed by spectral function. Default is no extra data.
Derived classes should override this function, if needed, to populate the dict with any information from the source that is required by the
spectral_function(), then callsuper().get_spectral_function_extra_datawith theextra_dataargument set to the dictionary that they loaded. This function then handles setting up the array for broadcasting.- Parameters:
source (SPHSource) – Source object, making particle properties available.
datacube (DataCube) –
DataCubeobject defining the observational parameters, including spectral channels.mask (slice, optional) – Slice defining the subset of particles to operate on.
extra_data (dict, optional) –
dictcontaining additional data arrays needed for the spectral function evaluation. The dictionary entries should contain scalars or 1D arrays of particle properties.
- Returns:
The extra data that have been read in and prepared for use.
- Return type:
dict
- half_width(source: SPHSource) Annotated[Quantity, Unit('km / s')][source]
Dirac-delta function has 0 width.
- init_spectra(source: SPHSource, datacube: DataCube) None
Pre-compute the spectrum of each particle.
The spectral model defined in
spectral_function()is evaluated using the channel edges from theDataCubeinstance and the particle velocities of theSPHSource(or derived class) instance provided.If the instance of this class was initialized with
ncpu > 1then a process pool is created to distribute subsets of the calculation in parallel. To minimize overhead form serializing large amounts of data inmultiprocesscommunications, each parallel process inherits the entire line-of-sight velocity array (cheap because of copy-on-write behaviour), then masks its copy to the subset to operate on.
- spectral_function(a: Annotated[Quantity, Unit('km / s')], b: Annotated[Quantity, Unit('km / s')], vmids: Annotated[Quantity, Unit('km / s')], extra_data: dict[str, Quantity] | None = None) Annotated[Quantity, Unit(dimensionless)][source]
Evaluate a Dirac-delta function in a channel.
- Parameters:
a (Quantity) –
Quantity, with dimensions of velocity. Lower spectral channel edge(s).b (Quantity) –
Quantity, with dimensions of velocity. Upper spectral channel edge(s).vmids (Quantity) –
Quantity, with dimensions of velocity. Particle velocities along the line of sight.extra_data (dict, optional) –
dictcontaining arrays of extra data for the spectral function evaluation.
- Returns:
The evaluated spectral model (dimensionless).
- Return type:
- class martini.spectral_models.GaussianSpectrum(sigma: Quantity, Unit("km / s")]=<Quantity 7. km / s>, ncpu: int | None = None, spec_dtype: type = <class 'numpy.float64'>)[source]
Bases:
_BaseSpectrumClass implementing a Gaussian model for the spectrum of the HI line.
The line is modelled as a Gaussian of either fixed width, or of width scaling with the particle temperature as \(\\sqrt{k_B T / m_p}\), centered at the particle velocity.
- Parameters:
sigma (Quantity or str, optional) –
Quantity, with dimensions of velocity, or string"thermal". Width of the Gaussian modelling the line (constant for all particles), or specify"thermal"for width equal to \(\\sqrt{k_B T / m_p}\) where \(k_B\) is Boltzmann’s constant, \(T\) is the particle temperature and \(m_p\) is the particle mass.ncpu (int, optional) – Number of cpus to use for evaluation of particle spectra. Defaults to
1if not provided.spec_dtype (type, optional) – Data type of the arrays storing spectra of each particle, can be used to manage memory usage by adjusting precision.
See also
martini.spectral_models._BaseSpectrum,martini.spectral_models.DiracDeltaSpectrum- evaluate_spectra(source: SPHSource, datacube: DataCube, mask: slice | EllipsisType = Ellipsis) Annotated[Quantity, Unit(dimensionless)]
Evaluate the spectra.
Separated into this function so that it can be called by a parallel process pool.
- Parameters:
- Returns:
The evaluated dimensionless spectra.
- Return type:
- get_spectral_function_extra_data(source: SPHSource, datacube: DataCube, mask: slice | EllipsisType = Ellipsis, extra_data: dict[str, Quantity] | None = None) dict[str, Quantity][source]
Expose particle velocity dispersions.
Access to these is needed by
spectral_function().- Parameters:
- Returns:
The extra data that have been read in and prepared for use.
- Return type:
dict
- half_width(source: SPHSource) Annotated[Quantity, Unit('km / s')][source]
Get 1D velocity dispersions from particle temperatures, or return constant.
- init_spectra(source: SPHSource, datacube: DataCube) None
Pre-compute the spectrum of each particle.
The spectral model defined in
spectral_function()is evaluated using the channel edges from theDataCubeinstance and the particle velocities of theSPHSource(or derived class) instance provided.If the instance of this class was initialized with
ncpu > 1then a process pool is created to distribute subsets of the calculation in parallel. To minimize overhead form serializing large amounts of data inmultiprocesscommunications, each parallel process inherits the entire line-of-sight velocity array (cheap because of copy-on-write behaviour), then masks its copy to the subset to operate on.
- spectral_function(a: Annotated[Quantity, Unit('km / s')], b: Annotated[Quantity, Unit('km / s')], vmids: Annotated[Quantity, Unit('km / s')], extra_data: dict[str, Quantity] | None = None) Annotated[Quantity, Unit(dimensionless)][source]
Evaluate a Gaussian integral in a channel.
Requires sigma to be available from
spectral_function_extra_data.- Parameters:
a (Quantity) –
Quantity, with dimensions of velocity. Lower spectral channel edge(s).b (Quantity) –
Quantity, with dimensions of velocity. Upper spectral channel edge(s).vmids (Quantity) –
Quantity, with dimensions of velocity. Particle velocities along the line of sight.extra_data (dict, optional) –
dictcontaining arrays of extra data for the spectral function evaluation.
- Returns:
The evaluated spectral model (dimensionless).
- Return type: