Example #1
0
 def to_spectrum(self):
     from hyperspy.signals.spectrum import Spectrum
     dic = self._get_signal_dict()
     dim = len(self.data.shape)
     dic['mapped_parameters']['record_by'] = 'spectrum'
     dic['data'] = np.rollaxis(dic['data'], 0, dim)
     dic['axes'] = utils_varia.rollelem(dic['axes'],0, dim)
     i = 0
     for axis in dic['axes']:
         axis['index_in_array'] = i
         i += 1
     sp = Spectrum(dic)
     sp.axes_manager._set_axes_index_in_array_from_position()
     if hasattr(self, 'learning_results'):
         sp.learning_results = copy.deepcopy(self.learning_results)
         sp.learning_results._transpose_results()
         sp.learning_results.original_shape = self.data.shape
     return sp
Example #2
0
    def to_spectrum(self, signal_axis=0):
        """Image to spectrum

        Parameters
        ----------
        signal_axis : integer
            Selected the signal axis.        
            
        Examples
        --------        
        >>> img = signals.Image({'data' : np.ones((3,4,5,6))})
        >>> img
        <Image, title: , dimensions: (3L, 4L, 5L, 6L)>

        >>> img.to_spectrum()
        <Spectrum, title: , dimensions: (4L, 5L, 6L, 3L)>

        >>> img.to_spectrum(1)
        <Spectrum, title: , dimensions: (3L, 5L, 6L, 4L)>
        
        """
        from hyperspy.signals.spectrum import Spectrum
        dic = self._get_signal_dict()
        dim = len(self.data.shape)
        dic['mapped_parameters']['record_by'] = 'spectrum'        
        dic['data'] = np.rollaxis(dic['data'], signal_axis, dim)
        dic['axes'] = utils_varia.rollelem(dic['axes'], signal_axis, dim)
        i = 0
        for axis in dic['axes']:
            axis['index_in_array'] = i
            i += 1
        sp = Spectrum(dic)
        sp.axes_manager._set_axes_index_in_array_from_position()
        if hasattr(self, 'learning_results'):
            if signal_axis != 0 and self.learning_results.loadings is not None:
                print("The learning results won't be transfered correctly")
            else :
                sp.learning_results = copy.deepcopy(self.learning_results)
                sp.learning_results._transpose_results()
                sp.learning_results.original_shape = self.data.shape
                
        sp.tmp_parameters = self.tmp_parameters.deepcopy()
        return sp