How to use the radis.phys.convert.nm2cm function in radis

To help you get started, we’ve selected a few radis examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github radis / radis / radis / spectrum / operations.py View on Github external
if not inplace:
        s = s.copy()
    
    # Convert wmin, wmax to Spectrum wavespace    
    # (deal with cases where wavelength are given in 'air' or 'vacuum')
    # TODO @dev: rewrite with wunit='cm-1', 'nm_air', 'nm_vac'
    waveunit = s.get_waveunit()
    wmin0, wmax0 = wmin, wmax
    if wunit == 'nm' and waveunit == 'cm-1':
        if medium == 'air':
            if wmax0: wmin = nm_air2cm(wmax0)   # reverted
            if wmin0: wmax = nm_air2cm(wmin0)   # reverted
        else:
            if wmax0: wmin = nm2cm(wmax0)   # reverted
            if wmin0: wmax = nm2cm(wmin0)   # reverted
    elif wunit == 'cm-1' and waveunit == 'nm':
        if s.get_medium() == 'air':
            if wmax0: wmin = cm2nm_air(wmax0)   # nm in air
            if wmin0: wmax = cm2nm_air(wmin0)   # nm in air
        else:
            if wmax0: wmin = cm2nm(wmax0)   # get nm in vacuum
            if wmin0: wmax = cm2nm(wmin0)   # get nm in vacuum
    elif wunit == 'nm' and waveunit == 'nm':
        if s.get_medium() == 'air' and medium == 'vacuum':
            # convert from given medium ('vacuum') to spectrum medium ('air')
            if wmin0: wmin = vacuum2air(wmin0)
            if wmax0: wmax = vacuum2air(wmax0)
        elif s.get_medium() == 'vacuum' and medium == 'air':
            # the other way around
            if wmin0: wmin = air2vacuum(wmin0)
            if wmax0: wmax = air2vacuum(wmax0)
github radis / radis / radis / spectrum / spectrum.py View on Github external
wstep = abs(diff(w)).min()
        assert wstep > 0
        waveunit = self.get_waveunit()

        if __debug__:
            printdbg('apply_slit: {0} in {1}, center `{2}`{1}, applied in waveunit {3}'.format(
                slit_function, unit, center_wavespace, waveunit))

        if center_wavespace is None:
            # center_wavespace should be ~ unit
            center_wavespace = w[len(w)//2]  # w ~ waveunit
            if waveunit == 'cm-1' and unit == 'nm':
                center_wavespace = cm2nm(
                    center_wavespace)     # wavenum > wavelen
            elif waveunit == 'nm' and unit == 'cm-1':
                center_wavespace = nm2cm(
                    center_wavespace)     # wavelen > wavenum

        # Get slit once and for all (and convert the slit unit
        # to the Spectrum `waveunit` if wavespaces are different)
        # -------
        wslit0, Islit0 = get_slit_function(slit_function, unit=unit, norm_by=norm_by,
                                         shape=shape, center_wavespace=center_wavespace,
                                         return_unit=waveunit, wstep=wstep, 
                                         auto_recenter_crop=auto_recenter_crop,
                                         verbose=verbose,
                                         plot=plot_slit, *args, **kwargs)

        # Check if dispersion is too large
        # ----
        if waveunit == 'nm':
            w_nm = w
github radis / radis / radis / tools / slit.py View on Github external
'Wrong format for slit function: {0}'.format(slit_function))
        if shape == 'trapezoidal':
            pass
        elif shape == 'triangular':  # it's the default
            warn('Triangular slit given with a tuple: we used trapezoidal slit instead')
            shape = 'trapezoidal'
        else:
            raise TypeError(
                'A (top, base) tuple must be used with a trapezoidal slit')

        # ... first get FWHM in our wavespace unit
        if return_unit == 'cm-1' and unit == 'nm':
            # center_wavespace ~ nm, FWHM ~ nm
            top = dnm2dcm(top, center_wavespace)   # wavelength > wavenumber
            base = dnm2dcm(base, center_wavespace)   # wavelength > wavenumber
            center_wavespace = nm2cm(center_wavespace)
            if norm_by == 'max':
                scale_slit = sum(slit_function) / \
                    (top+base)  # [unit/return_unit]
        elif return_unit == 'nm' and unit == 'cm-1':
            # center_wavespace ~ cm-1, FWHM ~ cm-1
            top = dcm2dnm(top, center_wavespace)  # wavenumber > wavelength
            base = dcm2dnm(base, center_wavespace)  # wavenumber > wavelength
            center_wavespace = cm2nm(center_wavespace)
            if norm_by == 'max':
                scale_slit = sum(slit_function) / \
                    (top+base)  # [unit/return_unit]
        else:
            pass  # correct unit already

        FWHM = (top+base)/2
