Example #1
0
    def test_automatic_background_subtraction_with_roi(self):
        x = np.linspace(0, 24, 2500)
        y = np.zeros(x.shape)

        peaks = [
            [10, 3, 0.1],
            [12, 4, 0.1],
            [12, 6, 0.1],
        ]
        for peak in peaks:
            y += gaussian(x, peak[0], peak[1], peak[2])
        y_bkg = x * 0.4 + 5.0
        y_measurement = y + y_bkg

        roi = [1, 23]

        spectrum = Spectrum(x, y_measurement)

        auto_background_subtraction_parameters = [2, 50, 50]
        spectrum.set_auto_background_subtraction(auto_background_subtraction_parameters, roi)

        x_spec, y_spec = spectrum.data

        self.assertGreater(x_spec[0],roi[0])
        self.assertLess(x_spec[-1], roi[1])
    def test_simple_linear_background_with_single_peak(self):
        x = np.linspace(0, 25, 2500)
        y_data = gaussian(x, 10, 3, 0.1)
        y_bkg = x * 0.4 + 5.0
        y_measurement = y_data + y_bkg

        y_extracted_bkg = extract_background(x, y_measurement, 1)
        self.assertAlmostEqual(np.sum(y_data - (y_measurement - y_extracted_bkg)), 0)
    def test_simple_linear_background_with_multiple_peaks(self):
        x = np.linspace(0, 24, 2500)
        y_data = np.zeros(x.shape)

        peaks = [
            [10, 3, 0.05],
            [12, 6, 0.05],
            [12, 9, 0.05],
        ]
        for peak in peaks:
            y_data += gaussian(x, peak[0], peak[1], peak[2])

        y_bkg = x * 0.4 + 5.0
        y_measurement = y_data + y_bkg

        y_extracted_bkg = extract_background(x, y_measurement, 0.3)
        self.assertAlmostEqual(np.sum(y_data - (y_measurement - y_extracted_bkg)), 0)
Example #4
0
    def test_automatic_background_subtraction(self):
        x = np.linspace(0, 24, 2500)
        y = np.zeros(x.shape)

        peaks = [
            [10, 3, 0.1],
            [12, 4, 0.1],
            [12, 6, 0.1],
        ]
        for peak in peaks:
            y += gaussian(x, peak[0], peak[1], peak[2])
        y_bkg = x * 0.4 + 5.0
        y_measurement = y + y_bkg

        spectrum = Spectrum(x, y_measurement)

        auto_background_subtraction_parameters = [2, 50, 50]
        spectrum.set_auto_background_subtraction(auto_background_subtraction_parameters)

        x_spec, y_spec = spectrum.data

        self.array_almost_equal(y_spec, y)
    def test_auto_background_subtraction(self):
        x = np.linspace(0, 24, 2500)
        y = np.zeros(x.shape)

        peaks = [
            [10, 3, 0.1],
            [12, 4, 0.1],
            [12, 6, 0.1],
            ]
        for peak in peaks:
            y += gaussian(x, peak[0], peak[1], peak[2])
        y_bkg = x * 0.4 + 5.0
        y_measurement = y + y_bkg

        self.spectrum_model.set_spectrum(x, y_measurement)

        auto_background_subtraction_parameters = [2, 50, 50]
        self.spectrum_model.set_auto_background_subtraction(auto_background_subtraction_parameters)

        x_spec, y_spec = self.spectrum_model.spectrum.data

        self.assertAlmostEqual(np.sum(y_spec- y),0)