synthesizer.emission_models.utils¶
A submodule containing utility functions for the emission models.
Functions
- synthesizer.emission_models.utils.cache_model_params(model, emitter)[source]¶
Cache all model specific parameters on to the emitter.
- This function stores all predefined parameters from the model including:
emitter: The emitter type for this model (stellar/blackhole/galaxy).
extract: The key that will extracted from the Grid.
combine: The models that will be combined to create the emission.
apply_to: The label of the model the transformation applies to.
transformer: The transformer’s repr.
generator: The generator’s repr.
mask parameters: Any parameters used in masking.
Note that all fixed parameters that are used will automatically be associated at the point of use via calls to get_param.
- Parameters:
model (EmissionModel) – The model object containing the parameters to cache.
emitter (Stars/Gas/BlackHoles/Galaxy) – The emitter object where the parameters will be cached.
- Return type:
None
- synthesizer.emission_models.utils.cache_param(param, emitter, model_label, value)[source]¶
Cache a parameter value on an emitter for a given model.
This function stores a computed parameter value in the emitter’s model_param_cache under the specified model label.
NOTE: This does not duplicate the value, it simply stores a reference to it. Under the hood this just increases the reference count by one.
- Parameters:
param (str) – The name of the parameter to cache.
emitter (Stars/Gas/BlackHoles/Galaxy) – The emitter object where the parameter will be cached.
model_label (str) – The label of the model associated with the parameter.
value (
Any) – The value to cache for the parameter.
- Return type:
None
- synthesizer.emission_models.utils.get_emission_label(emission)[source]¶
Return the emission dictionary key for an emission.
Emissions can be referred to either by their label or by the EmissionModel itself. This resolves either into the label used to key the dictionaries of generated emissions. The label is resolved lazily (rather than stored) so that relabelling a model is picked up.
- Parameters:
emission (EmissionModel/str) – The emission, either an EmissionModel or a label.
- Returns:
The label of the emission.
- Return type:
str
- synthesizer.emission_models.utils.get_param(param, model, emission, emitter, obj=None, default=<object object>, preserve_units=False, _singular_attempted=False, _plural_attempted=False, _visited=None)[source]¶
Extract a parameter from a model, emission, emitter, or object.
- The priority of extraction is:
Model (EmissionModel)
Emission (Sed/LineCollection)
Emitter (Stars/Gas/Galaxy)
Object (any object)
If we find a string value this should mean the parameter points to another attribute, so we will recursively look for that attribute.
- Parameters:
param (str) – The parameter to extract.
model (EmissionModel) – The model object.
emission (Sed/LineCollection) – The emission object.
emitter (Stars/Gas/Galaxy) – The emitter object.
obj (object, optional) – An optional additional object to look for the parameter on last.
default (object, optional) – The default value to return if the parameter is not found.
preserve_units (bool, optional) – If True, return raw parameter values with any attached units preserved. If False, array-like values are normalised for C-backed calculations where appropriate. Defaults to False.
_singular_attempted (bool, optional) – Internal flag to track if singular version has been attempted.
_plural_attempted (bool, optional) – Internal flag to track if plural version has been attempted.
_visited (set, optional) – Internal set to track visited parameters and detect cycles.
- Returns:
- value
The value of the parameter extracted from the appropriate object.
- Raises:
MissingAttribute – If the parameter is not found in the model, emission, or emitter. This is only raised if no default is passed.
- synthesizer.emission_models.utils.get_params(params, model, emission, emitter, obj=None, preserve_units=False)[source]¶
Extract a list of parameters from a model, emission, emitter, or object.
- The priority of extraction is:
Model (EmissionModel)
Emission (Sed/LineCollection)
Emitter (Stars/Gas/Galaxy)
Object (any object)
- Parameters:
params (list) – The parameters to extract.
model (EmissionModel) – The model object.
emission (Sed/LineCollection) – The emission object.
emitter (Stars/BlackHoles/Gas/Galaxy) – The emitter object.
obj (object, optional) – An optional additional object to look for parameters on last.
preserve_units (bool, optional) – If True, return raw parameter values with any attached units preserved. If False, array-like values are normalised for C-backed calculations where appropriate. Defaults to False.
- Returns:
A dictionary of the values of the parameters extracted from the appropriate object.
- Return type:
values (dict)