Mixin (taurex.mixin)

Core mixin functions.

class AnyMixin(**kwargs)[source]

Bases: Mixin[Any]

Can enhance any class.

KLASS_COMPAT

alias of object

class ChemistryMixin(**kwargs)[source]

Bases: Mixin[Chemistry], object

Enhances Chemistry.

KLASS_COMPAT

alias of Chemistry

class ContributionMixin(**kwargs)[source]

Bases: Mixin[Contribution], object

Enhances Contribution.

KLASS_COMPAT

alias of Contribution

class ForwardModelMixin(**kwargs)[source]

Bases: Mixin[ForwardModel], object

Enhances ForwardModel.

KLASS_COMPAT

alias of ForwardModel

class GasMixin(**kwargs)[source]

Bases: Mixin[Gas], object

Enhances Gas.

KLASS_COMPAT

alias of Gas

class InstrumentMixin(**kwargs)[source]

Bases: Mixin[Instrument], object

Enhances Instrument.

KLASS_COMPAT

alias of Instrument

class Mixin(**kwargs)[source]

Bases: MixinProtocol, Fittable, Citable, Generic[T]

Base mixin class.

KLASS_COMPAT: Type[T] = None
classmethod compatible(other: Type) bool[source]
classmethod input_keywords() Tuple[str, ...][source]
class MixinProtocol(*args, **kwargs)[source]

Bases: Protocol

Mixin protocol.

class ObservationMixin(**kwargs)[source]

Bases: SpectrumMixin

Enhances Spectrum.

class OptimizerMixin(**kwargs)[source]

Bases: Mixin[Optimizer], object

Enhances Optimizer.

KLASS_COMPAT

alias of Optimizer

class PlanetMixin(**kwargs)[source]

Bases: Mixin[Planet], object

Enhances Planet.

KLASS_COMPAT

alias of Planet

class PressureMixin(**kwargs)[source]

Bases: Mixin[PressureProfile], object

Enhances PressureProfile.

KLASS_COMPAT

alias of PressureProfile

class SpectrumMixin(**kwargs)[source]

Bases: Mixin[BaseSpectrum], object

Enhances Spectrum.

KLASS_COMPAT

alias of BaseSpectrum

class StarMixin(**kwargs)[source]

Bases: Mixin[Star], object

Enhances Star.

KLASS_COMPAT

alias of Star

class TemperatureMixin(**kwargs)[source]

Bases: Mixin[TemperatureProfile], object

Enhances TemperatureProfile.

KLASS_COMPAT

alias of TemperatureProfile

build_new_mixed_class(base_klass: Type[T], mixins: Sequence[Type[M]]) Type[T | M][source]

Build a new mixed class.

Parameters:
  • base_klass – Base class to mix with

  • mixins – Sequence of mixin classes

determine_mixin_args(klasses: Sequence[Type[T] | Type[M]]) Tuple[Dict[str, Any], bool][source]

Determine all arguments for a mixin class.

enhance_class(base_klass: Type[T], mixins: Sequence[Type[M]], **kwargs: Dict[str, Any]) T | M[source]

Build and initialise a new enhanced class.

Parameters:
  • base_klass – Base class to mix with

  • mixins – Sequence of mixin classes

  • kwargs – Keyword arguments to pass to the constructor

Returns:

A new class that is a subclass of base_klass and all mixins

Return type:

t.Union[T, M]

Raises:

KeyError: – If a keyword argument is not available in the new class

find_mapped_mixin(klass: Type[T]) Type[Mixin][source]

Find a mapped mixin class.

Parameters:

klass – Class to find the map.

mixed_init(self, **kwargs: Dict[str, Any]) None[source]

Initialisation function for mixed classes.

Some implemented mixins.

class MakeFreeMixin(**kwargs)[source]

Bases: ChemistryMixin

Provides a addGas() method to any chemistry

This class will either inject or force a molecule to become a Gas object. Allowing them to be freely changed or retrieved.

For example lets enhance ACE:

>>> from acepython.taurex import ACEChemistry
>>> from taurex.mixin import enhance_class, MakeFreeMixin
>>> old_ace = ACEChemistry()
>>> new_ace = enhance_class(ACEChemistry, MakeFreeMixin)

