def setUp(self): super().setUp() photon_detector = self.create_basic_photondetector() self.a = KRatioAnalysis(photon_detector) self.options = self.create_basic_options()
def testconvert_parse(self): handler = KRatioAnalysisHDF5Handler() detector = self.create_basic_photondetector() standard_materials = {29: Material.from_formula('CuZn'), 28: Material.from_formula('NiAl')} analysis = KRatioAnalysis(detector, standard_materials) analysis2 = self.convert_parse_hdf5handler(handler, analysis) self.assertEqual(analysis2, analysis)
def testconvert(self): handler = KRatioResultSeriesHandler() analysis = KRatioAnalysis(self.create_basic_photondetector()) b = KRatioResultBuilder(analysis) b.add_kratio((29, 'Ka1'), 2.0, 5.0) b.add_kratio((29, 'Ka'), 4.0, 5.0) result = b.build() s = handler.convert(result) self.assertEqual(4, len(s))
def testconvert(self): handler = OptionsHtmlHandler() options = self.create_basic_options() sample = HorizontalLayerSample(COPPER, tilt_rad=0.1, azimuth_rad=0.2) sample.add_layer(ZINC, 20e-9) sample.add_layer(VACUUM, 20e-9) sample.add_layer(GALLIUM, 50e-9) options.sample = sample detector = PhotonDetector('xray2', 2.2, 3.3) analysis = KRatioAnalysis(detector) analysis.add_standard_material(29, COPPER) analysis.add_standard_material(30, ZINC) options.analyses.append(analysis) doc = handler.convert(options) self.assertEqual(12, len(doc.getElementsByTagName('dt')))
class TestKRatioAnalysis(TestCase): def setUp(self): super().setUp() photon_detector = self.create_basic_photondetector() self.a = KRatioAnalysis(photon_detector) self.options = self.create_basic_options() def testapply(self): list_options = self.a.apply(self.options) self.assertEqual(1, len(list_options)) options = list_options[0] self.assertAlmostEqual(self.options.beam.energy_eV, options.beam.energy_eV, 4) self.assertAlmostEqual(self.options.beam.particle, options.beam.particle, 4) self.assertIsInstance(options.sample, SubstrateSample) self.assertEqual(Material.pure(29), options.sample.material) self.assertSequenceEqual(self.options.detectors, options.detectors) self.assertSequenceEqual(self.options.limits, options.limits) self.assertSequenceEqual(self.options.models, options.models) self.assertEqual(1, len(options.analyses)) self.assertIsInstance(options.analyses[0], PhotonIntensityAnalysis) def testapply2(self): self.options.sample.material = Material.from_formula('Al2O3') list_options = self.a.apply(self.options) self.assertEqual(2, len(list_options)) # def testcalculate_nothing(self): # simulation = self.create_basic_simulation() # simulations = [simulation] # newresult = self.a.calculate(simulation, simulations) # self.assertFalse(newresult) def testcalculate(self): # Create options beam = GaussianBeam(20e3, 10.e-9) sample = SubstrateSample(Material.from_formula('CaSiO4')) limit = ShowersLimit(100) unkoptions = Options(self.program, beam, sample, [self.a], [limit]) list_standard_options = self.a.apply(unkoptions) self.assertEqual(3, len(list_standard_options)) # Create simulations def create_simulation(options): builder = EmittedPhotonIntensityResultBuilder(self.a) for z, wf in options.sample.material.composition.items(): builder.add_intensity((z, 'Ka'), wf * 1e3, math.sqrt(wf * 1e3)) result = builder.build() return Simulation(options, [result]) unksim = create_simulation(unkoptions) stdsims = [ create_simulation(options) for options in list_standard_options ] sims = stdsims + [unksim] # Calculate newresult = self.a.calculate(unksim, sims) self.assertTrue(newresult) newresult = self.a.calculate(unksim, sims) self.assertFalse(newresult) # Test results = unksim.find_result(KRatioResult) self.assertEqual(1, len(results)) result = results[0] self.assertEqual(3, len(result)) q = result[('Ca', 'Ka')] self.assertAlmostEqual(0.303262, q.n, 4) self.assertAlmostEqual(0.019880, q.s, 4) q = result[('Si', 'Ka')] self.assertAlmostEqual(0.212506, q.n, 4) self.assertAlmostEqual(0.016052, q.s, 4) q = result[('O', 'Ka')] self.assertAlmostEqual(0.484232 / 0.470749, q.n, 4) self.assertAlmostEqual(0.066579, q.s, 4)
def testconvert_parse_no_standards(self): handler = KRatioAnalysisHDF5Handler() detector = self.create_basic_photondetector() analysis = KRatioAnalysis(detector) analysis2 = self.convert_parse_hdf5handler(handler, analysis) self.assertEqual(analysis2, analysis)
def testconvert(self): handler = KRatioAnalysisSeriesHandler() detector = self.create_basic_photondetector() analysis = KRatioAnalysis(detector) s = handler.convert(analysis) self.assertEqual(0, len(s))
def testconvert(self): handler = KRatioAnalysisHtmlHandler() detector = self.create_basic_photondetector() analysis = KRatioAnalysis(detector) root = handler.convert(analysis) self.assertEqual(3, len(root.children))