コード例 #1
0
ファイル: compare.py プロジェクト: VBaillard/radis
def get_diff(s1,
             s2,
             var,
             wunit='default',
             Iunit='default',
             medium='default',
             resample=True):
    ''' Get the difference between 2 spectra
    Basically returns w1, I1 - I2 where (w1, I1) and (w2, I2) are the values of
    s1 and s2 for variable var. (w2, I2) is linearly interpolated if needed.
    
    
    Parameters    
    ----------
    
    s1, s2: Spectrum objects
    
    var: str
        spectral quantity (ex: 'radiance', 'transmittance'...)
    
    wunit: 'nm', 'cm-1'
        waveunit to compare in
        
    Iunit: str
        If 'default' use s1 unit for variable var
    
    medium: 'air', 'vacuum', default'
        propagating medium to compare in (if in wavelength)
    
    Returns    
    -------
    
    w1, Idiff: array
        difference interpolated on the second range(order?)
    
    
    See Also
    --------
    
    :func:`~radis.spectrum.compare.get_ratio`, 
    :func:`~radis.spectrum.compare.get_distance`,  
    :func:`~radis.spectrum.compare.get_residual`,
    :func:`~radis.spectrum.compare.get_residual_integral`, 
    :func:`~radis.spectrum.compare.plot_diff` 
    :meth:`~radis.spectrum.spectrum.compare_with` 
    '''

    w1, I1, w2, I2 = _get_defaults(s1,
                                   s2,
                                   var=var,
                                   wunit=wunit,
                                   Iunit=Iunit,
                                   medium=medium,
                                   resample=resample)

    return curve_substract(w1, I1, w2,
                           I2)  # basically w1, I1 - I2 (on same range)
コード例 #2
0
ファイル: compare.py プロジェクト: gitter-badger/radis
 def get_wdiff_Idiff():
     wdiffs, Idiffs = [], []
     for method in methods:
         if not normalize:
             if method == 'distance':
                 wdiff, Idiff = get_distance(s1,
                                             s2,
                                             var=var,
                                             wunit=wunit,
                                             Iunit=Iunit,
                                             medium=medium)
             elif method == 'diff':
                 wdiff, Idiff = get_diff(s1,
                                         s2,
                                         var=var,
                                         wunit=wunit,
                                         Iunit=Iunit,
                                         medium=medium,
                                         diff_window=diff_window)
             elif method == 'ratio':
                 wdiff, Idiff = get_ratio(s1,
                                          s2,
                                          var=var,
                                          wunit=wunit,
                                          Iunit=Iunit,
                                          medium=medium)
             else:
                 raise ValueError(
                     'Unknown comparison method: {0}'.format(method))
             wdiffs.append(wdiff)
             Idiffs.append(Idiff)
         else:
             if method == 'distance':
                 raise ValueError(
                     '{0} was not implemented yet for normalized spectra'.
                     format(method))
             elif method == 'diff':
                 wdiff, Idiff = curve_substract(w1, I1, w2, I2)
             elif method == 'ratio':
                 wdiff, Idiff = get_ratio(s1,
                                          s2,
                                          var=var,
                                          wunit=wunit,
                                          Iunit=Iunit,
                                          medium=medium)
             else:
                 raise ValueError(
                     'Unknown comparison method: {0}'.format(method))
             wdiffs.append(wdiff)
             Idiffs.append(Idiff)
     return wdiffs, Idiffs
