def test_calc_spectrum_multiple_molecules_inputerror( verbose=True, plot=True, warnings=True, *args, **kwargs ): """Test calculations with multiple molecules Note: try to keep the same wavelength ranges for each of the multi-molecule tests, so that databases are only downloaded once, and cached!""" # Contradictory: with pytest.raises(ValueError): calc_spectrum( wavelength_min=4165, wavelength_max=5000, Tgas=1000, path_length=0.1, molecule=["CO2"], # contradictory mole_fraction=1, isotope={"CO2": "1,2", "CO": "1,2,3"}, verbose=verbose, ) # Partial: with pytest.raises(ValueError): calc_spectrum( wavelength_min=4165, wavelength_max=5000, Tgas=1000, path_length=0.1, molecule=["CO2", "CO"], # contradictory mole_fraction=1, isotope={"CO2": "1,2"}, # unclear for CO verbose=verbose, ) return True
def test_calc_spectrum_multiple_molecules_otherinputs(verbose=True, plot=True, warnings=True, *args, **kwargs): """Test calculations with differnet kind of inputs for multiple molecules Note: try to keep the same wavelength ranges for each of the multi-molecule tests, so that databases are only downloaded once, and cached!""" # Give molecule: s = calc_spectrum( wavelength_min=4165, wavelength_max=5000, Tgas=1000, path_length=0.1, molecule=["CO2", "CO"], mole_fraction=1, isotope={ "CO2": "1,2", "CO": "1,2,3" }, verbose=verbose, ) assert set(s.conditions["molecule"]) == set(["CO2", "CO"]) # Give isotope only s = calc_spectrum( wavelength_min=4165, wavelength_max=5000, Tgas=1000, path_length=0.1, isotope={ "CO2": "1,2", "CO": "1,2,3" }, verbose=verbose, ) assert set(s.conditions["molecule"]) == set(["CO2", "CO"]) # Give mole fractions only s = calc_spectrum( wavelength_min=4165, wavelength_max=5000, Tgas=1000, path_length=0.1, mole_fraction={ "CO2": 0.2, "CO": 0.8 }, isotope="1,2", verbose=verbose, ) assert set(s.conditions["molecule"]) == set(["CO2", "CO"]) return True
def test_calc_spectrum_multiple_molecules(verbose=True, plot=True, warnings=True, *args, **kwargs): """Test calculations with multiple molecules Note: try to keep the same wavelength ranges for each of the multi-molecule tests, so that databases are only downloaded once, and cached!""" s_co = calc_spectrum( wavelength_min=4165, wavelength_max=5000, Tgas=1000, path_length=0.1, mole_fraction=1, isotope={"CO": "1,2,3"}, verbose=verbose, ) s_co2 = calc_spectrum( wavelength_min=4165, wavelength_max=5000, Tgas=1000, path_length=0.1, mole_fraction=1, isotope={"CO2": "1,2"}, verbose=verbose, ) s_both = calc_spectrum( wavelength_min=4165, wavelength_max=5000, Tgas=1000, path_length=0.1, mole_fraction=1, isotope={ "CO2": "1,2", "CO": "1,2,3" }, verbose=verbose, ) if plot: s_both.plot(wunit="nm") # Check calculation went fine: assert set(s_both.conditions["molecule"]) == set(["CO2", "CO"]) # Compare from radis.los.slabs import MergeSlabs assert s_both.compare_with(MergeSlabs(s_co, s_co2), plot=False) return True
def check_wavelength_range(verbose=True, warnings=True, *args, **kwargs): """Check that input wavelength is correctly taken into account. See https://github.com/radis/radis/issues/214 """ if verbose: printm("Testing calc_spectrum wavelength range") wstep = 0.01 s = calc_spectrum( wavelength_min=4348, # nm wavelength_max=5000, molecule="CO", isotope="1,2,3", pressure=1.01325, # bar Tvib=1700, # K Trot=1700, # K databank="HITRAN-CO-TEST", wstep=wstep, ) w, I = s.get("radiance_noslit", wunit="nm", Iunit="mW/sr/cm2/nm") assert np.isclose(w.min(), 4348, atol=wstep) assert np.isclose(w.max(), 5000, atol=wstep) return True
def test_calc_spectrum(verbose=True, plot=True, warnings=True, *args, **kwargs): """ Basic example, used as a non-regression test Notes ----- How long it tooks to calculate this Spectrum? Performance test on old NeQ package, with the [CDSD-HITEMP-JMIN] databank. See the caveats in the E. Pannier "Limits of CO2 NonEquilibrium Models" paper. (just used here as a performance monitoring) - neq 0.9.20: 18.7s - neq 0.9.20*: 15.4s (removed 2nd loop on 1st isotope because of groupby().apply()) - neq 0.9.20**: 11.7s (after replacing fill_Evib with map() ) - neq 0.9.21: 9.4s (improve Qrot / nrot fetching performance) - neq 0.9.22: 8.4s 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]_ (we also expect the test to be much faster than above, but that's just because the database is smaller!) - radis 0.9.20 : 2.49 s on [HITRAN-2016] 4.05 s on [CDSD-HITEMP-JMIN] """ if verbose: printm("Testing calc_spectrum match reference") if plot: # Make sure matplotlib is interactive so that test are not stuck in pytest import matplotlib.pyplot as plt plt.ion() try: s = calc_spectrum( wavelength_min=4165, wavelength_max=4200, # databank='CDSD-HITEMP-JMIN', databank="fetch", # not appropriate for these temperatures, but convenient for automatic testing Tgas=300, Tvib=1700, Trot=1550, path_length=0.1, mole_fraction=0.5, molecule="CO2", isotope="1,2", wstep=0.01, cutoff=1e-25, use_cached=True, medium="vacuum", verbose=verbose, warnings={ "MissingSelfBroadeningWarning": "ignore", "NegativeEnergiesWarning": "ignore", "HighTemperatureWarning": "ignore", }, ) s.apply_slit((2, 2.5), "nm", shape="trapezoidal") if plot: s.plot(wunit="nm") w, I = s.get("radiance", wunit="nm") w_ref = w[::100] # Compare against hardcoded results (neq 0.9.22, 28/06/18) # I_ref = np.array([0.28694463, 0.29141711, 0.32461613, 0.32909566, 0.21939511, 0.18606445, # 0.19740763, 0.16948599, 0.16780345, 0.15572173, 0.16770853, 0.14966064, # 0.13041356, 0.11751016, 0.10818072, 0.11592531, 0.04666677, 0.00177108, # 0.00069339]) # Harcoded results changed for RADIS with the change of # database (HITEMP-2010 -> HITRAN-2016) and of Tvib model # CDSD with (P,C,Jmin,N) in CDSD polyad -> RADIS built-in constants) # I_ref = np.array([ 0.29148768, 0.29646856, 0.32999337, 0.32249701, 0.2078451 , # 0.18974631, 0.2019285 , 0.17346687, 0.17211401, 0.15939359, # 0.17240575, 0.15395179, 0.13374185, 0.11997065, 0.10858693, # 0.11114162, 0.04575873, 0.00163863, 0.00062654]) # Updated again in RADIS 0.9.20 (19/08/19) to account for the use of DLM (difference # not significant) # I_ref = np.array([ 0.29060991, 0.29756722, 0.32972058, 0.3206278 , 0.20696867, # 0.19218358, 0.20155747, 0.17336405, 0.17218653, 0.1589136 , # 0.17110649, 0.15403513, 0.13376804, 0.11932659, 0.10882006, # 0.11112725, 0.0458288 , 0.00247956, 0.00144128]) # Updated again in RADIS 0.9.20 (02/09/19) with switch to tabulated Q(Tref) I_ref = np.array( [ 0.29048064, 0.29743104, 0.32955513, 0.32047172, 0.20688813, 0.19210952, 0.20148265, 0.17330909, 0.17213373, 0.15887159, 0.17106096, 0.15400039, 0.13374285, 0.11930822, 0.10880631, 0.11111394, 0.04582291, 0.00247955, 0.00144128, ] ) if plot: plt.plot(w_ref, I_ref, "or", label="ref") plt.legend() assert np.allclose(I[::100], I_ref, atol=1e-6) return True except DatabankNotFound as err: assert IgnoreMissingDatabase(err, __file__, warnings)
def test_calc_spectrum_overpopulations( verbose=True, plot=False, warnings=True, *args, **kwargs ): """ Non-regression test: Example using overpopulation of the 001 asymmetric stretch first level of CO2, which is written (p,c,N) = (3,1,4) in [CDSD-4000]_ notation Notes ----- In old Neq package (before RADIS): the test uses a CDSD-PCN notation for vibrational energy assignation, i.e, Evib = minimal energy of a (p,c,N) polyad. See the discussion on the implications in the E. Pannier "Limits of CO2 NonEquilibrium models" paper. Better use the assignation scheme suggested in the paper. But it's okay here as a non-regression test. 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]_ """ if plot: # Make sure matplotlib is interactive so that test are not stuck in pytest import matplotlib.pyplot as plt plt.ion() try: s = calc_spectrum( wavelength_min=4165, wavelength_max=4200, # databank='CDSD-HITEMP-PCN', databank="fetch", # not appropriate for these temperatures, but convenient for automatic testings Tgas=300, Tvib=1700, Trot=1550, # overpopulation={'(3,1,4)': 3}, # 00'0'1 in spectroscopic notation overpopulation={"(0,0,0,1)": 3}, # 00'0'1 in spectroscopic notation path_length=0.1, mole_fraction=0.5, molecule="CO2", isotope="1,2", wstep=0.01, cutoff=1e-25, use_cached=True, medium="vacuum", verbose=verbose, warnings={ "MissingSelfBroadeningWarning": "ignore", "NegativeEnergiesWarning": "ignore", "HighTemperatureWarning": "ignore", }, ) s.apply_slit((2, 2.5), "nm", shape="trapezoidal") if plot: s.plot() w, I = s.get("radiance", wunit="nm") w_ref = w[::100] # Compare against hardcoded results (neq 0.9.22, 28/06/18) # I_ref = np.array([0.61826008, 0.65598262, 0.79760003, 0.7958013 , 0.5792486 , # 0.56727691, 0.60361258, 0.51549598, 0.51012651, 0.47133131, # 0.50770568, 0.45093953, 0.39129824, 0.35125324, 0.32238316, # 0.34542781, 0.13908073, 0.00506012, 0.00189535]) # Harcoded results changed for RADIS v1.0.1 with the change of # database (HITEMP-2010 -> HITRAN-2016) and of Tvib model # CDSD with (P,C,Jmin,N) in CDSD polyad -> RADIS built-in constants) # # I_ref = np.array([ 0.62299838, 0.66229013, 0.81037059, 0.79899315, 0.57215806, # 0.57626389, 0.61424273, 0.52454807, 0.5200812 , 0.47920924, # 0.51843533, 0.46058817, 0.3983277 , 0.35582979, 0.32095204, # 0.32821575, 0.13525543, 0.00469489, 0.00174166]) # Updated again in RADIS 0.9.20 (16/08/19) to account for the use of DLM (difference # not significant) # I_ref = np.array([ 0.62134142, 0.66722021, 0.81016539, 0.79387937, 0.56974945, # 0.58280035, 0.6120114 , 0.52319075, 0.5193041 , 0.47686282, # 0.51374777, 0.46022548, 0.3979033 , 0.3534643 , 0.32129239, # 0.32786479, 0.1351593 , 0.0068877 , 0.00387545]) # Updated again in RADIS 0.9.20 (02/09/19) with switch to tabulated Q(Tref) I_ref = np.array( [ 0.62109562, 0.66695661, 0.80983176, 0.79356445, 0.56958189, 0.58264143, 0.61185167, 0.52307454, 0.51919288, 0.47677519, 0.51365307, 0.46015383, 0.39785172, 0.35342697, 0.32126465, 0.32783797, 0.13514737, 0.00688769, 0.00387544, ] ) if plot: plt.plot(w_ref, I_ref, "or", label="ref") plt.legend() s.plot_populations() assert np.allclose(I[::100], I_ref, atol=1e-6) if verbose: printm("Test overpopulations: OK") return True except DatabankNotFound as err: assert IgnoreMissingDatabase(err, __file__, warnings)
def test_calc_spectrum(verbose=True, plot=True, warnings=True, *args, **kwargs): """Basic example, used as a non-regression test. Notes ----- How long it tooks to calculate this Spectrum? Performance test on old NeQ package, with the [CDSD-HITEMP-JMIN] databank. See the caveats in the E. Pannier "Limits of CO2 NonEquilibrium Models" paper. (just used here as a performance monitoring) - neq 0.9.20: 18.7s - neq 0.9.20*: 15.4s (removed 2nd loop on 1st isotope because of groupby().apply()) - neq 0.9.20**: 11.7s (after replacing fill_Evib with map() ) - neq 0.9.21: 9.4s (improve Qrot / nrot fetching performance) - neq 0.9.22: 8.4s 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>`_ (we also expect the test to be much faster than above, but that's just because the database is smaller!) - radis 0.9.20 : 2.49 s on [HITRAN-2016] 4.05 s on [CDSD-HITEMP-JMIN] """ if verbose: printm("Testing calc_spectrum match reference") if plot: # Make sure matplotlib is interactive so that test are not stuck in pytest import matplotlib.pyplot as plt plt.ion() s = calc_spectrum( wavelength_min=4165, wavelength_max=4200, # databank='CDSD-HITEMP-JMIN', databank= "hitran", # not appropriate for these temperatures, but convenient for automatic testing Tgas=300, Tvib=1700, Trot=1550, path_length=0.1, mole_fraction=0.5, molecule="CO2", isotope="1,2", wstep=0.01, cutoff=1e-25, use_cached=True, medium="vacuum", verbose=verbose, optimization="simple", warnings={ "MissingSelfBroadeningWarning": "ignore", "NegativeEnergiesWarning": "ignore", "HighTemperatureWarning": "ignore", }, ) s.apply_slit((2, 2.5), "nm", shape="trapezoidal") if plot: s.plot(wunit="nm") w, I = s.get("radiance", wunit="nm") # Compare against hardcoded results (neq 0.9.22, 28/06/18) # I_ref = np.array([0.28694463, 0.29141711, 0.32461613, 0.32909566, 0.21939511, 0.18606445, # 0.19740763, 0.16948599, 0.16780345, 0.15572173, 0.16770853, 0.14966064, # 0.13041356, 0.11751016, 0.10818072, 0.11592531, 0.04666677, 0.00177108, # 0.00069339]) # Harcoded results changed for RADIS with the change of # database (HITEMP-2010 -> HITRAN-2016) and of Tvib model # CDSD with (P,C,Jmin,N) in CDSD polyad -> RADIS built-in constants) # I_ref = np.array([ 0.29148768, 0.29646856, 0.32999337, 0.32249701, 0.2078451 , # 0.18974631, 0.2019285 , 0.17346687, 0.17211401, 0.15939359, # 0.17240575, 0.15395179, 0.13374185, 0.11997065, 0.10858693, # 0.11114162, 0.04575873, 0.00163863, 0.00062654]) # Updated again in RADIS 0.9.20 (19/08/19) to account for the use of DLM (difference # not significant) # I_ref = np.array([ 0.29060991, 0.29756722, 0.32972058, 0.3206278 , 0.20696867, # 0.19218358, 0.20155747, 0.17336405, 0.17218653, 0.1589136 , # 0.17110649, 0.15403513, 0.13376804, 0.11932659, 0.10882006, # 0.11112725, 0.0458288 , 0.00247956, 0.00144128]) # Updated again in RADIS 0.9.20 (02/09/19) with switch to tabulated Q(Tref) # I_ref = np.array([ 0.29048064, 0.29743104, 0.32955513, 0.32047172, 0.20688813, # 0.19210952, 0.20148265, 0.17330909, 0.17213373, 0.15887159, # 0.17106096, 0.15400039, 0.13374285, 0.11930822, 0.10880631, # 0.11111394, 0.04582291, 0.00247955, 0.00144128]) # Updated again on (05/08/20) with implementation of optimized weights: # I_ref = np.array([0.29043204, 0.29740738, 0.32954171, 0.32045394, 0.20680637, # 0.19205883, 0.2014279 , 0.17322236, 0.17206767, 0.15879478, # 0.17107564, 0.15400038, 0.13372559, 0.11929585, 0.10881116, # 0.11111882, 0.04581152, 0.00247154, 0.00143631]) # Updated with RADIS 0.9.26+ (13/12/20) and switch to latest HAPI version # therefore TIPS 2017 (instead of TIPS 2011) which changed CO2 partition functions # Q(Tref=300) 291.9025 --> 291.0405 w_ref = np.array([ 4197.60321744, 4195.84148905, 4194.08123884, 4192.32246493, 4190.56516548, 4188.80933862, 4187.05498252, 4185.30209532, 4183.55067518, 4181.80072025, 4180.05222871, 4178.30519870, 4176.55962842, 4174.81551601, 4173.07285967, 4171.33165756, 4169.59190786, 4167.85360877, 4166.11675846, ]) I_ref = np.array([ 0.29057002, 0.29755271, 0.32971832, 0.32062057, 0.20689238, 0.19213799, 0.20150788, 0.17328113, 0.17212415, 0.15883971, 0.17112437, 0.15403756, 0.13375255, 0.1193155, 0.10882585, 0.11113302, 0.04581781, 0.00247155, 0.00143631, ]) if plot: plt.plot(w_ref, I_ref, "or", label="ref") plt.legend() assert np.allclose(w[::100], w_ref, atol=1e-6) assert np.allclose(I[::100], I_ref, atol=1e-6) return True
def test_calc_spectrum(verbose=True, plot=True, warnings=True, *args, **kwargs): ''' Basic example, used as a non-regression test Note: test case not physically valid as overpopulation is currently calculated with a post processing method that is only valid in optically thin cases Notes ----- How long it tooks to calculate this Spectrum? Performance test on old NeQ package, with the [CDSD-HITEMP-JMIN] databank. See the caveats in the E. Pannier "Limits of CO2 NonEquilibrium Models" paper. (just used here as a performance monitoring) - 0.9.20: 18.7s - 0.9.20*: 15.4s (removed 2nd loop on 1st isotope because of groupby().apply()) - 0.9.20**: 11.7s (after replacing fill_Evib with map() ) - 0.9.21: 9.4s (improve Qrot / nrot fetching performance) - 0.9.22: 8.4s 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]_ (we also expect the test to be much faster than above, but that's just because the database is smaller!) ''' if verbose: printm('Testing calc_spectrum match reference') if plot: # Make sure matplotlib is interactive so that test are not stuck in pytest import matplotlib.pyplot as plt plt.ion() try: s = calc_spectrum( wavelength_min=4165, wavelength_max=4200, # databank='CDSD-HITEMP-JMIN', databank= 'fetch', # not appropriate for these temperatures, but convenient for automatic testing Tgas=300, Tvib=1700, Trot=1550, path_length=0.1, mole_fraction=0.5, molecule='CO2', isotope='1,2', wstep=0.01, cutoff=1e-25, use_cached=True, medium='vacuum', verbose=verbose, warnings={ 'MissingSelfBroadeningWarning': 'ignore', 'NegativeEnergiesWarning': 'ignore', 'HighTemperatureWarning': 'ignore' }) s.apply_slit((2, 2.5), 'nm', shape='trapezoidal') if plot: s.plot(wunit='nm') w, I = s.get('radiance', wunit='nm') w_ref = w[::100] # Compare against hardcoded results (neq 0.9.22, 28/06/18) # I_ref = np.array([0.28694463, 0.29141711, 0.32461613, 0.32909566, 0.21939511, 0.18606445, # 0.19740763, 0.16948599, 0.16780345, 0.15572173, 0.16770853, 0.14966064, # 0.13041356, 0.11751016, 0.10818072, 0.11592531, 0.04666677, 0.00177108, # 0.00069339]) # Harcoded results changed for RADIS v1.0.1 with the change of # database (HITEMP-2010 -> HITRAN-2016) and of Tvib model # CDSD with (P,C,Jmin,N) in CDSD polyad -> RADIS built-in constants) I_ref = np.array([ 0.29148768, 0.29646856, 0.32999337, 0.32249701, 0.2078451, 0.18974631, 0.2019285, 0.17346687, 0.17211401, 0.15939359, 0.17240575, 0.15395179, 0.13374185, 0.11997065, 0.10858693, 0.11114162, 0.04575873, 0.00163863, 0.00062654 ]) if plot: plt.plot(w_ref, I_ref, 'or', label='ref') plt.legend() assert np.allclose(I[::100], I_ref, atol=1e-6) return True except DatabankNotFound as err: assert IgnoreMissingDatabase(err, __file__, warnings)
def test_calc_spectrum_overpopulations(verbose=True, plot=False, warnings=True, *args, **kwargs): ''' Non-regression test: Example using overpopulation of the 001 asymmetric stretch first level of CO2, which is written (p,c,N) = (3,1,4) in [CDSD-4000]_ notation Notes ----- In old Neq package (before RADIS): the test uses a CDSD-PCN notation for vibrational energy assignation, i.e, Evib = minimal energy of a (p,c,N) polyad. See the discussion on the implications in the E. Pannier "Limits of CO2 NonEquilibrium models" paper. Better use the assignation scheme suggested in the paper. But it's okay here as a non-regression test. 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]_ ''' if plot: # Make sure matplotlib is interactive so that test are not stuck in pytest import matplotlib.pyplot as plt plt.ion() try: s = calc_spectrum( wavelength_min=4165, wavelength_max=4200, # databank='CDSD-HITEMP-PCN', databank= 'fetch', # not appropriate for these temperatures, but convenient for automatic testings Tgas=300, Tvib=1700, Trot=1550, # overpopulation={'(3,1,4)': 3}, # 00'0'1 in spectroscopic notation overpopulation={'(0,0,0,1)': 3}, # 00'0'1 in spectroscopic notation path_length=0.1, mole_fraction=0.5, molecule='CO2', isotope='1,2', wstep=0.01, cutoff=1e-25, use_cached=True, medium='vacuum', verbose=verbose, warnings={ 'MissingSelfBroadeningWarning': 'ignore', 'NegativeEnergiesWarning': 'ignore', 'HighTemperatureWarning': 'ignore' }) s.apply_slit((2, 2.5), 'nm', shape='trapezoidal') if plot: s.plot() w, I = s.get('radiance', wunit='nm') w_ref = w[::100] # Compare against hardcoded results (neq 0.9.22, 28/06/18) I_ref = np.array([ 0.61826008, 0.65598262, 0.79760003, 0.7958013, 0.5792486, 0.56727691, 0.60361258, 0.51549598, 0.51012651, 0.47133131, 0.50770568, 0.45093953, 0.39129824, 0.35125324, 0.32238316, 0.34542781, 0.13908073, 0.00506012, 0.00189535 ]) # Harcoded results changed for RADIS v1.0.1 with the change of # database (HITEMP-2010 -> HITRAN-2016) and of Tvib model # CDSD with (P,C,Jmin,N) in CDSD polyad -> RADIS built-in constants) I_ref = np.array([ 0.62299838, 0.66229013, 0.81037059, 0.79899315, 0.57215806, 0.57626389, 0.61424273, 0.52454807, 0.5200812, 0.47920924, 0.51843533, 0.46058817, 0.3983277, 0.35582979, 0.32095204, 0.32821575, 0.13525543, 0.00469489, 0.00174166 ]) if plot: plt.plot(w_ref, I_ref, 'or', label='ref') plt.legend() s.plot_populations() assert np.allclose(I[::100], I_ref, atol=1e-6) if verbose: printm('Test overpopulations: OK') return True except DatabankNotFound as err: assert IgnoreMissingDatabase(err, __file__, warnings)