synthesizer.emission_models.base_model¶
A module defining the emission model from which spectra are constructed.
Generating spectra involves the following steps: 1. Extraction from a Grid. 2. Generation of spectra. 3. Attenuation due to dust in the ISM/nebular. 4. Masking for different types of emission. 5. Combination of different types of emission.
An emission model defines the parameters necessary to perform these steps and gives an interface for simply defining the construction of complex spectra.
Example usage:
# Define the grid
grid = Grid(...)
# Define the dust curve
dust_curve = dust.attenuation.PowerLaw(...)
# Define the emergent emission model
emergent_emission_model = EmissionModel(
label="emergent",
grid=grid,
dust_curve=dust_curve,
apply_dust_to=dust_emission_model,
tau_v=tau_v,
fesc=fesc,
emitter="stellar",
)
# Generate the spectra
spectra = stars.get_spectra(emergent_emission_model)
# Generate the lines
lines = stars.get_lines(
line_ids=("Ne 4 1601.45A, He 2 1640.41A", "O3 1660.81A"),
emission_model=emergent_emission_model
)
Classes
- class synthesizer.emission_models.base_model.BlackHoleEmissionModel(*args, **kwargs)[source]¶
An emission model for black hole components.
This is a simple wrapper to quickly apply that the emitter a model should act on is a black hole.
- emitter¶
The emitter this model is for.
- Type:
str
- class synthesizer.emission_models.base_model.EmissionModel(label, grid=None, extract=None, combine=None, apply_dust_to=None, dust_curve=None, tau_v=None, generator=None, lum_intrinsic_model=None, lum_attenuated_model=None, mask_attr=None, mask_thresh=None, mask_op=None, fesc=0.0, lam_mask=None, related_models=None, emitter=None, fixed_parameters={}, scale_by=None, post_processing=(), save=True, per_particle=False, **kwargs)[source]¶
A class to define the construction of a spectra from a grid.
An emission model describes the steps necessary to construct a spectra from a grid. These steps can be: - Extracting a spectra from a grid. - Combining multiple spectra. - Applying a dust curve to a spectra. - Generating spectra from a dust emission model.
All of these stages can also have masks applied to them to remove certain elements from the spectra (e.g. if you want to eliminate young stars).
By chaining together multiple emission models, complex spectra can be constructed from a grid of particles.
Note: Every time a property is changed anywhere in the tree the tree must be reconstructed. This is a cheap process but must happen to ensure the expected properties are used when the model is used. This means most attributes are accessed through properties and set via setters to ensure the tree remains consistent.
A number of attributes are defined as properties to protect their values and ensure the tree is correctly reconstructed when they are changed. This also means the they are no included below in the Attributes section to avoid duplication.
- label¶
The key for the spectra that will be produced.
- Type:
str
- lam¶
The wavelength array.
- Type:
unyt_array
- masks¶
A list of masks to apply.
- Type:
list
- parents¶
A list of models which depend on this model.
- Type:
list
- children¶
A list of models this model depends on.
- Type:
list
A list of related models to this model. A related model is a model that is connected somewhere within the model tree but is required in the construction of the “root” model encapulated by self.
- Type:
list
- fixed_parameters¶
A dictionary of component attributes/parameters which should be fixed and thus ignore the value of the component attribute. This should take the form {<parameter_name>: <value>}.
- Type:
dict
- emitter¶
The emitter this emission model acts on. Default is “stellar”.
- Type:
str
- apply_dust_to¶
The model to apply the dust curve to.
- Type:
- dust_curve¶
The dust curve to apply.
- Type:
emission_models.attenuation.*
- tau_v¶
The optical depth to apply. Can be a float, ndarray, or a string to a component attribute. Can also be a tuple combining any of these.
- Type:
float/ndarray/str/tuple
- generator¶
The emission generation model. This must define a get_spectra method.
- Type:
- lum_intrinsic_model¶
The intrinsic model to use deriving the dust luminosity when computing dust emission.
- Type:
- lum_attenuated_model¶
The attenuated model to use deriving the dust luminosity when computing dust emission.
- Type:
- mask_attr¶
The component attribute to mask on.
- Type:
str
- mask_thresh¶
The threshold for the mask.
- Type:
unyt_quantity
- mask_op¶
The operation to apply. Can be “<”, “>”, “<=”, “>=”, “==”, or “!=”.
- Type:
str
- fesc¶
The escape fraction.
- Type:
float
- lam_mask¶
The mask to apply to the wavelength array.
- Type:
ndarray
- scale_by¶
A list of attributes to scale the spectra by.
- Type:
list
- post_processing¶
A list of post processing functions to apply to the emission after it has been generated. Each function must take a dict containing the spectra/lines, the emitters, and the emission model, and return the same dict with the post processing applied.
- Type:
list
- save¶
A flag for whether the emission produced by this model should be “saved”, i.e. attached to the emitter. If False, the emission will be discarded after it has been used. Default is True.
- Type:
bool
- per_particle¶
A flag for whether the emission produced by this model should be “per particle”. If True, the spectra and lines will be stored per particle. Integrated spectra are made automatically by summing the per particle spectra. Default is False.
- Type:
bool
- add_mask(attr, op, thresh, set_all=False)[source]¶
Add a mask.
- Parameters:
attr (str) – The component attribute to mask on.
op (str) – The operation to apply. Can be “<”, “>”, “<=”, “>=”, “==”, or “!=”.
thresh (unyt_quantity) – The threshold for the mask.
set_all (bool) – Whether to add the mask to all models.
- property apply_dust_to¶
Get the spectra to apply the dust curve to.
- property combine¶
Get the models to combine.
- property dust_curve¶
Get the dust curve to apply.
- property emitter¶
Get the emitter this emission model acts on.
- property extract¶
Get the key for the spectra to extract.
- property fesc¶
Get the escape fraction.
- fix_parameters(**kwargs)[source]¶
Fix parameters of the model.
- Parameters:
**kwargs – The parameters to fix.
- property generator¶
Get the emission generation model.
- property grid¶
Get the Grid object used for extraction.
- property lum_attenuated_model¶
Get the attenuated model for computing dust luminosity.
- property lum_intrinsic_model¶
Get the intrinsic model for computing dust luminosity.
- property per_particle¶
Get the per particle flag.
- plot_emission_tree(root=None, show=True, fontsize=10, figsize=(6, 6))[source]¶
Plot the tree defining the spectra.
- Parameters:
root (str) – If not None this defines the root of a sub tree to plot.
show (bool) – Whether to show the plot.
fontsize (int) – The fontsize to use for the labels.
- property post_processing¶
Get the post processing functions.
- relabel(old_label, new_label)[source]¶
Change the label associated to an existing spectra.
- Parameters:
old_label (str) – The current label of the spectra.
new_label (str) – The new label to assign to the spectra.
- replace_model(replace_label, *replacements, new_label=None)[source]¶
Remove a child model from this model.
- Parameters:
replace_label (str) – The label of the model to replace.
replacements (EmissionModel) – The models to replace the model with.
new_label (str) – The label for the new combination step if multiple replacements have been passed (ignored otherwise).
- property save¶
Get the flag for whether to save the emission.
- save_spectra(*args)[source]¶
Set the save flag to True for the given spectra.
- Parameters:
args (str) – The spectra to save.
- property scale_by¶
Get the attribute to scale the spectra by.
- set_combine(combine)[source]¶
Set the models to combine on this model.
- Parameters:
combine (list) – A list of models to combine.
- set_dust_props(dust_curve=None, apply_dust_to=None, tau_v=None, set_all=False)[source]¶
Set the dust attenuation properties on this model.
- Parameters:
dust_curve (emission_models.attenuation.*) – A dust curve instance to apply.
apply_dust_to (EmissionModel) – The model to apply the dust curve to.
tau_v (float/ndarray/str/tuple) – The optical depth to apply. Can be a float, ndarray, or a string to a component attribute. Can also be a tuple combining any of these. If a tuple then the eventual tau_v will be the product of all contributors.
set_all (bool) – Whether to set the properties on all models.
- set_emitter(emitter, set_all=False)[source]¶
Set the emitter this emission model acts on.
- Parameters:
emitter (str) – The emitter this emission model acts on.
set_all (bool) – Whether to set the emitter on all models.
- set_extract(extract)[source]¶
Set the spectra to extract from the grid.
- Parameters:
extract (str) – The key of the spectra to extract.
- set_fesc(fesc, set_all=False)[source]¶
Set the escape fraction on this model.
- Parameters:
fesc (float) – The escape fraction to set.
set_all (bool) – Whether to set the escape fraction on all models.
- set_generator(generator)[source]¶
Set the dust emission model on this model.
- Parameters:
generator (EmissionModel) – The emission generation model to set.
label (str) – The label of the model to set the dust emission model on. If None, sets the dust emission model on this model.
- set_grid(grid, set_all=False)[source]¶
Set the grid to extract from.
- Parameters:
grid (Grid) – The grid to extract from.
set_all (bool) – Whether to set the grid on all models.
- set_lum_attenuated_model(lum_attenuated_model)[source]¶
Set the attenuated model for computing dust luminosity.
- Parameters:
lum_attenuated_model (EmissionModel) – The attenuated model to set.
- set_lum_intrinsic_model(lum_intrinsic_model)[source]¶
Set the intrinsic model for computing dust luminosity.
- Parameters:
lum_intrinsic_model (EmissionModel) – The intrinsic model to set.
- set_per_particle(per_particle)[source]¶
Set the per particle flag.
For per particle spectra we need all children to also be per particle.
- Parameters:
per_particle (bool) – Whether to set the per particle flag.
set_all (bool) – Whether to set the per particle flag on all models.
- set_post_processing(post_processing, set_all=False)[source]¶
Set the post processing functions on this model.
- Parameters:
post_processing (list) – A list of post processing functions to apply to the emission after it has been generated. Each function must take a dict containing the spectra/lines and return the same dict with the post processing applied.
set_all (bool) – Whether to set the post processing functions on all models.
- set_save(save, set_all=False)[source]¶
Set the flag for whether to save the emission.
- Parameters:
save (bool) – Whether to save the emission.
set_all (bool) – Whether to set the save flag on all models.
- set_scale_by(scale_by, set_all=False)[source]¶
Set the attribute to scale the spectra by.
- Parameters:
scale_by (str/list/tuple/EmissionModel) – Either a component attribute to scale the resultant spectra by, a spectra key to scale by (based on the bolometric luminosity). or a tuple/list containing strings defining either of the former two options. Instead of a string, an EmissionModel can be passed to scale by the luminosity of that model.
set_all (bool) – Whether to set the scale by attribute on all models.
- property tau_v¶
Get the optical depth to apply.
- class synthesizer.emission_models.base_model.GalaxyEmissionModel(*args, **kwargs)[source]¶
An emission model for whole galaxy.
A galaxy model sets emitter to “galaxy” to flag to the get_spectra method that the model is for a galaxy. By definition a galaxy level spectra can only be a combination of component spectra.
- emitter¶
The emitter this model is for.
- Type:
str