def test_signal_and_background_shape_are_consistent_1d(self):
     calibration = Calibration.Calibration(418.92, 0.97, 'eV')
     data_and_metadata = DataAndMetadata.DataAndMetadata.from_data(
         numpy.ones((2048, ), numpy.float),
         dimensional_calibrations=[calibration])
     fit_range = 0.2, 0.3
     signal_range = 0.4, 0.5
     signal = eels_analysis.extract_original_signal(data_and_metadata,
                                                    [fit_range],
                                                    signal_range)
     background = eels_analysis.calculate_background_signal(
         data_and_metadata, [fit_range], signal_range)
     self.assertEqual(signal.data_shape, signal.data.shape)
     self.assertEqual(background.data_shape, background.data.shape)
Esempio n. 2
0
 def execute(self, eels_xdata, region, fit_interval, signal_interval):
     eels_spectrum_xdata = xd.sum_region(
         eels_xdata,
         region.mask_xdata_with_shape(eels_xdata.data_shape[0:2]))
     signal = eels_analysis.make_signal_like(
         eels_analysis.extract_original_signal(eels_spectrum_xdata,
                                               [fit_interval],
                                               signal_interval),
         eels_spectrum_xdata)
     background_xdata = eels_analysis.make_signal_like(
         eels_analysis.calculate_background_signal(eels_spectrum_xdata,
                                                   [fit_interval],
                                                   signal_interval),
         eels_spectrum_xdata)
     subtracted_xdata = signal - background_xdata
     self.__xdata = xd.vstack(
         (eels_spectrum_xdata, background_xdata, subtracted_xdata))
 def test_make_signal_like_puts_data_in_correct_place(self):
     calibration = Calibration.Calibration(200.0, 2.0, 'eV')
     spectrum_length = 1000
     data_and_metadata = DataAndMetadata.DataAndMetadata.from_data(
         numpy.ones((spectrum_length, ), numpy.float),
         dimensional_calibrations=[calibration])
     signal = eels_analysis.extract_original_signal(data_and_metadata,
                                                    [(0.2, 0.3)],
                                                    (0.4, 0.5))
     signal = DataAndMetadata.DataAndMetadata.from_data(
         numpy.ones(300, ), signal.intensity_calibration,
         signal.dimensional_calibrations)
     expanded = eels_analysis.make_signal_like(signal, data_and_metadata)
     self.assertEqual(expanded.dimensional_calibrations[0], calibration)
     self.assertTrue(
         numpy.array_equal(expanded.data[0:200], numpy.zeros((200, ))))
     self.assertTrue(
         numpy.array_equal(expanded.data[200:500], numpy.ones((300, ))))
     self.assertTrue(
         numpy.array_equal(expanded.data[500:1000], numpy.zeros((500, ))))
 def test_extracted_signal_has_correct_calibration_and_data(self):
     calibration = Calibration.Calibration(200.0, 2.0, 'eV')
     spectrum_length = 1000
     data_and_metadata = DataAndMetadata.DataAndMetadata.from_data(
         (numpy.random.randn(spectrum_length) * 100).astype(numpy.int32),
         dimensional_calibrations=[calibration])
     signal = eels_analysis.extract_original_signal(data_and_metadata,
                                                    [(0.2, 0.3)],
                                                    (0.4, 0.5))
     self.assertEqual(data_and_metadata.dimensional_calibrations[0],
                      calibration)  # dummy check
     self.assertAlmostEqual(
         signal.dimensional_calibrations[0].offset,
         0.2 * spectrum_length * calibration.scale + calibration.offset)
     self.assertAlmostEqual(signal.dimensional_calibrations[0].scale,
                            calibration.scale)
     self.assertEqual(signal.dimensional_calibrations[0].units,
                      calibration.units)
     self.assertTrue(
         numpy.array_equal(signal.data, data_and_metadata.data[200:500]))
 def execute(self, eels_spectrum_data_item, fit_interval_graphics,
             signal_interval_graphic):
     eels_spectrum_xdata = eels_spectrum_data_item.xdata
     fit_intervals = [
         fit_interval_graphic.interval
         for fit_interval_graphic in fit_interval_graphics
     ]
     signal_interval = signal_interval_graphic.interval
     signal_xdata = eels_analysis.extract_original_signal(
         eels_spectrum_xdata, fit_intervals, signal_interval)
     self.__background_xdata = eels_analysis.calculate_background_signal(
         eels_spectrum_xdata, fit_intervals, signal_interval)
     subtracted_xdata = signal_xdata - self.__background_xdata
     offset = int(
         round((signal_interval[0] - fit_intervals[0][0]) *
               eels_spectrum_xdata.data_shape[0]))
     length = int(
         round((signal_interval[1] - signal_interval[0]) *
               eels_spectrum_xdata.data_shape[0]))
     self.__subtracted_xdata = subtracted_xdata[offset:offset + length]
 def execute(self, eels_xdata, region, fit_interval, signal_interval):
     eels_spectrum_xdata = xd.sum_region(
         eels_xdata,
         region.mask_xdata_with_shape(eels_xdata.data_shape[0:2]))
     signal = eels_analysis.make_signal_like(
         eels_analysis.extract_original_signal(eels_spectrum_xdata,
                                               [fit_interval],
                                               signal_interval),
         eels_spectrum_xdata)
     background_xdata = eels_analysis.make_signal_like(
         eels_analysis.calculate_background_signal(eels_spectrum_xdata,
                                                   [fit_interval],
                                                   signal_interval),
         eels_spectrum_xdata)
     subtracted_xdata = signal - background_xdata
     # vstack will return a sequence; convert the sequence to an image
     self.__xdata = xd.redimension(
         xd.vstack(
             (eels_spectrum_xdata, background_xdata, subtracted_xdata)),
         DataAndMetadata.DataDescriptor(False, 0, 2))