def test_broadening_methods_different_wstep(verbose=True, plot=False, *args, **kwargs): ''' Test direct Voigt broadening vs convolution of Gaussian x Lorentzian for different spectral grid resolution ''' if plot: # Make sure matplotlib is interactive so that test are not stuck in pytest plt.ion() setup_test_line_databases() # add HITRAN-CO-TEST in ~/.radis if not there # Conditions T = 3000 p = 1 wmin = 2150 # cm-1 wmax = 2152 # cm-1 broadening_max_width = 10 # cm-1 for i, wstep in enumerate([0.01, 0.1, 0.5]): # %% Calculate with RADIS # ---------- sf = SpectrumFactory( wavenum_min=wmin, wavenum_max=wmax, mole_fraction=1, path_length=1, # doesnt change anything wstep=wstep, pressure=p, broadening_max_width=broadening_max_width, isotope='1', verbose=False, warnings={'MissingSelfBroadeningWarning':'ignore', 'NegativeEnergiesWarning':'ignore', 'HighTemperatureWarning':'ignore', 'GaussianBroadeningWarning':'ignore'} ) # 0.2) sf.load_databank('HITRAN-CO-TEST') # s = pl.non_eq_spectrum(Tvib=T, Trot=T, Ttrans=T) sf._broadening_method = 'voigt' s_voigt = sf.eq_spectrum(Tgas=T, name='direct') sf._broadening_method = 'convolve' s_convolve = sf.eq_spectrum(Tgas=T, name='convolve') res = get_residual(s_voigt, s_convolve, 'abscoeff') if verbose: print('Residual:', res) # plot the last one if plot: plot_diff(s_voigt, s_convolve, 'abscoeff', nfig='test_voigt_broadening_methods'+str(i), title='P {0} bar, T {1} K, wstep {2} cm-1'.format(p, T, wstep)) assert res < 2e-4
def test_broadening_DLM_FT(verbose=True, plot=False, *args, **kwargs): """ Test use of DLM with and without Fourier Transform Ensures that results are the same, and compare calculation times. """ if plot: # Make sure matplotlib is interactive so that test are not stuck in pytest plt.ion() setup_test_line_databases() # add HITRAN-CO-TEST in ~/.radis if not there # Conditions T = 3000 p = 1 wstep = 0.002 wmin = 2000 # cm-1 wmax = 2300 # cm-1 broadening_max_width = 10 # cm-1 # %% Calculate with RADIS # ---------- sf = SpectrumFactory( wavenum_min=wmin, wavenum_max=wmax, mole_fraction=1, path_length=1, # doesnt change anything wstep=wstep, pressure=p, broadening_max_width=broadening_max_width, isotope="1", verbose=verbose, chunksize="DLM", warnings={ "MissingSelfBroadeningWarning": "ignore", "NegativeEnergiesWarning": "ignore", "HighTemperatureWarning": "ignore", "GaussianBroadeningWarning": "ignore", }, ) # 0.2) sf.load_databank("HITRAN-CO-TEST") # DLM, real space if verbose: print("\nConvolve version \n") sf._broadening_method = "convolve" s_dlm = sf.eq_spectrum(Tgas=T) s_dlm.name = "DLM ({0:.2f}s)".format(s_dlm.conditions["calculation_time"]) # DLM , with Fourier if verbose: print("\nFFT version \n") sf.params.broadening_method = "fft" s_dlm_fft = sf.eq_spectrum(Tgas=T) s_dlm_fft.name = "DLM FFT ({0:.2f}s)".format( s_dlm_fft.conditions["calculation_time"]) # Compare res = get_residual(s_dlm, s_dlm_fft, "abscoeff") if verbose: print("Residual:", res) # plot if plot: plot_diff(s_dlm, s_dlm_fft, "abscoeff") plt.legend() assert res < 5e-6
def test_broadening_DLM(verbose=True, plot=False, *args, **kwargs): """ Test use of lineshape template for broadening calculation. Ensures that results are the same with and without DLM. """ if plot: # Make sure matplotlib is interactive so that test are not stuck in pytest plt.ion() setup_test_line_databases() # add HITRAN-CO-TEST in ~/.radis if not there # Conditions T = 3000 p = 1 wstep = 0.002 wmin = 2150 # cm-1 wmax = 2152 # cm-1 broadening_max_width = 10 # cm-1 # %% Calculate with RADIS # ---------- sf = SpectrumFactory( wavenum_min=wmin, wavenum_max=wmax, mole_fraction=1, path_length=1, # doesnt change anything wstep=wstep, pressure=p, broadening_max_width=broadening_max_width, isotope="1", verbose=False, warnings={ "MissingSelfBroadeningWarning": "ignore", "NegativeEnergiesWarning": "ignore", "HighTemperatureWarning": "ignore", "GaussianBroadeningWarning": "ignore", }, ) # 0.2) sf.load_databank("HITRAN-CO-TEST") # Reference: calculate without DLM assert sf.misc["chunksize"] is None s_ref = sf.eq_spectrum(Tgas=T) s_ref.name = "Reference ({0:.2f}s)".format( s_ref.conditions["calculation_time"]) # DLM: sf.misc["chunksize"] = "DLM" sf._broadening_method = "convolve" s_dlm = sf.eq_spectrum(Tgas=T) s_dlm.name = "DLM ({0:.2f}s)".format(s_dlm.conditions["calculation_time"]) # DLM Voigt with Whiting approximation: sf._broadening_method = "voigt" s_dlm_voigt = sf.eq_spectrum(Tgas=T) s_dlm_voigt.name = "DLM Whiting ({0:.2f}s)".format( s_dlm_voigt.conditions["calculation_time"]) # Compare res = get_residual(s_ref, s_dlm, "abscoeff") res_voigt = get_residual(s_dlm, s_dlm_voigt, "abscoeff") if verbose: print("Residual:", res) # plot the last one if plot: plot_diff(s_ref, s_dlm, "abscoeff") plt.legend() plot_diff(s_dlm, s_dlm_voigt, "abscoeff") assert res < 1.2e-5 assert res_voigt < 1e-5
def test_broadening_methods_different_conditions(verbose=True, plot=False, *args, **kwargs): """ Test direct Voigt broadening vs convolution of Gaussian x Lorentzian for different spectral grid resolution Notes ----- Reference broadening calculated manually with the HWHM formula of `HITRAN.org <https://hitran.org/docs/definitions-and-units/>`_ """ if plot: # Make sure matplotlib is interactive so that test are not stuck in pytest plt.ion() setup_test_line_databases() # add HITRAN-CO-TEST in ~/.radis if not there # Conditions wstep = 0.005 wmin = 2150.4 # cm-1 wmax = 2151.4 # cm-1 broadening_max_width = 2 # cm-1 for (T, p, fwhm_lorentz, fwhm_gauss) in [ # K, bar, expected FWHM for Lotentz, gauss (cm-1) (3000, 1, 0.02849411, 0.01594728), (300, 1, 0.16023415, 0.00504297), (3000, 0.01, 0.00028494, 0.01594728), ]: # %% Calculate with RADIS # ---------- sf = SpectrumFactory( wavenum_min=wmin, wavenum_max=wmax, mole_fraction=1, path_length=1, # doesnt change anything wstep=wstep, pressure=p, broadening_max_width=broadening_max_width, isotope="1", verbose=False, warnings={ "MissingSelfBroadeningWarning": "ignore", "NegativeEnergiesWarning": "ignore", "HighTemperatureWarning": "ignore", "OutOfRangeLinesWarning": "ignore", "GaussianBroadeningWarning": "ignore", "CollisionalBroadeningWarning": "ignore", }, ) sf.load_databank("HITRAN-CO-TEST") # Manually filter line database, keep one line only: sf.df0.drop(sf.df0[sf.df0.vu != 1].index, inplace=True) assert isclose(sf.df0.wav, 2150.856008) # Calculate spectra (different broadening methods) sf._broadening_method = "voigt" s_voigt = sf.eq_spectrum(Tgas=T, name="direct") # assert broadening FWHM are correct assert isclose(2 * float(sf.df1.hwhm_gauss), fwhm_gauss) assert isclose(2 * float(sf.df1.hwhm_lorentz), fwhm_lorentz) sf._broadening_method = "convolve" s_convolve = sf.eq_spectrum(Tgas=T, name="convolve") # assert broadening FWHM are correct assert isclose(2 * float(sf.df1.hwhm_gauss), fwhm_gauss) assert isclose(2 * float(sf.df1.hwhm_lorentz), fwhm_lorentz) res = get_residual(s_voigt, s_convolve, "abscoeff") if verbose: print( "{0} K, {1} bar: FWHM lorentz = {2:.3f} cm-1, FWHM gauss = {3:.3f} cm-1" .format(T, p, 2 * float(sf.df1.hwhm_lorentz), 2 * float(sf.df1.hwhm_gauss))) if plot: plot_diff( s_voigt, s_convolve, "abscoeff", title= r"T {0} K, p {1} bar: w$_\mathrm{{L}}$ {2:.3f}, w$_\mathrm{{G}}$ {3:.3f} cm$^{{-1}}$" .format(T, p, 2 * float(sf.df1.hwhm_lorentz), float(sf.df1.hwhm_gauss)), ) # assert all broadening methods match assert res < 2e-4