Beispiel #1
0
def get_distance(s1,
                 s2,
                 var,
                 wunit='default',
                 Iunit='default',
                 medium='default',
                 resample=True):
    ''' Get the Euclidian distance between 2 spectra
    
    If waveranges dont match, `s2` is interpolated over `s1`. 
    
    
    Parameters    
    ----------
    
    s1, s2: Spectrum objects
    
    var: str
        spectral quantity 
    
    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)
    
    
    See Also
    --------
    
    :func:`~radis.spectrum.compare.get_diff`, 
    :func:`~radis.spectrum.compare.get_ratio`,  
    :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_distance(
        w1, I1, w2, I2,
        discard_out_of_bounds=True)  # euclidian distance from w1, I1
Beispiel #2
0
def get_distance(s1, s2, var, wunit="default", Iunit="default", resample=True):
    # type: (Spectrum, Spectrum, str, str, str, str, bool) -> np.array, np.array
    """Get a regularized Euclidian distance between two spectra ``s1`` and ``s2``

    This regularized Euclidian distance minimizes the effect of a small shift in
    wavelength between the two spectra

    .. math::

        D(w_1)[i] = \sqrt{ \sum_j (\hat{I_1}[i]  - \hat{I_2}[j] )^2 + (\hat{w_1}[i] - \hat{w_2}[j])^2}

    Where values are normalized as:

    .. math::

        \hat{A} = \\frac{A}{max(A) - min(A)}

    If waveranges dont match, ``s2`` is interpolated over ``s1``.

    .. warning ::

        This is a distance on both the waverange and the intensity axis.
        It may be used to compensate for a small offset in your experimental
        spectrum (due to wavelength calibration, for instance) but can lead
        to wrong fits easily. Plus, it is very cost-intensive! Better use
        :func:`~radis.spectrum.compare.get_residual` for an automatized procedure.


    Parameters
    ----------

    s1, s2: Spectrum objects
        :py:class:`~radis.spectrum.spectrum.Spectrum`

    var: str
        spectral quantity

    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)

    Notes
    -----

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

    See Also
    --------

    :func:`~radis.spectrum.compare.get_diff`,
    :func:`~radis.spectrum.compare.get_ratio`,
    :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`

    """
    # TODO: normalize with Imax, wmax

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

    # euclidian distance from w1, I1
    return curve_distance(w1, I1, w2, I2, discard_out_of_bounds=True)