예제 #1
0
def test_pyrat_emission_str(tmp_path):
    cfg = make_config(tmp_path,
                      ROOT + 'tests/configs/spectrum_transmission_test.cfg',
                      reset={'rt_path': 'emission'})
    pyrat = pb.run(cfg)
    assert pyrat is not None
    assert str(pyrat.spec) == """\
Spectral information:
Wavenumber internal units: cm-1
Wavelength internal units: cm
Wavelength display units (wlunits): um
Low wavenumber boundary (wnlow):     5882.353 cm-1  (wlhigh =   1.70 um)
High wavenumber boundary (wnhigh):   9090.909 cm-1  (wllow  =   1.10 um)
Number of samples (nwave): 3209
Sampling interval (wnstep): 1.000 cm-1
Wavenumber array (wn, cm-1):
    [ 5882.353  5883.353  5884.353 ...  9088.353  9089.353  9090.353]
Oversampling factor (wnosamp): 2160

Intensity zenithal angles (raygrid, degree): [ 0. 20. 40. 60. 80.]
raygrid internal units: radian
Intensity spectra (intensity, erg s-1 cm-2 sr-1 cm):
    [ 7.741e+02  7.734e+02  7.727e+02 ...  3.549e+01  3.545e+01  3.542e+01]
    [ 7.741e+02  7.734e+02  7.727e+02 ...  3.549e+01  3.545e+01  3.542e+01]
    [ 7.741e+02  7.734e+02  7.727e+02 ...  3.549e+01  3.545e+01  3.542e+01]
    [ 7.741e+02  7.734e+02  7.727e+02 ...  3.549e+01  3.545e+01  3.542e+01]
    [ 7.741e+02  7.734e+02  7.727e+02 ...  3.549e+01  3.545e+01  3.542e+01]
Emission spectrum (spectrum, erg s-1 cm-2 cm):
    [ 2.432e+03  2.430e+03  2.428e+03 ...  1.115e+02  1.114e+02  1.113e+02]
"""

    assert str(pyrat.od) == """\
예제 #2
0
def test_transmission_patchy(tmp_path):
    cfg = make_config(tmp_path,
                      ROOT + 'tests/configs/spectrum_transmission_test.cfg',
                      reset={
                          'fpatchy': '0.5',
                          'rpars': '10.0 -15.0'
                      })
    pyrat = pb.run(cfg)
    np.testing.assert_allclose(pyrat.spec.spectrum,
                               expected['patchy'],
                               rtol=rtol)
    np.testing.assert_allclose(pyrat.spec.clear,
                               expected['patchy_clear'],
                               rtol=rtol)
    np.testing.assert_allclose(pyrat.spec.cloudy,
                               expected['patchy_cloudy'],
                               rtol=rtol)

    pyrat.cloud.fpatchy = 0.0
    pyrat.run()
    np.testing.assert_allclose(pyrat.spec.spectrum,
                               expected['patchy_clear'],
                               rtol=rtol)

    pyrat.cloud.fpatchy = 1.0
    pyrat.run()
    np.testing.assert_allclose(pyrat.spec.spectrum,
                               expected['patchy_cloudy'],
                               rtol=rtol)
예제 #3
0
def test_missing_mass_units(tmp_path, capfd):
    cfg = make_config(tmp_path, ROOT+'tests/configs/pt_tcea.cfg',
        reset={'mplanet':'1.0'})
    pyrat = pb.run(cfg)
    assert pyrat is None
    captured = capfd.readouterr()
    assert "Invalid units 'None' for parameter mplanet." in captured.out
예제 #4
0
def test_transmission_deck(tmp_path):
    cfg = make_config(tmp_path,
                      ROOT + 'tests/configs/spectrum_transmission_test.cfg',
                      remove=['tlifile', 'csfile', 'rayleigh', 'alkali'])
    pyrat = pb.run(cfg)
    np.testing.assert_allclose(pyrat.spec.spectrum,
                               expected['deck'],
                               rtol=rtol)
예제 #5
0
def test_units_separate(tmp_path):
    cfg = make_config(tmp_path,
                      ROOT + 'tests/configs/pt_isothermal.cfg',
                      reset={
                          'mplanet': '1.0',
                          'mpunits': 'mjup'
                      })
    pressure, temperature, abundances, species, radius = pb.run(cfg)
예제 #6
0
def test_lower_equal(tmp_path, capfd, param):
    cfg = make_config(tmp_path, ROOT+'tests/configs/pt_isothermal.cfg',
        reset={param:'1.1'})
    pyrat = pb.run(cfg)
    assert pyrat is None
    captured = capfd.readouterr()
    assert "Error in module: 'parser.py', function: 'parse'" in captured.out
    assert "({:s}) must be <= ".format(param) in captured.out
예제 #7
0
def test_invalid_file_path(tmp_path, capfd, param, invalid_path):
    cfg = make_config(tmp_path, ROOT+'tests/configs/pt_isothermal.cfg',
        reset={param:'nope/file.dat'})
    pyrat = pb.run(cfg)
    captured = capfd.readouterr()
    assert pyrat is None
    assert "Error in module: 'parser.py', function: 'parse'" in captured.out
    assert invalid_path[param] in captured.out
예제 #8
0
def test_greater_than(tmp_path, capfd, param, value):
    cfg = make_config(tmp_path, ROOT+'tests/configs/pt_tcea.cfg',
        reset={param:value})
    pyrat = pb.run(cfg)
    assert pyrat is None
    captured = capfd.readouterr()
    assert "Error in module: 'parser.py', function: 'parse'" in captured.out
    assert "({:s}) must be > ".format(param) in captured.out
예제 #9
0
def test_atmosphere_missing_species(tmp_path, capfd, undefined, chem):
    cfg = make_config(tmp_path,
        f'{ROOT}tests/configs/atmosphere_{chem}_test.cfg',
        remove=['species'])
    pyrat = pb.run(cfg)
    assert pyrat is None
    captured = capfd.readouterr()
    assert "Error in module: 'driver.py', function: 'check_atm'" in captured.out
    assert undefined['species'] in captured.out
예제 #10
0
def test_pt_temperature_missing(tmp_path, capfd, param, undefined):
    cfg = make_config(tmp_path, ROOT+'tests/configs/pt_isothermal.cfg',
        remove=[param])
    pyrat = pb.run(cfg)
    assert pyrat is None
    captured = capfd.readouterr()
    assert "Error in module: 'driver.py', function: 'check_temp'" \
           in captured.out
    assert undefined[param] in captured.out
예제 #11
0
def test_pressure_invalid_units(tmp_path, capfd, param):
    cfg = make_config(tmp_path, ROOT+'tests/configs/pt_isothermal.cfg',
        reset={param:'10.0 20.0'})
    pyrat = pb.run(cfg)
    captured = capfd.readouterr()
    assert pyrat is None
    assert "Error in module: 'parser.py', function: 'parse'" in captured.out
    assert f"Invalid units for value '10.0 20.0' for parameter {param}." \
           in captured.out
예제 #12
0
def test_units_in_value_invalid(tmp_path, capfd):
    cfg = make_config(tmp_path,
                      ROOT + 'tests/configs/pt_isothermal.cfg',
                      reset={'mplanet': '1.0 nope'})
    pyrat = pb.run(cfg)
    assert pyrat is None
    captured = capfd.readouterr()
    assert "Invalid units for value '1.0 nope' for parameter mplanet." \
        in captured.out
예제 #13
0
def test_spectrum_emission(tmp_path):
    cfg = make_config(tmp_path,
                      ROOT + 'tests/configs/spectrum_transmission_test.cfg',
                      reset={
                          'rt_path': 'emission',
                          'cpars': '-0.5'
                      })
    pyrat = pb.run(cfg)
    assert pyrat is not None
예제 #14
0
def test_invalid_float_all_params(tmp_path, capfd, param):
    cfg = make_config(tmp_path, ROOT+'tests/configs/pt_isothermal.cfg',
        reset={param:'abc'})
    pyrat = pb.run(cfg)
    captured = capfd.readouterr()
    assert pyrat is None
    assert "Error in module: 'parser.py', function: 'parse'" in captured.out
    assert ("Invalid data type for {:s}, could not convert string to "
            "float: 'abc'".format(param)) in captured.out
예제 #15
0
def test_atmosphere_tea_missing_elements(tmp_path, capfd, undefined):
    cfg = make_config(tmp_path,
        ROOT+'tests/configs/atmosphere_tea_test.cfg',
        remove=['elements'])
    pyrat = pb.run(cfg)
    assert pyrat is None
    captured = capfd.readouterr()
    assert "Error in module: 'driver.py', function: 'check_atm'" in captured.out
    assert undefined['elements'] in captured.out
예제 #16
0
def test_transmission_clear(tmp_path):
    # No opacity whatsoever:
    cfg = make_config(
        tmp_path,
        ROOT + 'tests/configs/spectrum_transmission_test.cfg',
        remove=['tlifile', 'csfile', 'rayleigh', 'alkali', 'clouds'])
    pyrat = pb.run(cfg)
    depth_bottom = (pyrat.atm.radius[-1] / pyrat.phy.rstar)**2
    np.testing.assert_allclose(pyrat.spec.spectrum, depth_bottom, rtol=rtol)
예제 #17
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)
예제 #18
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)
예제 #19
0
def test_transmission_resolution(tmp_path):
    cfg = make_config(tmp_path,
                      ROOT + 'tests/configs/spectrum_transmission_test.cfg',
                      reset={'resolution': '5000.0'},
                      remove=['clouds'])
    pyrat = pb.run(cfg)
    np.testing.assert_allclose(pyrat.spec.spectrum,
                               expected['resolution'],
                               rtol=rtol)
예제 #20
0
def test_pressure_invalid_type(tmp_path, capfd, param, value):
    cfg = make_config(tmp_path, ROOT+'tests/configs/pt_isothermal.cfg',
        reset={param:value})
    pyrat = pb.run(cfg)
    captured = capfd.readouterr()
    assert pyrat is None
    assert "Error in module: 'parser.py', function: 'parse'" in captured.out
    assert "Invalid value '{:s}' for parameter {:s}.". \
           format(value, param) in captured.out
예제 #21
0
def test_molfree_mismatch3(tmp_path, capfd):
    cfg = make_config(tmp_path,
        ROOT+'tests/configs/spectrum_transmission_test.cfg',
        reset={'molmodel':'vert', 'molfree':'N2'})
    pyrat = pb.run(cfg)
    assert pyrat is None
    captured = capfd.readouterr()
    assert "Error in module: 'argum.py', function: 'setup'" in captured.out
    assert "These species are not present in the atmosphere: ['N2']." in captured.out
예제 #22
0
def test_invalid_units(tmp_path, capfd, param, var):
    cfg = make_config(tmp_path, ROOT+'tests/configs/pt_isothermal.cfg',
        reset={param:'invalid'})
    pyrat = pb.run(cfg)
    captured = capfd.readouterr()
    assert pyrat is None
    assert "Error in module: 'parser.py', function: 'parse'" in captured.out
    assert "Invalid {:s} units ({:s}): invalid".format(var, param) \
           in captured.out
예제 #23
0
def test_bulk_molfree_overlap(tmp_path, capfd):
    cfg = make_config(tmp_path,
        ROOT+'tests/configs/spectrum_transmission_test.cfg',
        reset={'molmodel':'vert', 'molfree':'H2', 'bulk':'H2'})
    pyrat = pb.run(cfg)
    assert pyrat is None
    captured = capfd.readouterr()
    assert "Error in module: 'argum.py', function: 'setup'" in captured.out
    assert "These species were marked as both bulk and variable-abundance: ['H2']." in captured.out
예제 #24
0
def test_molfree_mismatch(tmp_path, capfd):
    cfg = make_config(tmp_path,
        ROOT+'tests/configs/spectrum_transmission_test.cfg',
        reset={'molmodel':'vert'})
    pyrat = pb.run(cfg)
    assert pyrat is None
    captured = capfd.readouterr()
    assert "Error in module: 'argum.py', function: 'setup'" in captured.out
    assert "molmodel is set, but there are no molfree." in captured.out
예제 #25
0
def test_opacity_missing(tmp_path, capfd, param, undefined_opacity):
    cfg = make_config(tmp_path, ROOT+'tests/configs/opacity_test.cfg',
        reset={'extfile':str(tmp_path/'new_opacity.dat')},
        remove=[param])
    pyrat = pb.run(cfg)
    assert pyrat is None
    captured = capfd.readouterr()
    assert "Error in module: 'argum.py', function: 'check_spectrum'" \
           in captured.out
    assert undefined_opacity[param] in captured.out
예제 #26
0
def test_kurucz_missing_pars(tmp_path, capfd, param, undefined):
    cfg = make_config(tmp_path,
        ROOT+'tests/configs/spectrum_transmission_test.cfg',
        reset={'kurucz':f'{ROOT}/tests/inputs/fp00k0odfnew.pck'},
        remove=[param])
    pyrat = pb.run(cfg)
    assert pyrat is None
    captured = capfd.readouterr()
    assert "Error in module: 'argum.py', function: 'setup'" in captured.out
    assert undefined[param] in captured.out
예제 #27
0
def test_bulk_not_in_atm(tmp_path, capfd):
    cfg = make_config(tmp_path,
        ROOT+'tests/configs/spectrum_transmission_test.cfg',
        reset={'bulk':'N2'})
    pyrat = pb.run(cfg)
    assert pyrat is None
    captured = capfd.readouterr()
    assert "Error in module: 'argum.py', function: 'setup'" in captured.out
    assert "These bulk species are not present in the atmosphere: ['N2']." \
           in captured.out
예제 #28
0
def test_spectrum_raygrid(tmp_path, capfd, invalid_raygrid, value):
    cfg = make_config(tmp_path,
        ROOT+'tests/configs/spectrum_transmission_test.cfg',
        reset={'raygrid':value})
    pyrat = pb.run(cfg)
    assert pyrat is None
    captured = capfd.readouterr()
    assert "Error in module: 'argum.py', function: 'check_spectrum'" \
           in captured.out
    assert invalid_raygrid[value] in captured.out
예제 #29
0
def test_spectrum_invalid_file(tmp_path, capfd, param, invalid_file):
    cfg = make_config(tmp_path,
        ROOT+'tests/configs/spectrum_transmission_test.cfg',
        reset={param:'nope.dat'})
    pyrat = pb.run(cfg)
    assert pyrat is None
    captured = capfd.readouterr()
    assert "Error in module: 'argum.py', function: 'check_spectrum'" \
           in captured.out
    assert invalid_file[param] in captured.out
예제 #30
0
def test_run_opacity_extfile(tmp_path, capfd, cfile):
    cfg = make_config(tmp_path, f'{ROOT}tests/configs/{cfile}',
        remove=['extfile'])
    pyrat = pb.run(cfg)
    assert pyrat is None
    captured = capfd.readouterr()
    caps = ["Error in module: 'driver.py', function: 'run'",
            "Undefined extinction-coefficient file (extfile)."]
    for cap in caps:
        assert cap in captured.out