Пример #1
0
def test_read_write_atm_ptqr(tmpdir):
    atmfile = "WASP-00b.atm"
    atm = "{}/{}".format(tmpdir, atmfile)
    nlayers = 11
    pressure = pa.pressure('1e-8 bar', '1e2 bar', nlayers)
    temperature = pa.tmodels.Isothermal(nlayers)(1500.0)
    species = ["H2", "He", "H2O", "CO", "CO2", "CH4"]
    abundances = [0.8496, 0.15, 1e-4, 1e-4, 1e-8, 1e-4]
    qprofiles = pa.uniform(pressure, temperature, species, abundances)
    radius = pa.hydro_g(pressure, temperature, 2.3, 2479.0, pc.bar, pc.rjup)
    io.write_atm(atm,
                 pressure,
                 temperature,
                 species,
                 qprofiles,
                 radius=radius,
                 punits='bar',
                 runits='km',
                 header='# Test write atm\n')
    assert atmfile in os.listdir(str(tmpdir))

    atm_input = io.read_atm(atm)
    assert atm_input[0] == ('bar', 'kelvin', 'volume', 'km')
    np.testing.assert_equal(atm_input[1], np.array(species))
    np.testing.assert_allclose(atm_input[2], pressure / pc.bar)
    np.testing.assert_allclose(atm_input[3], temperature)
    np.testing.assert_allclose(atm_input[4], qprofiles)
    np.testing.assert_allclose(atm_input[5], radius / pc.km, rtol=1e-5)
Пример #2
0
def test_transmission_input_radius_overwrite(tmp_path):
    cfg = make_config(
        tmp_path,
        ROOT + 'tests/configs/spectrum_transmission_test.cfg',
        reset={'atmfile': f'{INPUTS}/atmosphere_uniform_radius.atm'})
    pyrat = pb.run(cfg)
    atm = io.read_atm('inputs/atmosphere_uniform_radius.atm')
    np.testing.assert_raises(AssertionError, np.testing.assert_array_equal,
                             pyrat.atm.radius, atm[5] * pc.km)
Пример #3
0
def test_transmission_input_radius(tmp_path):
    cfg = make_config(
        tmp_path,
        ROOT + 'tests/configs/spectrum_transmission_test.cfg',
        reset={'atmfile': f'{INPUTS}atmosphere_uniform_radius.atm'},
        remove=['radmodel'])
    pyrat = pb.run(cfg)
    atm = io.read_atm('inputs/atmosphere_uniform_radius.atm')
    np.testing.assert_allclose(pyrat.atm.radius, atm[5] * pc.km, rtol=rtol)
Пример #4
0
def test_transmission_qmass_input():
    # This is the gist of it, prepare a qmass atmospheric file:
    atm = io.read_atm('inputs/atmosphere_uniform_test.atm')
    units, species, press, temp, q = atm
    symbol, mass, diam = io.read_molecs(pc.ROOT +
                                        "pyratbay/data/molecules.dat")
    mm = pa.mean_weight(q, species)
    qmass = qprofiles * molmass / mm
    io.write_atm(atmfile)
    # Then run spectrum, results must be the same as qnumber run:
    pyrat = pb.run(ROOT + 'tests/configs/spectrum_transmission_qmass_test.cfg')
    np.testing.assert_allclose(pyrat.spec.spectrum, expected['all'], rtol=rtol)
Пример #5
0
def test_atmosphere_hydro_default_runits(tmp_path):
    atmfile = str(tmp_path / 'test.atm')
    cfg = make_config(tmp_path,
                      ROOT + 'tests/configs/atmosphere_hydro_test.cfg',
                      reset={
                          'atmfile': atmfile,
                          'gplanet': '2478.7504116251885'
                      },
                      remove=['rplanet'])

    press, temp, abund, species, radius = pb.run(cfg)
    np.testing.assert_allclose(radius, expected_radius, rtol=1e-7)
    atmf = io.read_atm(atmfile)
    assert atmf[0] == ('bar', 'kelvin', 'volume', 'rjup')
    np.testing.assert_allclose(atmf[5] * pc.rjup, expected_radius, rtol=5e-5)
Пример #6
0
def test_read_write_atm_pt(tmpdir):
    atmfile = "WASP-00b.atm"
    atm = "{}/{}".format(tmpdir, atmfile)
    nlayers = 11
    pressure = pa.pressure('1e-8 bar', '1e2 bar', nlayers)
    temperature = pa.tmodels.Isothermal(nlayers)(1500.0)
    io.write_atm(atm, pressure, temperature, punits='bar')
    assert atmfile in os.listdir(str(tmpdir))

    atm_input = io.read_atm(atm)
    assert atm_input[0] == ('bar', 'kelvin', None, None)
    assert atm_input[1] is None
    np.testing.assert_allclose(atm_input[2], pressure / pc.bar)
    np.testing.assert_allclose(atm_input[3], temperature)
    assert atm_input[4] is None
    assert atm_input[5] is None
