def to_invcm_relative(self, laser, inplace=True, jacobian=True):
        """Converts signal axis of 1D signal to non-linear wavenumber axis
        (cm^-1) relative to the exciting laser wavelength (Stokes/Anti-Stokes
        shift). Assumes wavelength in units of nm unless the axis units are
        specifically set to µm.

        The intensity is converted from counts/nm (counts/µm) to counts/cm^-1
        by doing a Jacobian transformation, see e.g. Wang and Townsend,
        J. Lumin. 142, 202 (2013), which ensures that integrated signals are
        correct also in the energy domain.

        Input parameters
        ----------------
        laser : float
            Laser wavelength in same units as signal axes (nm or µm).
        inplace : boolean
            If `False`, a new signal object is created and returned. Otherwise
            (default) the operation is performed on the existing signal object.
        jacobian : boolean
            The default is to do the Jacobian transformation (recommended at
            least for luminescence signals), but the transformation can be
            suppressed by setting this option to `False`.

        Examples
        --------
        > import numpy as np
        > from lumispy import LumiSpectrum
        > S1 = LumiSpectrum(np.ones(20), DataAxis(axis = np.arange(200,400,10)), ))
        > S1.to_invcm()

        Note
        ----
        Using a non-linear axis works only for the non_uniform_axis development
        branch of HyperSpy.

        """

        # Check if non_uniform_axis is available in hyperspy version
        if not "axis" in getfullargspec(DataAxis)[0]:
            raise ImportError(
                "Conversion to wavenumber axis works only"
                " if the non_uniform_axis branch of HyperSpy is used.")

        invcmaxis, factor = axis2invcm(self.axes_manager.signal_axes[0])

        # convert to relative wavenumber scale
        if self.axes_manager.signal_axes[0].units == "µm":
            invcmlaser = nm2invcm(1000 * laser)
        else:
            invcmlaser = nm2invcm(laser)
        absaxis = invcmaxis.axis[::-1]
        invcmaxis.axis = invcmlaser - absaxis

        # in place conversion
        if inplace:
            if jacobian:
                self.data = data2invcm(self.data, factor,
                                       self.axes_manager.signal_axes[0].axis,
                                       absaxis)
            # else:
            #    self.data = self.isig[::-1].data
            self.axes_manager.remove(-1)
            self.axes_manager._axes.append(invcmaxis)
        # create and return new signal
        else:
            if jacobian:
                s2data = data2invcm(self.data, factor,
                                    self.axes_manager.signal_axes[0].axis,
                                    absaxis)
            else:
                s2data = self.data
            if self.data.ndim == 1:
                s2 = LumiSpectrum(s2data,
                                  axes=(invcmaxis.get_axis_dictionary(), ))
            elif self.data.ndim == 2:
                s2 = LumiSpectrum(
                    s2data,
                    axes=(
                        self.axes_manager.navigation_axes[0].
                        get_axis_dictionary(),
                        invcmaxis.get_axis_dictionary(),
                    ),
                )
            else:
                s2 = LumiSpectrum(
                    s2data,
                    axes=(
                        self.axes_manager.navigation_axes[1].
                        get_axis_dictionary(),
                        self.axes_manager.navigation_axes[0].
                        get_axis_dictionary(),
                        invcmaxis.get_axis_dictionary(),
                    ),
                )
            s2.set_signal_type(self.metadata.Signal.signal_type)
            s2.metadata = self.metadata
            return s2
Exemple #2
0
def test_nm2invcm():
    assert nm2invcm(250) == 4e4
    assert nm2invcm(400) == 25e3