def _import_photon_intensity(self, options, name, detector, path): wxrresult = CharacteristicIntensity(path) factor = self._get_normalization_factor(options, detector) # Retrieve intensities intensities = {} for z, line in wxrresult.getAtomicNumberLines(): data = wxrresult.intensities[z][line] transition = from_string("%s %s" % (symbol(z), line)) gnf = list(map(mul, data[WXRGENERATED], [factor] * 2)) enf = list(map(mul, data[WXREMITTED], [factor] * 2)) intensities[PhotonKey(transition, False, PhotonKey.P)] = gnf intensities[PhotonKey(transition, True, PhotonKey.P)] = enf return PhotonIntensityResult(intensities)
def _import_photon_intensity(self, options, name, detector, jobdir): intensities_filepath = os.path.join(jobdir, 'intensities_%s.csv' % name) if not os.path.exists(intensities_filepath): raise ImporterException('Result file "intensites_%s.csv" not found in job directory (%s)' % \ (name, jobdir)) intensities = {} with open(intensities_filepath, 'r') as fp: reader = csv.DictReader(fp, delimiter=';') try: row = next(reader) except StopIteration: row = {} for transition, intensity in row.items(): transition = from_string(transition.strip()) enf = (float(intensity.strip().replace(',', '.')), 0.0) # FIXME: Hack to handle locale problem intensities[PhotonKey(transition, True, PhotonKey.P)] = enf return PhotonIntensityResult(intensities)
def setUp(self): TestCase.setUp(self) self.t1 = Transition(29, 9, 4) self.t2 = K_family(14) self.t3 = Transition(29, siegbahn='La2') intensities = {} intensities[PhotonKey(self.t1, False, PhotonKey.P)] = (3.0, 0.3) intensities[PhotonKey(self.t1, False, PhotonKey.C)] = (1.0, 0.1) intensities[PhotonKey(self.t1, False, PhotonKey.B)] = (2.0, 0.2) intensities[PhotonKey(self.t1, False, PhotonKey.T)] = (6.0, 0.4) intensities[PhotonKey(self.t1, True, PhotonKey.P)] = (7.0, 0.7) intensities[PhotonKey(self.t1, True, PhotonKey.C)] = (5.0, 0.5) intensities[PhotonKey(self.t1, True, PhotonKey.B)] = (6.0, 0.6) intensities[PhotonKey(self.t1, True, PhotonKey.T)] = (18.0, 0.8) intensities[PhotonKey(self.t2, False, PhotonKey.P)] = (13.0, 0.3) intensities[PhotonKey(self.t2, False, PhotonKey.C)] = (11.0, 0.1) intensities[PhotonKey(self.t2, False, PhotonKey.B)] = (12.0, 0.2) intensities[PhotonKey(self.t2, False, PhotonKey.T)] = (36.0, 0.4) intensities[PhotonKey(self.t2, True, PhotonKey.P)] = (17.0, 0.7) intensities[PhotonKey(self.t2, True, PhotonKey.C)] = (15.0, 0.5) intensities[PhotonKey(self.t2, True, PhotonKey.B)] = (16.0, 0.6) intensities[PhotonKey(self.t2, True, PhotonKey.T)] = (48.0, 0.8) intensities[PhotonKey(self.t3, False, PhotonKey.P)] = (23.0, 0.3) intensities[PhotonKey(self.t3, False, PhotonKey.C)] = (21.0, 0.1) intensities[PhotonKey(self.t3, False, PhotonKey.B)] = (22.0, 0.2) intensities[PhotonKey(self.t3, False, PhotonKey.T)] = (66.0, 0.4) intensities[PhotonKey(self.t3, True, PhotonKey.P)] = (27.0, 0.7) intensities[PhotonKey(self.t3, True, PhotonKey.C)] = (25.0, 0.5) intensities[PhotonKey(self.t3, True, PhotonKey.B)] = (26.0, 0.6) intensities[PhotonKey(self.t3, True, PhotonKey.T)] = (78.0, 0.8) self.r = PhotonIntensityResult(intensities)
class TestPhotonIntensityResult(TestCase): def setUp(self): TestCase.setUp(self) self.t1 = Transition(29, 9, 4) self.t2 = K_family(14) self.t3 = Transition(29, siegbahn='La2') intensities = {} intensities[PhotonKey(self.t1, False, PhotonKey.P)] = (3.0, 0.3) intensities[PhotonKey(self.t1, False, PhotonKey.C)] = (1.0, 0.1) intensities[PhotonKey(self.t1, False, PhotonKey.B)] = (2.0, 0.2) intensities[PhotonKey(self.t1, False, PhotonKey.T)] = (6.0, 0.4) intensities[PhotonKey(self.t1, True, PhotonKey.P)] = (7.0, 0.7) intensities[PhotonKey(self.t1, True, PhotonKey.C)] = (5.0, 0.5) intensities[PhotonKey(self.t1, True, PhotonKey.B)] = (6.0, 0.6) intensities[PhotonKey(self.t1, True, PhotonKey.T)] = (18.0, 0.8) intensities[PhotonKey(self.t2, False, PhotonKey.P)] = (13.0, 0.3) intensities[PhotonKey(self.t2, False, PhotonKey.C)] = (11.0, 0.1) intensities[PhotonKey(self.t2, False, PhotonKey.B)] = (12.0, 0.2) intensities[PhotonKey(self.t2, False, PhotonKey.T)] = (36.0, 0.4) intensities[PhotonKey(self.t2, True, PhotonKey.P)] = (17.0, 0.7) intensities[PhotonKey(self.t2, True, PhotonKey.C)] = (15.0, 0.5) intensities[PhotonKey(self.t2, True, PhotonKey.B)] = (16.0, 0.6) intensities[PhotonKey(self.t2, True, PhotonKey.T)] = (48.0, 0.8) intensities[PhotonKey(self.t3, False, PhotonKey.P)] = (23.0, 0.3) intensities[PhotonKey(self.t3, False, PhotonKey.C)] = (21.0, 0.1) intensities[PhotonKey(self.t3, False, PhotonKey.B)] = (22.0, 0.2) intensities[PhotonKey(self.t3, False, PhotonKey.T)] = (66.0, 0.4) intensities[PhotonKey(self.t3, True, PhotonKey.P)] = (27.0, 0.7) intensities[PhotonKey(self.t3, True, PhotonKey.C)] = (25.0, 0.5) intensities[PhotonKey(self.t3, True, PhotonKey.B)] = (26.0, 0.6) intensities[PhotonKey(self.t3, True, PhotonKey.T)] = (78.0, 0.8) self.r = PhotonIntensityResult(intensities) def tearDown(self): TestCase.tearDown(self) def testintensity(self): # Transition 1 val, err = self.r.intensity(self.t1) self.assertAlmostEqual(18.0, val, 4) self.assertAlmostEqual(0.8, err, 4) val, err = self.r.intensity('Cu La1') self.assertAlmostEqual(18.0, val, 4) self.assertAlmostEqual(0.8, err, 4) val, err = self.r.intensity(self.t1, absorption=False) self.assertAlmostEqual(6.0, val, 4) self.assertAlmostEqual(0.4, err, 4) val, err = self.r.intensity(self.t1, fluorescence=False) self.assertAlmostEqual(7.0, val, 4) self.assertAlmostEqual(0.7, err, 4) val, err = self.r.intensity(self.t1, absorption=False, fluorescence=False) self.assertAlmostEqual(3.0, val, 4) self.assertAlmostEqual(0.3, err, 4) # Transition 2 val, err = self.r.intensity(self.t2) self.assertAlmostEqual(48.0, val, 4) self.assertAlmostEqual(0.8, err, 4) val, err = self.r.intensity('Si K') self.assertAlmostEqual(48.0, val, 4) self.assertAlmostEqual(0.8, err, 4) val, err = self.r.intensity(self.t2, absorption=False) self.assertAlmostEqual(36.0, val, 4) self.assertAlmostEqual(0.4, err, 4) val, err = self.r.intensity(self.t2, fluorescence=False) self.assertAlmostEqual(17.0, val, 4) self.assertAlmostEqual(0.7, err, 4) val, err = self.r.intensity(self.t2, absorption=False, fluorescence=False) self.assertAlmostEqual(13.0, val, 4) self.assertAlmostEqual(0.3, err, 4) # Transition 1 + 3 val, err = self.r.intensity('Cu La') self.assertAlmostEqual(78.0 + 18.0, val, 4) self.assertAlmostEqual(1.1314, err, 4) def testhas_transition(self): self.assertTrue(self.r.has_transition(self.t1)) self.assertTrue(self.r.has_transition(self.t2)) self.assertTrue(self.r.has_transition(self.t3)) self.assertFalse(self.r.has_transition('U Ma')) def testcharacteristic_fluorescence(self): # Transition 1 val, err = self.r.characteristic_fluorescence(self.t1) self.assertAlmostEqual(5.0, val, 4) self.assertAlmostEqual(0.5, err, 4) val, err = self.r.characteristic_fluorescence(self.t1, absorption=False) self.assertAlmostEqual(1.0, val, 4) self.assertAlmostEqual(0.1, err, 4) # Transition 2 val, err = self.r.characteristic_fluorescence(self.t2) self.assertAlmostEqual(15.0, val, 4) self.assertAlmostEqual(0.5, err, 4) val, err = self.r.characteristic_fluorescence(self.t2, absorption=False) self.assertAlmostEqual(11.0, val, 4) self.assertAlmostEqual(0.1, err, 4) def testbremmstrahlung_fluorescence(self): # Transition 1 val, err = self.r.bremsstrahlung_fluorescence(self.t1) self.assertAlmostEqual(6.0, val, 4) self.assertAlmostEqual(0.6, err, 4) val, err = self.r.bremsstrahlung_fluorescence(self.t1, absorption=False) self.assertAlmostEqual(2.0, val, 4) self.assertAlmostEqual(0.2, err, 4) # Transition 2 val, err = self.r.bremsstrahlung_fluorescence(self.t2) self.assertAlmostEqual(16.0, val, 4) self.assertAlmostEqual(0.6, err, 4) val, err = self.r.bremsstrahlung_fluorescence(self.t2, absorption=False) self.assertAlmostEqual(12.0, val, 4) self.assertAlmostEqual(0.2, err, 4) def testfluorescence(self): # Transition 1 val, err = self.r.fluorescence(self.t1) self.assertAlmostEqual(11.0, val, 4) self.assertAlmostEqual(0.78102, err, 4) val, err = self.r.fluorescence(self.t1, absorption=False) self.assertAlmostEqual(3.0, val, 4) self.assertAlmostEqual(0.2236, err, 4) # Transition 2 val, err = self.r.fluorescence(self.t2) self.assertAlmostEqual(31.0, val, 4) self.assertAlmostEqual(0.78102, err, 4) val, err = self.r.fluorescence(self.t2, absorption=False) self.assertAlmostEqual(23.0, val, 4) self.assertAlmostEqual(0.2236, err, 4) def testabsorption(self): # Transition 1 val, err = self.r.absorption(self.t1) self.assertAlmostEqual(12.0, val, 4) self.assertAlmostEqual(0.8944, err, 4) val, err = self.r.absorption(self.t1, fluorescence=False) self.assertAlmostEqual(4.0, val, 4) self.assertAlmostEqual(0.7616, err, 4) # Transition 2 val, err = self.r.absorption(self.t2) self.assertAlmostEqual(12.0, val, 4) self.assertAlmostEqual(0.8944, err, 4) val, err = self.r.absorption(self.t2, fluorescence=False) self.assertAlmostEqual(4.0, val, 4) self.assertAlmostEqual(0.7616, err, 4) def testiter_transitions(self): self.assertEqual(3, len(list(self.r.iter_transitions()))) def testiter_intensities(self): self.assertEqual(3, len(list(self.r.iter_intensities())))
def _import_photon_intensity(self, options, key, detector, path, phdets_key_index, phdets_index_keys, *args): def _read_intensities_line(line): values = line.split() try: z = int(values[0]) src = Subshell(z, iupac=values[2].strip()) dst = Subshell(z, iupac=values[1].strip()) transition = Transition(z, src, dst) except ValueError: # transition not supported return None, 0.0, 0.0, 0.0, 0.0 nf = float(values[4]), float(values[5]) cf = float(values[6]), float(values[7]) bf = float(values[8]), float(values[9]) #tf = float(values[10]), float(values[11]) # skip not needed t = float(values[12]), float(values[13]) return transition, cf, bf, nf, t index = phdets_key_index[key] + 1 # Find data files emitted_filepath = os.path.join( path, 'pe-intens-%s.dat' % str(index).zfill(2)) if not os.path.exists(emitted_filepath): raise ImporterException("Data file %s cannot be found" % emitted_filepath) generated_filepath = os.path.join(path, 'pe-gen-ph.dat') if not os.path.exists(generated_filepath): raise ImporterException("Data file %s cannot be found" % generated_filepath) # Load generated intensities = {} with open(generated_filepath, 'r') as fp: for line in fp: line = line.strip() if line.startswith('#'): continue transition, gcf, gbf, gnf, gt = _read_intensities_line(line) if transition is None: continue intensities[PhotonKey(transition, False, PhotonKey.C)] = gcf intensities[PhotonKey(transition, False, PhotonKey.B)] = gbf intensities[PhotonKey(transition, False, PhotonKey.P)] = gnf intensities[PhotonKey(transition, False, PhotonKey.T)] = gt # Load emitted with open(emitted_filepath, 'r') as fp: for line in fp: line = line.strip() if line.startswith('#'): continue transition, ecf, ebf, enf, et = _read_intensities_line(line) if transition is None: continue intensities[PhotonKey(transition, True, PhotonKey.C)] = ecf intensities[PhotonKey(transition, True, PhotonKey.B)] = ebf intensities[PhotonKey(transition, True, PhotonKey.P)] = enf intensities[PhotonKey(transition, True, PhotonKey.T)] = et return PhotonIntensityResult(intensities)