Пример #7
0
def test_molecule_not_in_molfile(tmp_path, capfd):
    # Modify atm:
    units, species, press, temp, q, rad = \
        io.read_atm(ROOT+'tests/inputs/atmosphere_uniform_test.atm')
    press = press * pb.tools.u(units[0])
    species[-1] = 'X'
    new_atm = str(tmp_path/'new_atmosphere_uniform_test.atm')
    io.write_atm(new_atm, press, temp, species, q, punits=units[0])

    cfg = make_config(tmp_path,
        ROOT+'tests/configs/spectrum_transmission_test.cfg',
        reset={'atmfile':new_atm})
    pyrat = pb.run(cfg)
    assert pyrat is None
    captured = capfd.readouterr()
    assert "Error in module: 'read_atm.py', function: 'get_constants'" \
           in captured.out
    assert "These species: ['X'] are not listed in the molecules info file" \
           in captured.out
Пример #8
0
def test_atmosphere_tea(tmp_path):
    atmfile = str(tmp_path / 'test.atm')
    cfg = make_config(tmp_path,
                      ROOT + 'tests/configs/atmosphere_tea_test.cfg',
                      reset={'atmfile': atmfile})

    press, temp, abund, species, radius = pb.run(cfg)
    np.testing.assert_allclose(press, expected_pressure, rtol=1e-7)
    np.testing.assert_allclose(temp, expected_temperature, atol=1e-7)
    np.testing.assert_allclose(abund, expected_abundance, rtol=1e-7)
    # Compare against the atmospheric file now:
    atmf = io.read_atm(atmfile)
    assert atmf[0] == ('bar', 'kelvin', 'volume', None)
    np.testing.assert_equal(
        atmf[1], np.array('H2 He Na K H2O CH4 CO CO2 NH3 HCN N2'.split()))
    # File read-write loses precision:
    np.testing.assert_allclose(atmf[2] * pc.bar, expected_pressure, rtol=3e-5)
    np.testing.assert_allclose(atmf[3], expected_temperature, rtol=5e-6)
    np.testing.assert_allclose(atmf[4], expected_abundance, rtol=1e-7)
Пример #9
0
def test_atmosphere_uniform(tmp_path):
    atmfile = str(tmp_path / 'test.atm')
    cfg = make_config(tmp_path,
                      ROOT + 'tests/configs/atmosphere_uniform_test.cfg',
                      reset={'atmfile': atmfile})

    press, temp, abund, species, radius = pb.run(cfg)
    np.testing.assert_allclose(press, expected_pressure, rtol=1e-7)
    np.testing.assert_allclose(temp, expected_temperature, rtol=1e-7)
    q = np.tile([0.85, 0.149, 3.0e-6, 4.0e-4, 1.0e-4, 5.0e-4, 1.0e-7], (81, 1))
    np.testing.assert_equal(abund, q)
    # Compare against the atmospheric file now:
    atm = io.read_atm(atmfile)
    assert atm[0] == ('bar', 'kelvin', 'volume', None)
    np.testing.assert_equal(atm[1],
                            np.array('H2 He Na H2O CH4 CO CO2'.split()))
    # File read-write loses precision:
    np.testing.assert_allclose(atm[2] * pc.bar, expected_pressure, rtol=3e-5)
    np.testing.assert_allclose(atm[3], expected_temperature, rtol=1e-6)
    np.testing.assert_equal(atm[4], q)
Пример #10
0
def test_read_atm_no_temp():
    match = "Atmospheric file does not have '@TEMPERATURE' header"
    with pytest.raises(ValueError, match=match):
        dummy = io.read_atm('inputs/uniform_notemp_test.atm')
Пример #11
0
import os

import numpy as np
import matplotlib.pyplot as plt

import pyratbay as pb
import pyratbay.atmosphere as pa
import pyratbay.io as io
import pyratbay.tools as pt
import mc3

# Indices for species in atmosphere:
units, specs, press, temp, q, rad = io.read_atm(
    'run_setup/isothermal_1500K_uniform.atm')
iHe = np.where(specs == 'He')[0][0]
iH2 = np.where(specs == 'H2')[0][0]
iH = np.where(specs == 'H')[0][0]
iH2O = np.where(specs == 'H2O')[0][0]
iCH4 = np.where(specs == 'CH4')[0][0]
iHCN = np.where(specs == 'HCN')[0][0]


def ZX(params, pyrat):
    Zsun = 0.0134  # Asplund et al. 2009
    Xsun = 0.7381
    q2 = pa.qscale(pyrat.atm.qbase,
                   pyrat.mol.name,
                   pyrat.atm.molmodel,
                   pyrat.atm.molfree,
                   params[pyrat.ret.imol],
                   pyrat.atm.bulk,