Exemple #1
0
 def setUp(self):
     self.counts = (1, 1, 1)
     self.edges = (0, 1, 2, 3)
     self.energyScale = EnergyScale(self.edges)
     self.realtime = 1
     self.livetime = 1
     self.distance = 10.
     self.gamma_dose = 100.
     self.title = "test"
     self.spectrum = Spectrum(self.counts, self.energyScale, self.realtime,
                              self.livetime, self.distance, self.gamma_dose,
                              self.title)
Exemple #2
0
 def test_toXml(self):
     counts = (1, 1, 1)
     edges = (0, 1, 2, 3)
     energyScale = EnergyScale(edges)
     rt = 1
     lt = 1
     distance = 10.
     gamma_dose = 100.
     title = "test"
     spectrum = Spectrum(counts, energyScale, rt, lt, distance, gamma_dose,
                         title)
     sp_list = SpectrumList()
     sp_list.addSpectrum(spectrum)
     sp_list.addSpectrum(spectrum)
     os.makedirs("build/test", exist_ok=True)
     with open("build/test/spectrum.test", "w") as fp:
         sp_list.write(fp.name)
         sp_list2 = loadXml(fp.name)
         for sp in sp_list2:
             self.assertSequenceEqual(tuple(sp.energyScale.getEdges()),
                                      edges)
             self.assertSequenceEqual(tuple(sp.counts), counts)
             self.assertEqual(sp.realtime, rt)
             self.assertEqual(sp.livetime, lt)
             self.assertEqual(sp.distance, distance)
             self.assertEqual(sp.gamma_dose, gamma_dose)
             self.assertEqual(sp.title, title)
Exemple #3
0
 def setUp(self):
     self.sensor = GaussianSensorModel(0.05)
     energies = [40, 116, 130]  # 3 total peaks
     self.peaks = []
     for erg in energies:
         self.peaks.append(Peak(erg, 1000, 0))
     channels = np.arange(0, 100)
     es = EnergyScale(np.arange(0, 303, 3))  # 3 keV per channel
     counts = channels * -0.5 + 100
     for peak in self.peaks:
         response = self.sensor.getResponse(peak.energy, peak.intensity,
                                            es.getEdges())
         counts += response
     self.spectrum = Spectrum(counts, es)
     self.mu = 1
     self.lld = 40
     self.baseline, self.smooth = spa.computeBaseline(
         self.spectrum.counts, self.mu)
     self.responsed_peaks = spa.responsePeaks(self.peaks, self.sensor,
                                              self.spectrum.energyScale)
     self.id_input = IdentificationInput(self.spectrum,
                                         intrinsic=self.spectrum)
     self.analysis = spa.SmoothPeakAnalysis()
     self.analysis.setSensor(self.sensor)
     self.result = self.analysis.analyze(self.id_input)
Exemple #4
0
    def test_toXml(self):
        counts = (1,1,1)
        edges = (0,1,2,3)
        energyScale = EnergyScale(edges)
        rt = 1
        lt = 1
        distance = 10.
        gamma_dose = 100.
        title = "test"
        spectrum = Spectrum(counts,
                            energyScale,
                            rt,
                            lt,
                            distance,
                            gamma_dose,
                            title)
        sp_list = SpectrumList()
        sp_list.addSpectrum(spectrum)
        sp_list.addSpectrum(spectrum)

        with tempfile.NamedTemporaryFile() as fp:
            sp_list.write(fp.name)
            sp_list2 = loadXml(fp.name)
            for sp in sp_list2:
                self.assertSequenceEqual(tuple(sp.energyScale.getEdges()), edges)
                self.assertSequenceEqual(tuple(sp.counts), counts)
                self.assertEqual(sp.realtime, rt)
                self.assertEqual(sp.livetime, lt)
                self.assertEqual(sp.distance, distance)
                self.assertEqual(sp.gamma_dose, gamma_dose)
                self.assertEqual(sp.title, title)
Exemple #5
0
 def test_getNormedCounts(self):
     self.assertSequenceEqual(tuple(self.spectrum.getNormedCounts()),
                              (1, 1, 1))
     sp2 = Spectrum([1, 1, 1, 1, 1], EnergyScale([0, 1, 2, 4, 8, 8.5]))
     self.assertSequenceEqual(tuple(sp2.getNormedCounts()),
                              (1., 1., 0.5, 0.25, 2.))
Exemple #6
0
class SpectrumTestCase(unittest.TestCase):
    def setUp(self):
        self.counts = (1, 1, 1)
        self.edges = (0, 1, 2, 3)
        self.energyScale = EnergyScale(self.edges)
        self.realtime = 1
        self.livetime = 1
        self.distance = 10.
        self.gamma_dose = 100.
        self.title = "test"
        self.spectrum = Spectrum(self.counts, self.energyScale, self.realtime,
                                 self.livetime, self.distance, self.gamma_dose,
                                 self.title)

    def test_Integral(self):
        self.assertEqual(self.spectrum.getIntegral(0, 3), 3)
        self.assertEqual(self.spectrum.getIntegral(0.6, 3), 2.4)
        self.assertEqual(self.spectrum.getIntegral(0, 2.4), 2.4)
        # supress the out-of-bounds warning thrown from using -1 energy
        warnings.simplefilter('ignore', category=UserWarning)
        self.assertEqual(self.spectrum.getIntegral(-1, 4), 3)
        warnings.simplefilter('default', category=UserWarning)

    def test_downsample(self):
        sp2 = self.spectrum.downsample()
        self.assertSequenceEqual(tuple(sp2.energyScale.getEdges()), (0, 2))
        self.assertSequenceEqual(tuple(sp2.counts), (2, 2))

    def test_copy(self):
        sp2 = self.spectrum.copy()
        self.assertSequenceEqual(tuple(sp2.energyScale.getEdges()), self.edges)
        self.assertSequenceEqual(tuple(sp2.counts), self.counts)
        self.assertEqual(sp2.realtime, self.realtime)
        self.assertEqual(sp2.livetime, self.livetime)
        self.assertEqual(sp2.distance, self.distance)
        self.assertEqual(sp2.gamma_dose, self.gamma_dose)
        self.assertEqual(sp2.title, self.title)

    def test_getNormedCounts(self):
        self.assertSequenceEqual(tuple(self.spectrum.getNormedCounts()),
                                 (1, 1, 1))
        sp2 = Spectrum([1, 1, 1, 1, 1], EnergyScale([0, 1, 2, 4, 8, 8.5]))
        self.assertSequenceEqual(tuple(sp2.getNormedCounts()),
                                 (1., 1., 0.5, 0.25, 2.))

    def test_toXml(self):
        """ Write and read to temporaty file and compare
        """
        tmp = "build/test"
        os.makedirs("build/test", exist_ok=True)
        with open("build/test/spectrum.test", "w") as fp:
            self.spectrum.write(fp.name)
            sp2 = loadXml(fp.name)
            self.assertSequenceEqual(tuple(sp2.energyScale.getEdges()),
                                     self.edges)
            self.assertSequenceEqual(tuple(sp2.counts), self.counts)
            self.assertEqual(sp2.realtime, self.realtime)
            self.assertEqual(sp2.livetime, self.livetime)
            self.assertEqual(sp2.distance, self.distance)
            self.assertEqual(sp2.gamma_dose, self.gamma_dose)
            self.assertEqual(sp2.title, self.title)