"""Opacities from Exo_Transmit.Exo_Transmit is a code for calculating transmission spectra for exoplanetatmospheres of varied composition. Its opacities are based on HITRAN andhave the format `opac{molecule}.dat`."""importpathlibimporttypingastimportnumpyasnpimportnumpy.typingasnptfromtaurex.opacity.interpolateopacityimportInterpModeType,InterpolatingOpacityfromtaurex.typesimportPathLike
[docs]classExoTransmitOpacity(InterpolatingOpacity):"""Opacity from Exo_Transmit."""
[docs]@classmethoddefdiscover(cls,)->t.List[t.Tuple[str,t.Tuple[pathlib.Path,InterpModeType]]]:"""Discover opacities from Exo_Transmit. They have the format `opac{molecule}.dat`. So we try to search for them in the xsec_path. """importpathlibfromtaurex.cacheimportGlobalCachefromtaurex.utilimportsanitize_molecule_stringpath=GlobalCache()["xsec_path"]ifpathisNone:return[]path=pathlib.Path(path)files=path.glob("opac*.dat")discovery=[]interp=GlobalCache()["xsec_interpolation"]or"linear"forfinfiles:mol_name=sanitize_molecule_string(f.stem[4:])discovery.append((mol_name,[f,interp]))returndiscovery
def__init__(self,filename:PathLike,interpolation_mode:t.Optional[InterpModeType]="linear",):"""Initialize opacity from Exo_Transmit. Parameters ---------- filename: PathLike Path to opacity file. interpolation_mode: str, optional Interpolation mode. Either 'linear' or 'exp'. Raises ------ FileNotFoundError If file is not found. """super().__init__(f"ExoOpacity:{pathlib.Path(filename).stem[4:]}",interpolation_mode=interpolation_mode,)self._filename=pathlib.Path(filename)ifnotself._filename.exists():raiseFileNotFoundError(f"Could not find {self._filename}")self._molecule_name=pathlib.Path(filename).stem[4:]self._load_exo_transmit(filename)def_load_exo_transmit(self,filename:pathlib.Path):"""Load opacity from Exo_Transmit file. Parameters ---------- filename: PathLike Path to opacity file. """self.debug(f"Loading opacity from {filename}")withopen(filename)asf:lines=f.readlines()self._temperature_grid=np.array([float(col)forcolinlines[0].split()])# *t_conversionself._pressure_grid=np.array([float(col)forcolinlines[1].split()])*1e5self._min_pressure=self._pressure_grid.min()self._max_pressure=self._pressure_grid.max()self._min_temperature=self._temperature_grid.min()self._max_temperature=self._temperature_grid.max()wn_grid=[]forlninlines[2:]:arr=np.array([float(col)forcolinln.split()])ifarr.shape[0]==1:wn_grid.append(10000*1e-6/arr[0])wn_grid=np.array(wn_grid)grid_sort=wn_grid.argsort()self._wavenumber_grid=wn_grid[grid_sort]pressure_count=0lambda_count=-1self._xsec_grid=np.empty(shape=(self.pressureGrid.shape[0],self.temperatureGrid.shape[0],self.wavenumberGrid.shape[0],))forlninlines[2:]:arr=np.array([float(col)forcolinln.split()])ifarr.shape[0]==1:lambda_count+=1pressure_count=0else:self._xsec_grid[pressure_count,:,lambda_count]=arr[1:]+1e-60pressure_count+=1self._xsec_grid=self._xsec_grid[:,:,grid_sort]*10000@propertydefwavenumberGrid(self)->npt.NDArray[np.float64]:# noqa: N802"""Wavenumber grid."""returnself._wavenumber_grid@propertydeftemperatureGrid(self)->npt.NDArray[np.float64]:# noqa: N802"""Temperature grid."""returnself._temperature_grid@propertydefpressureGrid(self)->npt.NDArray[np.float64]:# noqa: N802"""Pressure grid."""returnself._pressure_grid@propertydefresolution(self)->float:"""Resolution of opacity."""returnself._resolution@propertydefmoleculeName(self)->str:# noqa: N802"""Name of molecule."""returnself._molecule_name@propertydefxsecGrid(self)->npt.NDArray[np.float64]:# noqa: N802"""Opacity grid."""returnself._xsec_gridBIBTEX_ENTRIES=[""" @ARTICLE{2017PASP..129d4402K, author = {{Kempton}, Eliza M. -R. and {Lupu}, Roxana and {Owusu-Asare}, Albert and {Slough}, Patrick and {Cale}, Bryson}, title = "{Exo-Transmit: An Open-Source Code for Calculating Transmission Spectra for Exoplanet Atmospheres of Varied Composition}", journal = {Publications of the Astronomical Society of the Pacific}, keywords = {Astrophysics - Earth and Planetary Astrophysics}, year = 2017, month = apr, volume = {129}, number = {974}, pages = {044402}, doi = {10.1088/1538-3873/aa61ef}, archivePrefix = {arXiv}, eprint = {1611.03871}, primaryClass = {astro-ph.EP}, adsurl = {https://ui.adsabs.harvard.edu/abs/2017PASP..129d4402K}, adsnote = {Provided by the SAO/NASA Astrophysics Data System} } """,]