Exemplo n.º 1
0
def test_TestBaseline(plot=False, *args, **kwargs):

    s = load_spec(getTestFile("CO_Tgas1500K_mole_fraction0.01.spec"), binary=True)
    s.update("radiance_noslit", verbose=False)
    s.apply_slit(0.1)
    s = Radiance_noslit(s)
    assert s.units["radiance"] == "mW/cm2/sr/nm"

    s2 = sub_baseline(s, 2e-4, -2e-4)
    if plot:
        plot_diff(s, s2)
    assert s2.get_radiance_noslit()[-1] == s.get_radiance_noslit()[-1] + 2e-4
    assert s2.get_radiance_noslit()[0] == s.get_radiance_noslit()[0] - 2e-4
Exemplo n.º 2
0
def test_dimensioned_operations(*args, **kwargs):

    import astropy.units as u
    import numpy as np

    from radis import Radiance, load_spec
    from radis.spectrum import sub_baseline
    from radis.test.utils import getTestFile

    # Generate the equivalent of an experimental spectrum
    s = load_spec(getTestFile(r"CO_Tgas1500K_mole_fraction0.01.spec"),
                  binary=True)
    s.update()  # add radiance, etc.
    s.apply_slit(0.5)  # nm
    s = Radiance(s)

    # Test
    assert s.units["radiance"] == "mW/cm2/sr/nm"
    Imax = s.get("radiance")[1].max()

    # add a baseline
    s += 0.1 * u.Unit("W/cm2/sr/nm")

    assert np.isclose(s.get("radiance")[1].max(), Imax + 100)

    # remove a baseline (we could also have used s=-0.1, but we're testing another function here)
    s = sub_baseline(s, 0.1 * u.Unit("W/cm2/sr/nm"),
                     0.1 * u.Unit("W/cm2/sr/nm"))

    assert np.isclose(s.get("radiance")[1].max(), Imax)

    # Test division
    # Example : a manual normalization
    s /= s.max() * u.Unit("mW/cm2/sr/nm")

    assert s.units["radiance"] == ""  # normalized
    assert s.max() == 1.0

    # Test Multiplication
    # example : a manual Calibration
    s.units["radiance"] = "count"
    s *= 100 * u.Unit("mW/cm2/sr/nm/count")

    assert u.Unit(s.units["radiance"]) == u.Unit(
        "mW/cm2/sr/nm")  # check units are valid
    assert s.units[
        "radiance"] == "mW / (cm2 nm sr)"  # check units have been simplified