def test_constant_gas(self): from taurex.data.profiles.chemistry import ConstantGas gas = ConstantGas('H2O', 1e-4) file_path = self.gen_valid_hdf5_output(gas, 'Test') with h5py.File(file_path, 'r') as f: loaded = load_gas_from_hdf5(f['Test'], 'H2O') self.assertTrue(isinstance(loaded, ConstantGas)) self.assertEqual(gas._mix_ratio, loaded._mix_ratio)
def _setup_defaults(self, nlayers, atm_min_pressure, atm_max_pressure): if self._pressure_profile is None: from taurex.data.profiles.pressure import SimplePressureProfile self.info('No pressure profile defined, using simple pressure ' 'profile with') self.info('parameters nlayers: %s, atm_pressure_range=(%s,%s)', nlayers, atm_min_pressure, atm_max_pressure) self._pressure_profile = \ SimplePressureProfile(nlayers, atm_min_pressure, atm_max_pressure) if self._planet is None: from taurex.data import Planet self.warning('No planet defined, using Jupiter as planet') self._planet = Planet() if self._temperature_profile is None: from taurex.data.profiles.temperature import Isothermal self.warning('No temeprature profile defined using default ' 'Isothermal profile with T=1500 K') self._temperature_profile = Isothermal() if self._chemistry is None: from taurex.data.profiles.chemistry import TaurexChemistry, \ ConstantGas tc = TaurexChemistry() self.warning('No gas profile set, using constant profile with H2O ' 'and CH4') tc.addGas(ConstantGas('H2O', mix_ratio=1e-5)) tc.addGas(ConstantGas('CH4', mix_ratio=1e-6)) self._chemistry = tc if self._star is None: from taurex.data.stellar import BlackbodyStar self.warning('No star, using the Sun') self._star = BlackbodyStar()
def test_directimage(self): from taurex.util.hdf5 import load_model_from_hdf5 from taurex.model import DirectImageModel from taurex.data.profiles.chemistry import TaurexChemistry, ConstantGas from taurex.contributions import AbsorptionContribution, RayleighContribution from taurex.cache import OpacityCache with patch.object(OpacityCache, "find_list_of_molecules") as mock_my_method: mock_my_method.return_value = ['H2O'] chem = TaurexChemistry() chem.addGas(ConstantGas()) tm = DirectImageModel(chemistry=chem, ngauss=10) tm.add_contribution(AbsorptionContribution()) tm.add_contribution(RayleighContribution()) tm.build() tm.initialize_profiles() wngrid = np.linspace(100, 400) tm.star.initialize(wngrid) with patch.object(DirectImageModel, "model") as mock_my_method: mock_my_method = None file_path = self.gen_valid_hdf5_output(tm, 'Test') with h5py.File(file_path, 'r') as f: loaded = load_model_from_hdf5(f['Test']['ModelParameters']) loaded.build() loaded.initialize_profiles() wngrid = np.linspace(100, 400) self.assertTrue(isinstance(loaded, DirectImageModel)) np.testing.assert_array_equal(loaded.densityProfile, tm.densityProfile) truth_contrib = [type(c) for c in tm.contribution_list] loaded_contrib = [type(c) for c in loaded.contribution_list] self.assertTrue(set(truth_contrib) == set(loaded_contrib)) self.assertEqual(tm._ngauss, loaded._ngauss)
def _compute_inital_mu(self): from taurex.data.profiles.chemistry import TaurexChemistry, ConstantGas tc = TaurexChemistry() tc.addGas(ConstantGas('H2O')) self._inital_mu = tc