synthesizer.units¶
A module for dynamically returning attributes with and without units.
The Units class below acts as a container of unit definitions for various attributes spread throughout Synthesizer.
The Quantity is the object that defines all attributes with attached units. Its a helper class which enables the optional return of units.
Example defintion:
class Foo:
bar = Quantity()
- def __init__(self, bar):
self.bar = bar
Example usage:
foo = Foo(bar)
bar_with_units = foo.bar bar_no_units = foo._bar
Functions
- synthesizer.units.accepts(**units)[source]¶
Check arguments passed to the wrapped function have compatible units.
This decorator will cross check any of the arguments passed to the wrapped function with the units defined in this decorators kwargs. If units are not compatible or are missing an error will be raised. If the units don’t match the defined units in units then the values will be converted to the correct units.
This is inspired by the accepts decorator in the unyt package, but includes Synthesizer specific errors and conversion functionality.
- Parameters:
**units – The keyword arguments defined with this decorator. Each takes the form of argument=unit_for_argument. In reality this is a dictionary of the form {“variable”: unyt.unit}.
- Returns:
- function
The wrapped function.
- synthesizer.units.has_units(x)[source]¶
Check whether the passed variable has units.
This will check the argument is a unyt_quanity or unyt_array.
- Parameters:
x (generic variable) – The variables to check.
- Returns:
- bool
True if the variable has units, False otherwise.
Classes
- class synthesizer.units.Quantity[source]¶
Provides the ability to associate attribute values on an object with unyt units defined in the global unit system held in (Units).
- public_name¶
The name of the class variable containing Quantity. Used the user wants values with a unit returned.
- Type:
str
- private_name¶
The name of the class variable with a leading underscore. Used the mostly internally for (or when the user wants) values without a unit returned.
- Type:
str
- class synthesizer.units.UnitSingleton[source]¶
A metaclass used to ensure singleton behaviour of Units.
i.e. there can only ever be a single instance of a class in a namespace.
Adapted from: https://stackoverflow.com/questions/6760685/creating-a-singleton-in-python
- class synthesizer.units.Units(new_units=None, force=False)[source]¶
Holds the definition of the internal unit system using unyt.
Units is a Singleton, meaning there can only ever be one. Each time a new instance is instantiated the original will be returned. This enforces a consistent unit system is used in a single top level namespace.
All default attributes are hardcoded but these can be modified by instantiating the original Units instance with a dictionary of units of the form {“variable”: unyt.unit}. This must be done before any calculations have been performed, changing the unit system will not retroactively convert computed quantities! In fact, if any quantities have been calculated the original default Units object will have already been instantiated, thus the default Units will be returned regardless of the modifications dictionary due to the rules of a Singleton metaclass. The user can force an update but BE WARNED this is dangerous and should be avoided.
- lam¶
Rest frame wavelength unit.
- Type:
unyt.unit_object.Unit
- obslam¶
Observer frame wavelength unit.
- Type:
unyt.unit_object.Unit
- wavelength¶
Alias for rest frame wavelength unit.
- Type:
unyt.unit_object.Unit
- nu¶
Rest frame frequency unit.
- Type:
unyt.unit_object.Unit
- obsnu¶
Observer frame frequency unit.
- Type:
unyt.unit_object.Unit
- nuz¶
Observer frame frequency unit.
- Type:
unyt.unit_object.Unit
- luminosity¶
Luminosity unit.
- Type:
unyt.unit_object.Unit
- lnu¶
Rest frame spectral luminosity density (in terms of frequency) unit.
- Type:
unyt.unit_object.Unit
- llam¶
Rest frame spectral luminosity density (in terms of wavelength) unit.
- Type:
unyt.unit_object.Unit
- continuum¶
Continuum level of an emission line unit.
- Type:
unyt.unit_object.Unit
- fnu¶
Spectral flux density (in terms of frequency) unit.
- Type:
unyt.unit_object.Unit
- flam¶
Spectral flux density (in terms of wavelength) unit.
- Type:
unyt.unit_object.Unit
- flux¶
“Rest frame” Spectral flux density (at 10 pc) unit.
- Type:
unyt.unit_object.Unit
- photo_lnu¶
Rest frame photometry unit.
- Type:
unyt.unit_object.Unit
- photo_fnu¶
Observer frame photometry unit.
- Type:
unyt.unit_object.Unit
- ew¶
Equivalent width unit.
- Type:
unyt.unit_object.Unit
- coordinates¶
Particle coordinate unit.
- Type:
unyt.unit_object.Unit
- centre¶
Galaxy/particle distribution centre unit.
- Type:
unyt.unit_object.Unit
- radii¶
Particle radii unit.
- Type:
unyt.unit_object.Unit
- smoothing_lengths¶
Particle smoothing length unit.
- Type:
unyt.unit_object.Unit
- softening_length¶
Particle gravitational softening length unit.
- Type:
unyt.unit_object.Unit
- velocities¶
Particle velocity unit.
- Type:
unyt.unit_object.Unit
- masses¶
Particle masses unit.
- Type:
unyt.unit_object.Unit
- initial_masses¶
Stellar particle initial mass unit.
- Type:
unyt.unit_object.Unit
- initial_mass¶
Stellar population initial mass unit.
- Type:
unyt.unit_object.Unit
- current_masses¶
Stellar particle current mass unit.
- Type:
unyt.unit_object.Unit
- dust_masses¶
Gas particle dust masses unit.
- Type:
unyt.unit_object.Unit
- ages¶
Stellar particle age unit.
- Type:
unyt.unit_object.Unit
- accretion_rate¶
Black hole accretion rate unit.
- Type:
unyt.unit_object.Unit
- bolometric_luminosity¶
Bolometric luminositiy unit.
- Type:
unyt.unit_object.Unit
- bolometric_luminosities¶
Bolometric luminositiy unit.
- Type:
unyt.unit_object.Unit
- bb_temperature¶
Black hole big bump temperature unit.
- Type:
unyt.unit_object.Unit
- bb_temperatures¶
Black hole big bump temperature unit.
- Type:
unyt.unit_object.Unit
- inclination¶
Black hole inclination unit.
- Type:
unyt.unit_object.Unit
- inclinations¶
Black hole inclination unit.
- Type:
unyt.unit_object.Unit
- resolution¶
Image resolution unit.
- Type:
unyt.unit_object.Unit
- fov¶
Field of View unit.
- Type:
unyt.unit_object.Unit
- orig_resolution¶
Original resolution (for resampling) unit.
- Type:
unyt.unit_object.Unit
- softening_lengths¶
Particle gravitational softening length unit.
- Type:
unyt.unit_object.Unit