new_ace behaves the same as old_ace:

>>> new_ace.ace_metallicity
1.0

And we see the same molecules and fitting parameters exist:

>>> old_ace.gases == new_ace.gases
True
>>> new_ace.gases
['CH3COOOH', 'C4H9O', ... 'HNC', 'HON', 'NCN']
>>> new_ace.fitting_parameters().keys()
dict_keys(['ace_metallicity', 'metallicity', 'ace_co', 'C_O_ratio'])

new_ace is embued with the

>>> from taurex.chemistry import ConstantGas
>>> new_ace.addGas(ConstantGas('TiO',1e-8)).addGas(ConstantGas('VO',1e-8))
>>> new_ace.gases == old_ace.gases
False
>>> new_ace.gases
['CH3COOOH', 'C4H9O', ... 'HNC', 'HON', 'NCN', 'TiO', 'VO']

And indeed see that they are included. We can also retrieve them:

>>> new_ace.fitting_parameters().keys()
dict_keys(['TiO', 'VO', 'ace_metallicity', 'metallicity', 'ace_co', 'C_O_ratio'])

Finally we can force an existing molecule like CH4 into becoming a Gas:

>>> new_ace.addGas(ConstantGas('CH4',1e-5))

And see that it is now a retrieval parameter as well.

>>> new_ace.fitting_parameters().keys()
dict_keys(['TiO', 'VO', 'CH4', 'ace_metallicity',
            'metallicity', 'ace_co', 'C_O_ratio'])
property activeGasMixProfile: ndarray[tuple[int, ...], dtype[float64]]

Active gas layer by layer mix profile.

Returns:

active_mix_profile

Return type:

array

property activeGases: List[str]

Active gases in the atmosphere + injected.

addGas(gas: Gas) MakeFreeMixin[source]

Adds a gas in the atmosphere.

Parameters:

gas (Gas) – Gas to add into the atmosphere. Only takes effect on next initialization call.

compute_mu_profile(nlayers: int)[source]

Computes molecular weight of atmosphere for each layer.

Parameters:

nlayers (int) – Number of layers, deprecated

determine_new_mix_mask() None[source]

Determines which gases are new and which are old.

fitting_parameters() Dict[str, Tuple[str, str, Callable[[], float], Callable[[float], None], Literal['linear', 'log'], bool, Tuple[float, float]]][source]

Adds fitting parameters for injected gases.

Overrides the fitting parameters to return one with all the gas profile parameters as well

Returns:

fit_param

Return type:

dict

property gases: List[str]

Gases in the atmosphere + injected.

property inactiveGasMixProfile: ndarray[tuple[int, ...], dtype[float64]]

Inactive gas layer by layer mix profile

Returns:

inactive_mix_profile

Return type:

array

property inactiveGases: List[str]

Inactive gases in the atmosphere + injected.

initialize_chemistry(nlayers: int, temperature_profile: ndarray[tuple[int, ...], dtype[float64]], pressure_profile: ndarray[tuple[int, ...], dtype[float64]], altitude_profile: ndarray[tuple[int, ...], dtype[float64]] | None = None) None[source]

Initialize the chemistry.

Parameters:
  • nlayers (int) – number of layers

  • temperature_profile (np.ndarray) – temperature profile

  • pressure_profile (np.ndarray) – pressure profile

  • altitude_profile (np.ndarray , optional) – altitude profile, deprecated

classmethod input_keywords() Tuple[str, ...][source]

Input keywords for mixin.

property muProfile: ndarray[tuple[int, ...], dtype[float64]]

Molecular weight profile.

Returns:

mu_profile

Return type:

array

class TempScaler(**kwargs)[source]

Bases: TemperatureMixin

Scales the temperature profile by a factor.

Mostly a proof of concept class for mixins. Not particularly useful in practice.

classmethod input_keywords() Tuple[str, ...][source]

Input keywords for mixin.

property profile: ndarray[tuple[int, ...], dtype[float64]]

Scaled temperature profile.

property scaleFactor: float

Scale factor for temperature profile.