ExObsSim / Rapoc-public

Rapoc uses molecular absorption measurements (i.e. wavelength-dependent opacities) to calculate Rosseland and Planck mean opacities that are commonly used in atmospheric modelling.
https://rapoc-public.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
3 stars 1 forks source link

Exomol opacity files dont't open #2

Closed AaronDavidSchneider closed 2 years ago

AaronDavidSchneider commented 2 years ago

Problem

Hi, I tried to open up some TauREx exomol file, following the description in the docs, and encountered the following error Cheers Aaron

code:

from rapoc import Rosseland, Planck
import astropy.units as u
r_model = Rosseland(input_data='water.TauREx.h5')
opacity = r_model.estimate(P_input=10000 * u.Pa, T_input=1000 * u.K, band=(0.3 *u.um, 50*u.um))

error:

TypeError                                 Traceback (most recent call last)
Input In [4], in <cell line: 1>()
----> 1 r_model = Rosseland(input_data='water.TauREx.h5')
      2 opacity = r_model.estimate(P_input=10000 * u.Pa, T_input=1000 * u.K, band=(0.3 *u.um, 50*u.um))

File ~/codes/exo/Rapoc-public/rapoc/models/rosseland.py:82, in Rosseland.__init__(self, input_data)
     57 def __init__(self, input_data):
     58     '''
     59 
     60     Parameters
   (...)
     80     Now the model is ready to be used
     81     '''
---> 82     super().__init__(input_data)
     83     self.model_name = 'Rosseland'

File ~/codes/exo/Rapoc-public/rapoc/models/model.py:73, in Model.__init__(self, input_data)
     71 self.selected_grid = None
     72 loaded = self._loader_selector()
---> 73 self.mol, self.mol_mass, self.pressure_grid, self.temperature_grid, self.wavenumber_grid, self.opacities, self.exceptions = loaded.read_content()
     74 self.frequency_grid = (self.wavenumber_grid * const.c).si
     75 self.wavelength_grid = 1 / self.wavenumber_grid.to(1 / u.um)

File ~/codes/exo/Rapoc-public/rapoc/loaders/loader.py:40, in FileLoader.read_content(self)
     38 opened_file = self._open()
     39 mol = self._read_molecule_name(opened_file)
---> 40 mol_mass = self._get_mol_mass(mol)
     41 pressure_grid = self._read_pressure_grid(opened_file)
     42 temperature_grid = self._read_temperature_grid(opened_file)

File ~/codes/exo/Rapoc-public/rapoc/loaders/exoMolFileLoader.py:39, in ExoMolFileLoader._get_mol_mass(self, mol)
     37 def _get_mol_mass(self, mol):
     38     from molmass import Formula
---> 39     f = Formula(mol)
     40     self.mol_mass = (f.mass * u.u / u.ct).to(u.g / u.ct)
     41     return self.mol_mass

File ~/anaconda3/envs/exorad/lib/python3.10/site-packages/molmass/molmass.py:247, in Formula.__init__(self, formula, groups)
    246 def __init__(self, formula='', groups=None):
--> 247     self._formula = from_string(formula, groups)

File ~/anaconda3/envs/exorad/lib/python3.10/site-packages/molmass/molmass.py:838, in from_string(formula, groups)
    807 """Return formula string from user input string.
    808 
    809 Return string should be composed of chemical elements/isotopes,
   (...)
    835 
    836 """
    837 try:
--> 838     formula = formula.strip().replace(' ', '')
    839 except AttributeError as exc:
    840     raise FormulaError('not a string') from exc
leoriohub commented 2 years ago

Hi, I was triying the quickstart and got the same error!

LorenzoMugnai commented 2 years ago

Hi, thanks for your feedback. The error seems to be caused by a missing ASCII conversion. I included a minor fix in the new release. Please try rapoc-1.0.8 and let me know if the error persists.

AaronDavidSchneider commented 2 years ago

thanks! Will try as soon as possible

AaronDavidSchneider commented 2 years ago

can confirm that it works now.