def test_plot_compare_with_nan( plot=True, verbose=True, close_plots=True, *args, **kwargs ): if plot and close_plots: import matplotlib.pyplot as plt plt.close("all") s = calc_spectrum( 1900, 2300, # cm-1 molecule="CO", isotope="1,2,3", pressure=1.01325, # bar Tgas=700, # K mole_fraction=0.1, path_length=1, # cm ) s = Radiance_noslit(s) s._q["radiance_noslit"][0] = np.nan # Test Plot function when there are Nans in the spectrum: if plot: s.plot(normalize=True) s.plot(normalize=(2200, 2250)) # Test plot_diff function when there are Nans in the spectra: if plot: plot_diff(s, s * 1.2, normalize=True) plot_diff(s, s * 1.2, "radiance_noslit", normalize=(2000, 2100))
def test_compare_methods(verbose=True, plot=True, close_plots=True, *args, **kwargs): ''' Just run all Spectrum compare methods to check they work''' if plot and close_plots: import matplotlib.pyplot as plt plt.close('all') s = load_spec(getTestFile('CO_Tgas1500K_mole_fraction0.01.spec')) s.resample(np.linspace(2193, 2193.8, 100)) # limits to a single line, because get_distance() # is very computationaly heavy s.update('radiance_noslit') s_noabsorption = s.copy() s.name = 'solve RTE' s_noabsorption.name = 'optically thin' # rescale, normal # s.rescale_mole_fraction(10) s.rescale_path_length(10) # rescale, optically thin mode s_noabsorption.conditions['self_absorption'] = False # s_noabsorption.rescale_mole_fraction(10) s_noabsorption.rescale_path_length(10) # Compare get_distance(s, s_noabsorption, 'radiance_noslit') # should be added in an example with experimental fit of bandhead title = 'CO x={0:.2f}, L={1:.2f}cm'.format(s.conditions['mole_fraction'], s.conditions['path_length']) if plot: plot_diff(s, s_noabsorption, method='diff', title=title) plot_diff(s, s_noabsorption, method='ratio', normalize=True, title=title)
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
def test_compare_methods(verbose=True, plot=True, close_plots=True, *args, **kwargs): """ Just run all Spectrum compare methods to check they work""" if plot and close_plots: import matplotlib.pyplot as plt plt.close("all") s = load_spec(getTestFile("CO_Tgas1500K_mole_fraction0.01.spec"), binary=True) # limits to a single line, because get_distance() s.resample(np.linspace(2193, 2193.8, 100)) # is very computationaly heavy s.update("radiance_noslit") s_noabsorption = s.copy() s.name = "solve RTE" s_noabsorption.name = "optically thin" # rescale, normal # s.rescale_mole_fraction(10) s.rescale_path_length(10) # rescale, optically thin mode s_noabsorption.conditions["self_absorption"] = False # s_noabsorption.rescale_mole_fraction(10) s_noabsorption.rescale_path_length(10) # Compare # should be added in an example with experimental fit of bandhead get_distance(s, s_noabsorption, "radiance_noslit") title = "CO x={0:.2f}, L={1:.2f}cm".format(s.conditions["mole_fraction"], s.conditions["path_length"]) if plot: plot_diff(s, s_noabsorption, method="diff", diff_window=1, title=title) plot_diff(s, s_noabsorption, method="ratio", normalize=True, title=title)
def test_offset(verbose=True, 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) s2 = offset(s, 10, 'nm', name='offset_10nm') if plot: plot_diff(s, s2) assert np.allclose(s2.get_wavelength(which='convoluted'), s.get_wavelength(which='convoluted') + 10) assert np.allclose(s2.get_wavelength(which='non_convoluted'), s.get_wavelength(which='non_convoluted') + 10) # Test inplace version s.offset(10, 'nm') assert np.allclose(s2.get_wavelength(which='convoluted'), s.get_wavelength(which='convoluted'))