コード例 #3
0
ファイル: compare.py プロジェクト: thewindsofwinter/radis
 def get_wdiff_Idiff():
     wdiffs, Idiffs = [], []
     for method in methods:
         if not normalize:
             if method == "distance":
                 wdiff, Idiff = get_distance(s1,
                                             s2,
                                             var=var,
                                             wunit=wunit,
                                             Iunit=Iunit)
             elif method == "diff":
                 wdiff, Idiff = get_diff(
                     s1,
                     s2,
                     var=var,
                     wunit=wunit,
                     Iunit=Iunit,
                     diff_window=diff_window,
                 )
             elif method == "ratio":
                 wdiff, Idiff = get_ratio(s1,
                                          s2,
                                          var=var,
                                          wunit=wunit,
                                          Iunit=Iunit)
             else:
                 raise ValueError(
                     "Unknown comparison method: {0}".format(method))
             wdiffs.append(wdiff)
             Idiffs.append(Idiff)
         else:
             if method == "distance":
                 raise ValueError(
                     "{0} was not implemented yet for normalized spectra".
                     format(method))
             elif method == "diff":
                 wdiff, Idiff = curve_substract(w1, I1, w2, I2)
             elif method == "ratio":
                 wdiff, Idiff = get_ratio(s1,
                                          s2,
                                          var=var,
                                          wunit=wunit,
                                          Iunit=Iunit)
             else:
                 raise ValueError(
                     "Unknown comparison method: {0}".format(method))
             wdiffs.append(wdiff)
             Idiffs.append(Idiff)
     return wdiffs, Idiffs
コード例 #4
0
ファイル: compare.py プロジェクト: thewindsofwinter/radis
def get_diff(s1,
             s2,
             var,
             wunit="default",
             Iunit="default",
             resample=True,
             diff_window=0):
    # type: (Spectrum, Spectrum, str, str, str, str, bool, int) -> np.array, np.array
    """Get the difference between 2 spectra.
    Basically returns w1, I1 - I2 where (w1, I1) and (w2, I2) are the values of
    s1 and s2 for variable var. (w2, I2) is linearly interpolated if needed.

        .. math::

            dI = I_1 - I_2


    Parameters
    ----------

    s1, s2: Spectrum objects
        2 spectra to compare.

    var: str
        spectral quantity (ex: ``'radiance'``, ``'transmittance'``...)

    wunit: ``'nm'``, ``'cm-1'``, ``'nm_vac'``
        waveunit to compare in: wavelength air, wavenumber, wavelength vacuum

    Iunit: str
        if ``'default'`` use s1 unit for variable var

    medium: 'air', 'vacuum', default'
        propagating medium to compare in (if in wavelength)

    Other Parameters
    ----------------

    resample: bool
        if not ``True``, wavelength must be equals. Else, resample ``s2`` on
        ``s1`` if needed.

    diff_window: int
        If non 0, calculates diff by offsetting s1 by ``diff_window`` number of
        units on either side, and returns the minimum. Compensates for experimental
        errors on the w axis. Default 0. (look up code for more details...)

    Returns
    -------

    w1, Idiff: array
        difference interpolated on the wavespace range of the first Spectrum

    Notes
    -----

    Uses :func:`~radis.misc.curve.curve_substract` internally

    See Also
    --------

    :func:`~radis.spectrum.compare.get_ratio`,
    :func:`~radis.spectrum.compare.get_distance`,
    :func:`~radis.spectrum.compare.get_residual`,
    :func:`~radis.spectrum.compare.get_residual_integral`,
    :func:`~radis.spectrum.compare.plot_diff`,
    :meth:`~radis.spectrum.spectrum.compare_with`
    """

    w1, I1, w2, I2 = _get_defaults(s1,
                                   s2,
                                   var=var,
                                   wunit=wunit,
                                   Iunit=Iunit,
                                   assert_same_wavelength=not resample)

    # basically w1, I1 - I2 (on same range)
    w1, Idiff = curve_substract(w1, I1, w2, I2)
    if diff_window:
        # allow fluctuation from diff_window units. Kinda compensates
        # for experimental errors on x-axis
        diff_list = []
        I2_interp = I1 - Idiff
        for i in range(-diff_window, diff_window + 1):
            diff_list.append(I2_interp - np.roll(I1, i))
        # get minimum in abs value
        diff_list = np.array(diff_list)
        b = np.abs(diff_list).argmin(axis=0)
        Idiff = np.choose(b, diff_list)  # keeps sign
    return w1, Idiff