Exemplo n.º 1
0
def test_resampling_function(verbose=True,
                             plot=True,
                             close_plots=True,
                             *args,
                             **kwargs):
    ''' Test resampling functions 
    
    Get a Spectrum calculated in cm-1, then resample on a smaller range in cm-1, 
    and in approximately the same range (but in nm). Check that all 3 overlap 
    '''
    # %%
    from radis.test.utils import getTestFile
    from radis.tools.database import load_spec
    from radis.spectrum import get_residual_integral

    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)
    s.name = 'original'
    s2 = s.copy()
    s2b = s.copy()
    s3 = s.copy()
    s2.resample(np.linspace(4500, 4700, 10000), unit='nm', medium='vacuum')
    s2b.resample(np.linspace(4500, 4700, 10000), unit='nm', medium='air')
    s3.resample(np.linspace(2127.2, 2227.7, 10000), unit='cm-1')
    s2.name = 'resampled in nm (vacuum)'
    s2b.name = 'resampled in nm (air)'
    s3.name = 'resampled in cm-1'

    s.compare_with(s2,
                   plot=plot,
                   title='Residual: {0:.2g}'.format(
                       get_residual_integral(s,
                                             s2,
                                             'abscoeff',
                                             ignore_nan=True)))
    s.compare_with(s2b,
                   plot=plot,
                   title='Residual: {0:.2g}'.format(
                       get_residual_integral(s,
                                             s2b,
                                             'abscoeff',
                                             ignore_nan=True)))
    s.compare_with(s3,
                   plot=plot,
                   title='Residual: {0:.2g}'.format(
                       get_residual_integral(s,
                                             s3,
                                             'abscoeff',
                                             ignore_nan=True)))

    assert get_residual_integral(s, s2, 'abscoeff', ignore_nan=True) < 1e-4
    assert get_residual_integral(s, s2b, 'abscoeff', ignore_nan=True) < 1e-3
    assert get_residual_integral(s, s3, 'abscoeff', ignore_nan=True) < 1e-5
Exemplo n.º 2
0
def test_resampling_function(verbose=True,
                             plot=True,
                             close_plots=True,
                             *args,
                             **kwargs):
    """Test resampling functions

    Get a Spectrum calculated in cm-1, then resample on a smaller range in cm-1,
    and in approximately the same range (but in nm). Check that all 3 overlap
    """
    # %%
    from radis.spectrum import get_residual_integral
    from radis.test.utils import getTestFile
    from radis.tools.database import load_spec

    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)
    s.name = "original"

    # Test resampling without changing anything
    s_cm = s.resample(s.get_wavenumber(), "cm-1", inplace=False)
    s_nm = s.resample(s.get_wavelength(), "nm", inplace=False)
    assert s == s_cm
    assert np.allclose(s.get("abscoeff", wunit="nm"),
                       s_nm.get("abscoeff", wunit="nm"))

    # Test resampling on new ranges
    s2 = s.copy()
    s2b = s.copy()
    s3 = s.copy()
    s2.resample(np.linspace(4500, 4700, 10000), unit="nm_vac")
    s2b.resample(np.linspace(4500, 4700, 10000), unit="nm")
    s3.resample(np.linspace(2127.2, 2227.7, 10000), unit="cm-1")
    s2.name = "resampled in nm (vacuum)"
    s2b.name = "resampled in nm (air)"
    s3.name = "resampled in cm-1"

    s.compare_with(
        s2,
        plot=plot,
        title="Residual: {0:.2g}".format(
            get_residual_integral(s, s2, "abscoeff", ignore_nan=True)),
    )
    s.compare_with(
        s2b,
        plot=plot,
        title="Residual: {0:.2g}".format(
            get_residual_integral(s, s2b, "abscoeff", ignore_nan=True)),
    )
    s.compare_with(
        s3,
        plot=plot,
        title="Residual: {0:.2g}".format(
            get_residual_integral(s, s3, "abscoeff", ignore_nan=True)),
    )

    assert get_residual_integral(s, s2, "abscoeff", ignore_nan=True) < 1e-3
    assert get_residual_integral(s, s2b, "abscoeff", ignore_nan=True) < 1e-3
    assert get_residual_integral(s, s3, "abscoeff", ignore_nan=True) < 1e-5