Source code for taurex.data.profiles.chemistry.autochemistry
"""Chemistry that automatically seperates out active and inactive gases."""importtypingastimportnumpyasnpimportnumpy.typingasnptfrom.chemistryimportChemistry
[docs]classAutoChemistry(Chemistry):""" Chemistry class that automatically seperates out active and inactive gases Has a helper function that should be called at the end of initialization. :func:`determine_active_inactive` once :func:`gases` has been set. You'll only need to implement :func:`gases` and :func:`mixProfile` to use this class. """def__init__(self,name):"""Initialize auto chemistry. Parameters ---------- name: str Name of class """super().__init__(name)self._active=[]self._inactive=[]self._inactive_mask=Noneself._active_mask=None
[docs]defdetermine_active_inactive(self)->None:"""Determines active and inactive gases."""try:self._active,self._active_mask=zip(*[(m,i)fori,minenumerate(self.gases)ifminself.availableActive])exceptValueError:self.debug("No active gases detected")self._active,self._active_mask=[],Nonetry:self._inactive,self._inactive_mask=zip(*[(m,i)fori,minenumerate(self.gases)ifmnotinself.availableActive])exceptValueError:self.debug("No inactive gases detected")self._inactive,self._inactive_mask=[],Noneifself._active_maskisnotNone:self._active_mask=np.array(self._active_mask)ifself._inactive_maskisnotNone:self._inactive_mask=np.array(self._inactive_mask)
[docs]defcompute_mu_profile(self,nlayers:t.Optional[int]=None)->None:"""Computes molecular weight of atmosphere for each layer Parameters ---------- nlayers: int Number of layers, deprecated """ifself.mixProfileisnotNone:mix_profile=self.mixProfileself.mu_profile=np.sum([self.get_molecular_mass(gas)*mixforgas,mixinzip(self.gases,mix_profile)],axis=0,)else:raiseValueError("Mix profile not set/computed")
@propertydefgases(self)->t.List[str]:"""List of gases in atmosphere."""raiseNotImplementedError@propertydefmixProfile(self)->npt.NDArray[np.float64]:# noqa: N802"""Mix profile of gases."""raiseNotImplementedError@propertydefactiveGases(self)->npt.NDArray[np.float64]:# noqa: N802"""Actively absorbing gases."""returnself._active@propertydefinactiveGases(self)->npt.NDArray[np.float64]:# noqa: N802"""Non absorbing gases."""returnself._inactive@propertydefactiveGasMixProfile(self)->t.Optional[npt.NDArray[np.float64]]:# noqa: N802"""Active gas layer by layer mix profile Returns ------- active_mix_profile : :obj:`array` Active gas mix profile with shape ``(nactive, nlayer)`` """ifself.mixProfileisNone:raiseValueError("No mix profile computed.")ifself._active_maskisNone:returnNonereturnself.mixProfile[self._active_mask]@propertydefinactiveGasMixProfile(# noqa: N802self,)->t.Optional[npt.NDArray[np.float64]]:"""Inactive gas layer by layer mix profile. Returns ------- inactive_mix_profile : :obj:`array` """ifself.mixProfileisNone:raiseException("No mix profile computed.")ifself._inactive_maskisNone:returnNonereturnself.mixProfile[self._inactive_mask]