示例#1
0
class EnergyScaleTestCase(unittest.TestCase):
    def setUp(self):
        self.energy_scale = EnergyScale([0, 1, 2, 3, 4, 5])

    def test_newScale(self):
        es = EnergyScale.newScale(0, 5, 1, 1)
        self.assertSequenceEqual(tuple(es.getEdges()), tuple(self.energy_scale.getEdges()))

    def test_getCenter(self):
        self.assertEqual(self.energy_scale.getCenter(4), 4.5)

    def test_getCenters(self):
        self.assertSequenceEqual(tuple(self.energy_scale.getCenters()), tuple([0.5,1.5,2.5,3.5,4.5]))

    def test_findBin(self):
        self.assertEqual(self.energy_scale.findBin(5), 4)
        self.assertEqual(self.energy_scale.findBin(6), 5)
        self.assertEqual(self.energy_scale.findBin(-1), 0)

    def test_Length(self):
        self.assertEqual(len(self.energy_scale), 6)

    def test_findEnergy(self):
        self.assertEqual(self.energy_scale.findEnergy(1.5), 1.5)

    def test_toXml(self):
        """ Write and read to temporaty file and compare
        """
        os.makedirs("build/test", exist_ok=True)
        with open("build/test/bins.test","w") as fp:
            self.energy_scale.write(fp.name)
            es = loadXml(fp.name)
            self.assertSequenceEqual(tuple(es.getEdges()), tuple(self.energy_scale.getEdges()))
示例#2
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)