Beispiel #1
0
    def save_principal_components(self, n, spectrum_prefix = 'pc',
    image_prefix = 'im', spectrum_format = 'msa', image_format = 'tif',
                                  on_peaks=False):
        """Save the `n` first principal components  and score maps
        in the specified format

        Parameters
        ----------
        n : int
            Number of principal components to save_als_ica_results
        image_prefix : string
            Prefix for the image file names
        spectrum_prefix : string
            Prefix for the spectrum file names
        spectrum_format : string
        image_format : string

        """
        from spectrum import Spectrum
        target=self._get_target(on_peaks)
        im_list = self.plot_principal_components_maps(n, plot = False,
                                                      on_peaks=on_peaks)
        s = Spectrum({'calibration' : {'data_cube' : target.pc[:,0]}})
        s.get_calibration_from(self)
        for i in xrange(n):
            s.data_cube = target.pc[:,i]
            s.get_dimensions_from_cube()
            s.save('%s-%i.%s' % (spectrum_prefix, i, spectrum_format))
            im_list[i].save('%s-%i.%s' % (image_prefix, i, image_format))
Beispiel #2
0
    def save_principal_components(self,
                                  n,
                                  spectrum_prefix='pc',
                                  image_prefix='im',
                                  spectrum_format='msa',
                                  image_format='tif',
                                  on_peaks=False):
        """Save the `n` first principal components  and score maps
        in the specified format

        Parameters
        ----------
        n : int
            Number of principal components to save_als_ica_results
        image_prefix : string
            Prefix for the image file names
        spectrum_prefix : string
            Prefix for the spectrum file names
        spectrum_format : string
        image_format : string

        """
        from spectrum import Spectrum
        target = self._get_target(on_peaks)
        im_list = self.plot_principal_components_maps(n,
                                                      plot=False,
                                                      on_peaks=on_peaks)
        s = Spectrum({'calibration': {'data_cube': target.pc[:, 0]}})
        s.get_calibration_from(self)
        for i in xrange(n):
            s.data_cube = target.pc[:, i]
            s.get_dimensions_from_cube()
            s.save('%s-%i.%s' % (spectrum_prefix, i, spectrum_format))
            im_list[i].save('%s-%i.%s' % (image_prefix, i, image_format))
Beispiel #3
0
    def save_independent_components(self,
                                    elements=None,
                                    spectrum_format='msa',
                                    image_format='tif',
                                    recmatrix=None,
                                    ic=None,
                                    on_peaks=False):
        """Saves the result of the ICA in image and spectrum format.
        Note that to save the image, the NaNs in the map will be converted
        to zeros.

        Parameters
        ----------
        elements : None or tuple of strings
            a list of names (normally an element) to be assigned to IC. If not
            the will be name ic-0, ic-1 ...
        image_format : string
        spectrum_format : string
        recmatrix : None or numpy array
            externally supplied recmatrix
        ic : None or numpy array
            externally supplied IC
        """
        from hyperspy.signals.spectrum import Spectrum
        target = self._get_target(on_peaks)
        pl = self.plot_independent_components_maps(plot=False,
                                                   recmatrix=recmatrix,
                                                   ic=ic,
                                                   no_nans=True,
                                                   on_peaks=on_peaks)
        if ic is None:
            ic = target.ic
        if self.data.shape[2] > 1:
            maps = True
        else:
            maps = False
        for i in xrange(ic.shape[1]):
            axes = (self.axes_manager._slicing_axes[0].get_axis_dictionary(), )
            axes[0]['index_in_array'] = 0
            spectrum = Spectrum({'data': ic[:, i], 'axes': axes})
            spectrum.data_cube = ic[:, i].reshape((-1, 1, 1))

            if elements is None:
                spectrum.save('ic-%s.%s' % (i, spectrum_format))
                if maps is True:
                    pl[i].save('map_ic-%s.%s' % (i, image_format))
                else:
                    pl[i].save('profile_ic-%s.%s' % (i, spectrum_format))
            else:
                element = elements[i]
                spectrum.save('ic-%s.%s' % (element, spectrum_format))
                if maps:
                    pl[i].save('map_ic-%s.%s' % (element, image_format))
                else:
                    pl[i].save('profile_ic-%s.%s' % (element, spectrum_format))
Beispiel #4
0
    def save_independent_components(self, elements=None,
                                    spectrum_format='msa',
                                    image_format='tif',
                                    recmatrix=None, ic=None,
                                    on_peaks=False):
        """Saves the result of the ICA in image and spectrum format.
        Note that to save the image, the NaNs in the map will be converted
        to zeros.

        Parameters
        ----------
        elements : None or tuple of strings
            a list of names (normally an element) to be assigned to IC. If not
            the will be name ic-0, ic-1 ...
        image_format : string
        spectrum_format : string
        recmatrix : None or numpy array
            externally supplied recmatrix
        ic : None or numpy array
            externally supplied IC
        """
        from hyperspy.signals.spectrum import Spectrum
        target=self._get_target(on_peaks)
        pl = self.plot_independent_components_maps(plot=False,
                                                   recmatrix=recmatrix,
                                                   ic=ic,
                                                   no_nans=True,
                                                   on_peaks=on_peaks)
        if ic is None:
            ic = target.ic
        if self.data.shape[2] > 1:
            maps = True
        else:
            maps = False
        for i in xrange(ic.shape[1]):
            axes = (self.axes_manager._slicing_axes[0].get_axis_dictionary(),)
            axes[0]['index_in_array'] = 0
            spectrum = Spectrum({'data' : ic[:,i], 'axes' : axes})
            spectrum.data_cube = ic[:,i].reshape((-1,1,1))

            if elements is None:
                spectrum.save('ic-%s.%s' % (i, spectrum_format))
                if maps is True:
                    pl[i].save('map_ic-%s.%s' % (i, image_format))
                else:
                    pl[i].save('profile_ic-%s.%s' % (i, spectrum_format))
            else:
                element = elements[i]
                spectrum.save('ic-%s.%s' % (element, spectrum_format))
                if maps:
                    pl[i].save('map_ic-%s.%s' % (element, image_format))
                else:
                    pl[i].save('profile_ic-%s.%s' % (element, spectrum_format))