Example #1
0
def test_eq_vs_noneq_isotope(verbose=True,
                             plot=False,
                             warnings=True,
                             *args,
                             **kwargs):
    ''' Test same spectrum for 2 different calculation codes (equilibrium, 
    non-equilibrium) in the presence of isotopes 
    
    Notes
    -----
    
    On the old NeQ package the test used [HITEMP-2010]_
    
    Starting from RADIS 1.0.1, the test is run on [HITRAN-2016]_, which 
    is not valid for these temperatures but can be more conveniently 
    downloaded automatically and thus executed everytime with [Travis]_
    
    '''

    try:
        Tgas = 1500

        sf = SpectrumFactory(wavelength_min=4250,
                             wavelength_max=4350,
                             mole_fraction=1,
                             path_length=1,
                             cutoff=1e-25,
                             molecule='CO2',
                             isotope='1,2',
                             db_use_cached=True,
                             verbose=verbose)
        sf.warnings['MissingSelfBroadeningWarning'] = 'ignore'
        sf.warnings['NegativeEnergiesWarning'] = 'ignore'
        sf.warnings['HighTemperatureWarning'] = 'ignore'
        sf.fetch_databank(
        )  # uses HITRAN: not really valid at this temperature, but runs on all machines without install
        #        sf.load_databank('HITEMP-CO2-DUNHAM')
        s_nq = sf.non_eq_spectrum(Tvib=Tgas, Trot=Tgas, name='Non-eq')
        s_eq = sf.eq_spectrum(Tgas=Tgas, name='Eq')

        rtol = 5e-3  # 2nd isotope calculated with placeholder energies
        match_eq_vs_non_eq = s_eq.compare_with(s_nq,
                                               spectra_only='abscoeff',
                                               rtol=rtol,
                                               plot=plot)
        match_eq_vs_non_eq *= s_eq.compare_with(s_nq,
                                                spectra_only='radiance_noslit',
                                                rtol=rtol,
                                                plot=plot)

        if verbose:
            printm('Tested eq vs non-eq (<{0:.1f}% error) with isotopes: {1}'.
                   format(rtol * 100, bool(match_eq_vs_non_eq)))

        assert match_eq_vs_non_eq

    except DatabankNotFound as err:
        assert IgnoreMissingDatabase(err, __file__, warnings)
Example #2
0
def test_eq_vs_noneq_isotope(verbose=True,
                             plot=False,
                             warnings=True,
                             *args,
                             **kwargs):
    """Test same spectrum for 2 different calculation codes (equilibrium,
    non-equilibrium) in the presence of isotopes

    Notes
    -----

    On the old NeQ package the test used [HITEMP-2010]_

    Starting from RADIS 1.0.1, the test is run on [HITRAN-2016]_, which
    is not valid for these temperatures but can be more conveniently
    downloaded automatically and thus executed everytime with `Travis CI <https://travis-ci.com/radis/radis>`_

    """

    Tgas = 1500

    sf = SpectrumFactory(
        wavelength_min=4250,
        wavelength_max=4350,
        mole_fraction=1,
        path_length=1,
        cutoff=1e-25,
        molecule="CO2",
        isotope="1,2",
        db_use_cached=True,
        verbose=verbose,
    )
    sf.warnings["MissingSelfBroadeningWarning"] = "ignore"
    sf.warnings["NegativeEnergiesWarning"] = "ignore"
    sf.warnings["HighTemperatureWarning"] = "ignore"
    sf.fetch_databank(
    )  # uses HITRAN: not really valid at this temperature, but runs on all machines without install
    #        sf.load_databank('HITEMP-CO2-DUNHAM')
    s_nq = sf.non_eq_spectrum(Tvib=Tgas, Trot=Tgas, name="Non-eq")
    s_eq = sf.eq_spectrum(Tgas=Tgas, name="Eq")

    rtol = 5e-3  # 2nd isotope calculated with placeholder energies
    match_eq_vs_non_eq = s_eq.compare_with(s_nq,
                                           spectra_only="abscoeff",
                                           rtol=rtol,
                                           plot=plot)
    match_eq_vs_non_eq *= s_eq.compare_with(s_nq,
                                            spectra_only="radiance_noslit",
                                            rtol=rtol,
                                            plot=plot)

    if verbose:
        printm(
            "Tested eq vs non-eq (<{0:.1f}% error) with isotopes: {1}".format(
                rtol * 100, bool(match_eq_vs_non_eq)))

    assert match_eq_vs_non_eq