github radis / radis / radis / lbl / calc.py View on Github external
:class:`~radis.lbl.factory.SpectrumFactory`, 
    the :ref:`Spectrum page `
    '''

    # Check inputs

    # ... wavelengths / wavenumbers
    if ((wavelength_min is not None or wavelength_max is not None) and
            (wavenum_min is not None or wavenum_max is not None)):
        raise ValueError("Wavenumber and Wavelength both given... it's time to choose!")

    if (wavenum_min is None and wavenum_max is None):
        assert(wavelength_max is not None)
        assert(wavelength_min is not None)
        wavenum_min = nm2cm(wavelength_max)
        wavenum_max = nm2cm(wavelength_min)
    else:
        assert(wavenum_min is not None)
        assert(wavenum_max is not None)

    # ... temperatures

    if Tgas is None and Trot is None:
        raise ValueError(
            'Choose either Tgas (equilibrium) or Tvib / Trot (non equilibrium)')

    if Tvib is None and Trot is not None or Tvib is not None and Trot is None:
        raise ValueError('Choose both Tvib and Trot')
        
    # ... others
    if databank is None:
github radis / radis / radis / lbl / base.py View on Github external
assert wavelength_max is not None
        assert wavelength_min is not None
        # Test range is correct:
        assert wavelength_min < wavelength_max

        # In wavelength mode, the propagating medium matters. Convert to
        # calculation medium (vacuum) if needed:
        if medium == 'air':
            wavelength_min_vac = air2vacuum(wavelength_min)
            wavelength_max_vac = air2vacuum(wavelength_max)
        else:
            wavelength_min_vac = wavelength_min
            wavelength_max_vac = wavelength_max

        wavenum_min = nm2cm(wavelength_max_vac)
        wavenum_max = nm2cm(wavelength_min_vac)
    # ... or input is in wavenumber:
    else:
        assert wavenum_min is not None
        assert wavenum_max is not None
        # Test range is correct:
        assert wavenum_min < wavenum_max

    return wavenum_min, wavenum_max
github radis / radis / radis / misc / signal.py View on Github external
----------

    debug: boolean
        swamps the console namespace with local variables. Default ``False``

    '''

    from radis.test.utils import getTestFile
    from radis.phys.convert import nm2cm, cm2nm
    import matplotlib.pyplot as plt
    from numpy import loadtxt, linspace

    # Test even resampling

    w_nm, I_nm = loadtxt(getTestFile('spectrum.txt')).T
    w_cm, I_cm = resample_even(nm2cm(w_nm), I_nm, resfactor=2, energy_threshold=1e-3,
                               print_conservation=verbose)

    if plot:
        plt.figure()
        plt.xlabel('Wavelength (nm)')
        plt.ylabel('Intensity')
        plt.plot(w_nm, I_nm, '-ok', label='original')
        plt.plot(cm2nm(w_cm), I_cm, '-or', label='resampled')
        plt.legend()

    # Test resampling

    w_crop = linspace(376, 381, 100)
    I_crop = resample(w_nm, I_nm, w_crop, energy_threshold=0.01)

    if plot:
github radis / radis / radis / spectrum / spectrum.py View on Github external
stored_medium = self.conditions.get('medium', None)
            if stored_medium is None:
                raise KeyError('Medium not defined in Spectrum conditions. We cant ' +
                               'derive wavenumber if we dont know whether ' +
                               'wavelengths are in vacuum or air. ' +
                               "Update conditions")
            elif stored_medium == 'vacuum':
                pass
            elif stored_medium == 'air':
                w = air2vacuum(w)
            else:
                raise NotImplementedError(
                    'Unknown propagating medium: {0}'.format(stored_medium))

            # Convert to wavenumber
            w = nm2cm(w)
        return w
github radis / radis / radis / lbl / calc.py View on Github external
:class:`~radis.lbl.factory.SpectrumFactory`, 
    the :ref:`Spectrum page `
    '''

    # Check inputs

    # ... wavelengths / wavenumbers
    if ((wavelength_min is not None or wavelength_max is not None) and
            (wavenum_min is not None or wavenum_max is not None)):
        raise ValueError("Wavenumber and Wavelength both given... it's time to choose!")

    if (wavenum_min is None and wavenum_max is None):
        assert(wavelength_max is not None)
        assert(wavelength_min is not None)
        wavenum_min = nm2cm(wavelength_max)
        wavenum_max = nm2cm(wavelength_min)
    else:
        assert(wavenum_min is not None)
        assert(wavenum_max is not None)

    # ... temperatures

    if Tgas is None and Trot is None:
        raise ValueError(
            'Choose either Tgas (equilibrium) or Tvib / Trot (non equilibrium)')

    if Tvib is None and Trot is not None or Tvib is not None and Trot is None:
        raise ValueError('Choose both Tvib and Trot')
        
    # ... others
    if databank is None:
        raise ValueError('Give a databank name')