def peakmem_noneq_spectrum(self): opt = self.test_options sf = SpectrumFactory( **{ k: opt[k] for k in [ "wavenum_min", "wavenum_max", "molecule", "isotope", "wstep", "cutoff", "verbose", "chunksize", ] } ) sf.load_databank( path=opt["path"], format=opt["dbformat"], parfuncfmt="hapi", levelsfmt="radis", ) assert len(sf.df0) == 1487308 # number of lines sf.non_eq_spectrum(Ttrans=300, Tvib=1700, Trot=1550)
def time_noneq_spectrum(self): # Note @ dev: can't use calc_spectrum directly because it cannot # read a custom database opt = self.test_options sf = SpectrumFactory( **{ k: opt[k] for k in [ "wavenum_min", "wavenum_max", "molecule", "isotope", "wstep", "cutoff", "verbose", "chunksize", ] } ) sf.load_databank( path=opt["path"], format=opt["dbformat"], parfuncfmt="hapi", levelsfmt="radis", ) assert len(sf.df0) == 1487308 # number of lines sf.non_eq_spectrum(Ttrans=300, Tvib=1700, Trot=1550)
def run_example(): setup_test_line_databases( verbose=True) # add HITEMP-CO2-HAMIL-TEST in ~/.radis if not there sf = SpectrumFactory( wavenum_min=2283.7, wavenum_max=2285.1, wstep=0.001, cutoff=1e-30, path_length=0.1, mole_fraction=400e-6, isotope=[1], db_use_cached=True, # important to test CAche file here verbose=2, ) sf.warnings["MissingSelfBroadeningWarning"] = "ignore" sf.load_databank("HITEMP-CO2-HAMIL-TEST") # Now generate vibrational energies for a 2-T model # ... Note that this is arbitrary. Lookup Pannier & Dubuet 2020 for more. levels = sf.parsum_calc["CO2"][1]["X"].df levels["Evib"] = levels.Evib1 + levels.Evib2 + levels.Evib3 # Calculate populations using the non-equilibrium module: # This will crash the first time because the Levels Database is just a fragment and does not include all levels. try: sf.non_eq_spectrum(300, 300) except AssertionError: # expected sf.df0.dropna(inplace=True) getTestFile("HITEMP-CO2-HAMIL-TEST") s = sf.non_eq_spectrum(300, 300) s.plot()
def run_example(): from radis.test.utils import ( define_Evib_as_sum_of_Evibi, discard_lines_with_na_levels, ) setup_test_line_databases( verbose=True) # add HITEMP-CO2-HAMIL-TEST in ~/.radis if not there sf = SpectrumFactory( wavenum_min=2283.7, wavenum_max=2285.1, wstep=0.001, cutoff=1e-30, path_length=0.1, mole_fraction=400e-6, isotope=[1], verbose=2, ) sf.warnings["MissingSelfBroadeningWarning"] = "ignore" sf.load_databank( "HITEMP-CO2-HAMIL-TEST", db_use_cached=True, # important to test CAche file here ) # Now generate vibrational energies for a 2-T model levels = sf.parsum_calc["CO2"][1]["X"].df define_Evib_as_sum_of_Evibi(levels) discard_lines_with_na_levels(sf) # Calculate populations using the non-equilibrium module: # This will crash the first time because the Levels Database is just a fragment and does not include all levels. try: sf.non_eq_spectrum(300, 300) except AssertionError: # expected sf.df0.dropna(inplace=True) s = sf.non_eq_spectrum(300, 300) s.plot()
def test_klarenaar_validation_case(verbose=True, plot=False, warnings=True, *args, **kwargs): """ Reproduce the Klarenaar 2018 validation case, as given in the [RADIS-2018]_ article. References ---------- Klarenaar et al, "Time evolution of vibrational temperatures in a CO 2 glow discharge measured with infrared absorption spectroscopy", doi 10.1088/1361-6595/aa902e, and the references there in. """ setup_test_line_databases() # %% Data from Dang, adapted by Klarenaar s_exp = Spectrum.from_txt( getValidationCase( join( "test_CO2_3Tvib_vs_klarenaar_data", "klarenaar_2017_digitized_data.csv", )), "transmittance_noslit", waveunit="cm-1", unit="I/I0", delimiter=",", name="Klarenaar 2017", ) # %% Calculate Klarenaar test case conditions sf = SpectrumFactory( 2284.2, 2284.6, wstep=0.001, # cm-1 pressure=20 * 1e-3, # bar db_use_cached=True, cutoff=1e-25, molecule="CO2", isotope="1,2", path_length=10, # cm-1 # warning! 10% in mass fraction -> less in mole fraction mole_fraction=0.1 * 28.97 / 44.07, broadening_max_width=1, # cm-1 medium="vacuum", export_populations="vib", ) sf.warnings["MissingSelfBroadeningWarning"] = "ignore" # sf.load_databank('HITEMP-CO2-DUNHAM') sf.load_databank("HITEMP-CO2-TEST") # Calculate with Klarenaar fitted values T12 = 517 T3 = 2641 Trot = 491 s = sf.non_eq_spectrum((T12, T12, T3), Trot, Ttrans=Trot, vib_distribution="treanor", name="RADIS") if plot: plot_diff(s, s_exp, "transmittance_noslit") # plt.savefig('test_CO2_3Tvib_vs_klarenaar.png') assert get_residual(s, s_exp, "transmittance_noslit", ignore_nan=True) < 0.003 return True
from radis.test.utils import setup_test_line_databases if __name__ == "__main__": # %% Generate carbon monoxide files from radis import SpectrumFactory setup_test_line_databases() # add HITRAN-CO-TEST in ~/.radis if not there Tgas = 1500 sf = SpectrumFactory( wavelength_min=4400, wavelength_max=4800, mole_fraction=0.01, # path_length=0.1, cutoff=1e-25, wstep=0.005, isotope=[1], db_use_cached=True, self_absorption=True, verbose=False, ) sf.load_databank("HITRAN-CO-TEST") s1 = sf.non_eq_spectrum(Tgas, Tgas, path_length=0.01) s1.store("CO_Tgas1500K_mole_fraction0.01.spec", compress=True) s2 = sf.non_eq_spectrum(Tgas, Tgas, path_length=0.01, mole_fraction=0.5) s2.store("CO_Tgas1500K_mole_fraction0.5.spec", compress=True)
def test_validation_vs_specair(rtol=1e-2, verbose=True, plot=False, *args, **kwargs): ''' Test RADIS output on CO IR bands against SPECAIR Test is only performed on integrals of absorption coefficient RADIS doesnt actually match Specair exactly, but this is due to line intensity differences (Specair has no rovibrational specific intensities) rather than differences in populations calculations, as evidenced by the partition functions comparison in the RADIS presentation article. ''' setup_test_line_databases() # add HITRAN-CO-TEST in ~/.radis if not there # %% Specair calculation # ----------- specair_300_300 = load_spec(getValidationCase( join('test_validation_vs_specair_noneqCO_data', 'specair_CO_IR_Tvib300_Trot300.spec')), binary=True) specair_300_2000 = load_spec(getValidationCase( join('test_validation_vs_specair_noneqCO_data', 'specair_CO_IR_Tvib300_Trot2000.spec')), binary=True) specair_2000_300 = load_spec(getValidationCase( join('test_validation_vs_specair_noneqCO_data', 'specair_CO_IR_Tvib2000_Trot300.spec')), binary=True) article_version = False # just for the article # %% Compare with RADIS # ---------- wstep = 0.002 pl = SpectrumFactory( wavelength_min=4400, wavelength_max=4900, mole_fraction=1, pressure=0.01, # bar path_length=1, # we dont care for abscoeff anyway parallel=False, cutoff=1e-30, wstep=wstep, isotope=1, # '1,2,3', medium='vacuum') # 0.2) pl.warnings['MissingSelfBroadeningWarning'] = 'ignore' if article_version: pl.load_databank('HITEMP-CO-DUNHAM') else: pl.load_databank('HITRAN-CO-TEST') # Available on all systems, convenient for fast testing, but you # will be missing some small lines for T ~ 2000 K . print( 'Using HITRAN: small lines will be missing at T ~ 2000K. Use HITEMP if you want them' ) s_300_300 = pl.eq_spectrum(300, name='RADIS') s_2000_300 = pl.non_eq_spectrum(Tvib=2000, Trot=300, Ttrans=300, name='RADIS') s_300_2000 = pl.non_eq_spectrum(Tvib=300, Trot=2000, Ttrans=2000, name='RADIS') # %% Test # Compare integrals b1 = np.isclose(specair_300_300.get_integral('abscoeff'), s_300_300.get_integral('abscoeff'), rtol=rtol) b1 *= np.isclose(specair_2000_300.get_integral('abscoeff'), s_2000_300.get_integral('abscoeff'), rtol=rtol) b1 *= np.isclose(specair_300_2000.get_integral('abscoeff'), s_300_2000.get_integral('abscoeff'), rtol=rtol) # Compare partition functions to hardcoded values b2 = np.isclose(s_2000_300.lines.Q, 139, atol=1) # Specair: 139 b2 *= np.isclose(s_300_2000.lines.Q, 727, atol=1) # Specair: 727 if verbose: printm( '>>> comparing RADIS vs SPECAIR on CO: integrals of abscoeff is are close' + ' to within {0:.1f}%: {1} ({2:.1f}%, {3:.1f}%, {4:.1f}%)'.format( rtol * 100, bool(b1), abs( specair_300_300.get_integral('abscoeff') / s_300_300.get_integral('abscoeff') - 1) * 100, abs( specair_2000_300.get_integral('abscoeff') / s_2000_300.get_integral('abscoeff') - 1) * 100, abs( specair_300_2000.get_integral('abscoeff') / s_300_2000.get_integral('abscoeff') - 1) * 100, )) printm('>>> comparing RADIS vs SPECAIR on CO: partition functions ' + 'are equal to round error: {0}'.format(bool(b2))) if plot: plot_diff( specair_300_300, s_300_300, title=r'T$_\mathregular{vib}$ 300 K, T$_\mathregular{rot}$ 300 K', diff_window=int( 0.02 // wstep ), # compensate for small shifts in both codes. we're comparing intensities here. lw_multiplier=1, #0.75, wunit='nm_vac', plot_medium=True, ) plt.xlim((4500, 4900)) if article_version: plt.savefig( 'out/test_validation_vs_specair_noneqCO_Tvib300_Trot300.png') plt.savefig( 'out/test_validation_vs_specair_noneqCO_Tvib300_Trot300.pdf') plot_diff( specair_2000_300, s_2000_300, title=r'T$_\mathregular{vib}$ 2000 K, T$_\mathregular{rot}$ 300 K', diff_window=int( 0.02 // wstep ), # compensate for small shifts in both codes. we're comparing intensities here. lw_multiplier=1, #0.75, wunit='nm_vac', plot_medium=True, ) plt.xlim((4500, 4900)) if article_version: plt.savefig( 'out/test_validation_vs_specair_noneqCO_Tvib2000_Trot300.png') plt.savefig( 'out/test_validation_vs_specair_noneqCO_Tvib2000_Trot300.pdf') plot_diff( specair_300_2000, s_300_2000, title=r'T$_\mathregular{vib}$ 300 K, T$_\mathregular{rot}$ 2000 K', diff_window=int( 0.02 // wstep ), # compensate for small shifts in both codes. we're comparing intensities here. lw_multiplier=1, #0.75, wunit='nm_vac', plot_medium=True, ) plt.xlim((4500, 4900)) if article_version: plt.savefig( 'out/test_validation_vs_specair_noneqCO_Tvib300_Trot2000.png') plt.savefig( 'out/test_validation_vs_specair_noneqCO_Tvib300_Trot2000.pdf') return bool(b1 * b2)
def test_klarenaar_validation_case(verbose=True, plot=False, warnings=True, *args, **kwargs): ''' Reproduce the Klarenaar 2018 validation case, as given in the [RADIS-2018]_ article. References ---------- Klarenaar et al, "Time evolution of vibrational temperatures in a CO 2 glow discharge measured with infrared absorption spectroscopy", doi 10.1088/1361-6595/aa902e, and the references there in. ''' setup_test_line_databases() try: # %% Data from Dang, adapted by Klarenaar s_exp = Spectrum.from_txt(getValidationCase(join('test_CO2_3Tvib_vs_klarenaar_data', 'klarenaar_2017_digitized_data.csv')), 'transmittance_noslit', waveunit='cm-1', unit='I/I0', delimiter=',', name='Klarenaar 2017') # %% Calculate Klarenaar test case conditions sf = SpectrumFactory(2284.2, 2284.6, wstep=0.001, # cm-1 pressure=20*1e-3, # bar db_use_cached=True, cutoff=1e-25, molecule='CO2', isotope='1,2', path_length=10, # cm-1 # warning! 10% in mass fraction -> less in mole fraction mole_fraction=0.1*28.97/44.07, broadening_max_width=1, # cm-1 medium='vacuum', export_populations='vib', ) sf.warnings['MissingSelfBroadeningWarning'] = 'ignore' # sf.load_databank('HITEMP-CO2-DUNHAM') sf.load_databank('HITEMP-CO2-TEST') # Calculate with Klarenaar fitted values T12 = 517 T3 = 2641 Trot = 491 s = sf.non_eq_spectrum((T12, T12, T3), Trot, Ttrans=Trot, vib_distribution='treanor', name='RADIS') if plot: plot_diff(s, s_exp, 'transmittance_noslit') # plt.savefig('test_CO2_3Tvib_vs_klarenaar.png') assert get_residual(s, s_exp, 'transmittance_noslit', ignore_nan=True) < 0.003 return True except DatabankNotFound as err: assert IgnoreMissingDatabase(err, __file__, warnings)
sf = SpectrumFactory( wavelength_min=4000, wavelength_max=5000, # cm-1 wstep=0.01, isotope='1', verbose=3, chunksize='DLM', ) sf.load_databank('HITEMP-CO2') # link to my CO2 HITEMP database files s_forebody = sf.eq_spectrum(Tgas=4000, pressure=1, mole_fraction=0.027, path_length=1) s_freeflow = sf.non_eq_spectrum(Trot=1690, pressure=0.017, Tvib=2200, mole_fraction=0.606, path_length=3) # Calcule CO sfco = SpectrumFactory( wavelength_min=4000, wavelength_max=5000, # cm-1 wstep=0.01, isotope='1', verbose=3, ) sfco.load_databank('HITEMP-CO') # link to my CO HITEMP database files s_co = sfco.non_eq_spectrum( # non_eq_spectrum because eq_spectrum requires partitions functions # tabulated with TIPS which is limited to 3000 K Tvib=4000,