Example #3
0
def test_plot_all_CO2_bandheads(verbose=True, plot=False, *args, **kwargs):
    """In this test we use the :meth:`~radis.lbl.bands.BandFactory.non_eq_bands`
    method to calculate separately all vibrational bands of CO2, and compare
    them with the final Spectrum.

    """

    # Note: only with iso1 at the moment

    if plot:  # Make sure matplotlib is interactive so that test are not stuck in pytest
        plt.ion()

    Tgas = 1000

    sf = SpectrumFactory(
        wavelength_min=4160,
        wavelength_max=4220,
        mole_fraction=1,
        path_length=0.3,
        cutoff=1e-23,
        molecule="CO2",
        isotope=1,
        optimization=None,
        verbose=verbose,
    )
    sf.warnings["MissingSelfBroadeningWarning"] = "ignore"
    sf.warnings["NegativeEnergiesWarning"] = "ignore"
    sf.warnings["HighTemperatureWarning"] = "ignore"
    sf.fetch_databank("hitran")

    s_tot = sf.non_eq_spectrum(Tvib=Tgas, Trot=Tgas)
    s_bands = sf.non_eq_bands(Tvib=Tgas, Trot=Tgas)

    if verbose:
        printm("{0} bands in spectrum".format(len(s_bands)))

    assert len(s_bands) == 6

    # Ensure that recombining gives the same
    s_merged = MergeSlabs(*list(s_bands.values()))
    assert s_tot.compare_with(s_merged, "radiance_noslit", plot=False)

    if verbose:
        printm("Recombining bands give the same Spectrum")

    # %%
    if plot:
        s_tot.apply_slit(1, "nm")
        s_tot.name = "Full spectrum"
        s_tot.plot(wunit="nm", lw=3)
        for band, s in s_bands.items():
            s.plot(wunit="nm", nfig="same")
        plt.legend(loc="upper left")
        plt.ylim(ymax=0.25)

    # %% Compare with equilibrium bands now
    s_bands_eq = sf.eq_bands(Tgas)
    s_merged_eq = MergeSlabs(*list(s_bands_eq.values()))

    assert get_residual(s_tot, s_merged_eq, "radiance_noslit") < 1.5e-5

    return True
Example #4
0
def test_plot_all_CO2_bandheads(verbose=True, plot=False, *args, **kwargs):
    ''' In this test we use the :meth:`~radis.lbl.bands.BandFactory.non_eq_bands`
    method to calculate separately all vibrational bands of CO2, and compare
    them with the final Spectrum. 

    '''

    # Note: only with iso1 at the moment

    if plot:  # Make sure matplotlib is interactive so that test are not stuck in pytest
        plt.ion()

    verbose = True
    Tgas = 1000

    sf = SpectrumFactory(wavelength_min=4160,
                         wavelength_max=4220,
                         mole_fraction=1,
                         path_length=0.3,
                         cutoff=1e-23,
                         molecule='CO2',
                         isotope=1,
                         db_use_cached=True,
                         lvl_use_cached=True,
                         verbose=verbose)
    sf.warnings['MissingSelfBroadeningWarning'] = 'ignore'
    sf.warnings['NegativeEnergiesWarning'] = 'ignore'
    sf.warnings['HighTemperatureWarning'] = 'ignore'
    sf.fetch_databank()

    s_tot = sf.non_eq_spectrum(Tvib=Tgas, Trot=Tgas)
    s_bands = sf.non_eq_bands(Tvib=Tgas, Trot=Tgas)

    if verbose:
        printm('{0} bands in spectrum'.format(len(s_bands)))

    assert len(s_bands) == 6

    # Ensure that recombining gives the same
    s_merged = MergeSlabs(*list(s_bands.values()))
    assert s_tot.compare_with(s_merged, 'radiance_noslit', plot=False)

    if verbose:
        printm('Recombining bands give the same Spectrum')

    # %%
    if plot:
        s_tot.apply_slit(1, 'nm')
        s_tot.name = 'Full spectrum'
        s_tot.plot(wunit='nm', lw=3)
        for band, s in s_bands.items():
            s.plot(wunit='nm', nfig='same')
        plt.legend(loc='upper left')
        plt.ylim(ymax=0.25)

    # %% Compare with equilibrium bands now
    s_bands_eq = sf.eq_bands(Tgas)
    s_merged_eq = MergeSlabs(*list(s_bands_eq.values()))

    assert get_residual(s_tot, s_merged_eq, 'radiance_noslit') < 1e-5

    return True