def test_result_toXml(self): os.makedirs("build/test", exist_ok=True) with open("build/test/spectrum.test", "w") as fp: self.result.write(fp.name) r = loadXml(fp.name) attributes = ["sample", "intrinsic"] for attr in attributes: original = getattr(self.result, attr) loaded = getattr(r, attr) self.assertEqual(original.getEnergyScale(), loaded.getEnergyScale()) self.assertAlmostEqual(original.getContinuum().counts.sum(), loaded.getContinuum().counts.sum()) peaks_original = original.getPeaks() peaks_loaded = original.getPeaks() num_peaks = len(peaks_original) self.assertEqual(len(peaks_loaded), num_peaks) for i in range(len(peaks_loaded)): self.assertAlmostEqual(peaks_original[i].energy, peaks_loaded[i].energy) self.assertAlmostEqual(peaks_original[i].intensity, peaks_loaded[i].intensity) self.assertAlmostEqual(peaks_original[i].baseline, peaks_loaded[i].baseline) self.assertAlmostEqual(peaks_original[i].width, peaks_loaded[i].width)
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)
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)
def test_toXml(self): """ Write and read to temporaty file and compare """ with tempfile.NamedTemporaryFile() as fp: self.nr.write(fp.name) nr = loadXml(fp.name) self.assertEqual(nr.score, 0.9) self.assertEqual(nr.prediction, 1)
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()))
def test_toXml(self): """ Write and read to temporaty file and compare """ with tempfile.NamedTemporaryFile() as fp: self.energy_scale.write(fp.name) es = loadXml(fp.name) self.assertSequenceEqual(tuple(es.getEdges()), tuple(self.energy_scale.getEdges()))
def test_toXml(self): """ Write and read to temporaty file and compare """ with tempfile.NamedTemporaryFile() 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)
def test_load(self): data_path = pathlib.Path(__file__).parent.joinpath( "data", "test_spa", "spa.xml") spa = loadXml(data_path) self.assertEqual(spa.startEnergy, 45.0) self.assertEqual(spa.endEnergy, 3000.0) self.assertEqual(spa.smoothingFactor, 3.0) sensor = spa.sensor self.assertEqual(sensor.resolution, 0.055) self.assertEqual(sensor.resolutionEnergy, 662) self.assertEqual(sensor.wideningPower, 0.5) self.assertEqual(sensor.electronicNoise, 0.0) self.assertEqual(sensor.C, 0.5) self.assertAlmostEqual(sensor.B, 0.3610784300467453)
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)