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))
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))
def _extract_background_fired(self): if self.pl is None: return signal = self.SI() - self.pl.function(self.SI.energy_axis) i = self.SI.energy2index(self.bg_span_selector.range[1]) signal[:i] = 0. s = Spectrum({'calibration' : {'data_cube' : signal}}) s.get_calibration_from(self.SI) interactive_ns[self.background_substracted_spectrum_name] = s
def chrono_align_and_sum(spectrum, energy_range = (None, None), spatial_shape = None): """Alignment and sum of a chrono-spim SI Parameters ---------- spectrum : Spectrum instance Chrono-spim energy_range : tuple of floats energy interval in which to perform the alignment in energy units axis : int """ from spectrum import Spectrum dc = spectrum.data_cube min_energy_size = dc.shape[0] # i = 0 new_dc = None # For the progress bar to work properly we must capture the output of the # functions that are called during the alignment process import cStringIO import sys capture_output = cStringIO.StringIO() from hyperspy.misc.progressbar import progressbar pbar = progressbar(maxval = dc.shape[2] - 1) for i in xrange(dc.shape[2]): pbar.update(i) sys.stdout = capture_output s = Spectrum({'calibration': {'data_cube' : dc[:,:,i]}}) s.get_calibration_from(spectrum) s.find_low_loss_origin() s.align(energy_range, progress_bar = False) min_energy_size = min(s.data_cube.shape[0], min_energy_size) if new_dc is None: new_dc = s.data_cube.sum(1) else: new_dc = np.concatenate([new_dc[:min_energy_size], s.data_cube.sum(1)[:min_energy_size]], 1) sys.stdout = sys.__stdout__ pbar.finish() spectrum.data_cube = new_dc spectrum.get_dimensions_from_cube() spectrum.find_low_loss_origin() spectrum.align(energy_range) spectrum.find_low_loss_origin() if spatial_shape is not None: spectrum.data_cube = spectrum.data_cube.reshape( [spectrum.data_cube.shape[0]] + list(spatial_shape)) spectrum.data_cube = spectrum.data_cube.swapaxes(1,2) spectrum.get_dimensions_from_cube()