def testconvert4(self): # Base options ops = Options(name="Test") ops.beam.energy = 100e3 ops.detectors['prz'] = PhiZDetector((0, 1), (2, 3), 1000) ops.detectors['xray'] = PhotonIntensityDetector((0, 1), (2, 3)) ops.limits.add(ShowersLimit(5678)) # Convert opss = self.converter.convert(ops) # Test self.assertEqual(1, len(opss)) self.assertEqual(2, len(opss[0].detectors)) self.assertEqual(7, len(opss[0].models)) # Test difference in elevation ops.detectors['xray'] = PhotonIntensityDetector((0.5, 1), (2, 3)) opss = self.converter.convert(ops) self.assertEqual(2, len(opss)) # Test difference in azimuth ops.detectors['xray'] = PhotonIntensityDetector((0, 1), (2.5, 3)) opss = self.converter.convert(ops) self.assertEqual(2, len(opss)) # Test difference in elevation (PhotonSpectrumDetector) ops.detectors['xray'] = PhotonSpectrumDetector((0.5, 1), (2, 3), 1000, (0, 1234)) opss = self.converter.convert(ops) self.assertEqual(2, len(opss))
def test_detector_photon_intensity(self): # Create ops = Options(name='test1') ops.beam.energy_eV = 20e3 ops.detectors['xray1'] = \ PhotonIntensityDetector((radians(35), radians(45)), (0, radians(360.0))) ops.detectors['xray2'] = \ PhotonIntensityDetector((radians(-45), radians(-35)), (0, radians(360.0))) # Import resultscontainer = self.i.import_(ops, self.testdata) # Test # self.assertEqual(2, len(resultscontainer)) result = resultscontainer['xray2'] val, unc = result.intensity('W Ma1') self.assertAlmostEqual(6.07152e-05, val, 9) self.assertAlmostEqual(2.23e-06, unc, 9) val, unc = result.intensity('W Ma1', fluorescence=False) self.assertAlmostEqual(5.437632e-05, val, 9) self.assertAlmostEqual(2.12e-06, unc, 9) val, unc = result.intensity('W Ma1', absorption=False) self.assertAlmostEqual(5.521557e-4, val, 9) self.assertAlmostEqual(4.79e-06, unc, 9) val, unc = result.intensity('W Ma1', absorption=False, fluorescence=False) self.assertAlmostEqual(4.883132e-4, val, 9) self.assertAlmostEqual(4.45e-06, unc, 9)
def testconvert1(self): # Base options ops = Options(name="Test") ops.beam = PencilBeam(1234) ops.detectors['xrays'] = PhotonIntensityDetector((0.1, 0.2), (0.3, 0.4)) ops.limits.add(ShowersLimit(5678)) # Convert with warnings.catch_warnings(record=True) as ws: opss = self.converter.convert(ops) # 6 warnings for the default models self.assertEqual(5, len(ws)) self.assertEqual(1, len(opss)) # Test self.assertAlmostEqual(1234, opss[0].beam.energy_eV, 4) self.assertEqual(1, len(opss[0].detectors)) self.assertEqual(1, len(opss[0].limits)) limit = list(ops.limits.iterclass(ShowersLimit))[0] self.assertEqual(5678, limit.showers) self.assertEqual(5, len(opss[0].models))
def testconvert2(self): # Base options ops = Options("Test") ops.beam.origin_m = (0.0, 0.0, 0.09) det = PhotonIntensityDetector((radians(35), radians(45)), (0, radians(360.0))) ops.detectors['det1'] = det # Convert opss = self.converter.convert(ops) self.assertEqual(0, len(opss)) # No showers limit
def testexport_substrate(self): # Create options mat = Material({ 79: 0.5, 47: 0.5 }, 'Mat1', absorption_energy_eV={ELECTRON: 123.0}) ops = Options() ops.beam.energy_eV = 1234 ops.beam.diameter_m = 25e-9 ops.beam.origin_m = (100e-9, 0, 1) ops.geometry.body.material = mat ops.limits.add(ShowersLimit(5678)) ops.detectors['bse'] = BackscatteredElectronEnergyDetector( 123, (0, 567)) ops.detectors['bse polar'] = BackscatteredElectronPolarAngularDetector( 125) ops.detectors['xrays'] = \ PhotonIntensityDetector((radians(30), radians(40)), (0, radians(360.0))) ops.detectors['prz'] = \ PhiZDetector((radians(30), radians(40)), (0, radians(360.0)), 750) # Export to WinX-Ray options wxrops = self.e.export_wxroptions(ops) # Test self.assertAlmostEqual(1.234, wxrops.getIncidentEnergy_keV(), 4) self.assertAlmostEqual(25.0, wxrops.getBeamDiameter_nm(), 4) self.assertEqual(5678, wxrops.getNbElectron()) zs, _wfs = wxrops.getElements() self.assertTrue(79 in zs) self.assertTrue(47 in zs) self.assertAlmostEqual(13.6007, wxrops.getMeanDensity_g_cm3(), 4) # internally calculated by WinXray self.assertAlmostEqual(123, wxrops.getMinimumElectronEnergy_eV(), 4) self.assertTrue(wxrops.isComputeBSEDistribution()) self.assertTrue(wxrops.isComputeBSEEnergy()) self.assertEqual(123, wxrops.getNbBSEEnergy()) self.assertTrue(wxrops.isComputeBSEAngular()) self.assertEqual(125, wxrops.getNbBSEAngular()) self.assertTrue(wxrops.isXrayCompute()) self.assertTrue(wxrops.isXrayComputeCharacteristic()) self.assertAlmostEqual(35.0, wxrops.getTOA_deg(), 4) self.assertAlmostEqual(55, wxrops.getAngleThetaDetector_deg(), 4) self.assertAlmostEqual(180.0, wxrops.getAnglePhiDetector_deg(), 4) self.assertEqual(750, wxrops.getNumberFilm())
def setUp(self): unittest.TestCase.setUp(self) self.ops = Options('aatest') self.ops.beam.energy_eV = 4e3 self.ops.geometry.material = \ Material({6: 0.4, 13: 0.6}, absorption_energy_eV={ELECTRON: 234.0}) self.ops.detectors['xray'] = PhotonIntensityDetector((0, 1), (2, 3)) self.ops.detectors['prz'] = PhiZDetector((0, 1), (2, 3), 128) self.ops.limits.add(ShowersLimit(1234)) self.i = Importer() self._testdata = os.path.join(os.path.dirname(__file__), 'testdata')
def setUp(self): TestCase.setUp(self) self.outputdir = tempfile.mkdtemp() self.workdir = tempfile.mkdtemp() ops = Options('test') ops.beam = PencilBeam(5e3) ops.geometry.body.material = \ Material({6: 0.4, 13: 0.6}, absorption_energy_eV={ELECTRON: 234.0}) ops.detectors['xray'] = \ PhotonIntensityDetector.annular(d2r(40.0), d2r(5.0)) ops.limits.add(ShowersLimit(1)) self.ops = Converter().convert(ops)[0] self.worker = Worker(program)
def setUp(self): TestCase.setUp(self) self.ops = Options() self.ops.detectors['xray'] = PhotonIntensityDetector((0, 1), (2, 3)) self.ops.detectors['fraction'] = ElectronFractionDetector() self.ops.detectors['time'] = TimeDetector() self.ops.detectors['showers'] = ShowersStatisticsDetector() self.ops.detectors['prz'] = PhiZDetector((0, 1), (2, 3), 100) self.ops.detectors['spectrum'] = \ PhotonSpectrumDetector((0, 1), (2, 3), 500, (0, 1000)) self.ops.limits.add(ShowersLimit(1000)) dirpath = os.path.join(os.path.dirname(__file__), 'testdata', 'al_10keV_1ke_001') self.results = Importer().import_(self.ops, dirpath)
def testexport(self): # Create ops = Options(name='test1') ops.beam.energy_eV = 30e3 ops.geometry.body.material = PenelopeMaterial.pure(29) ops.detectors['x-ray'] = \ PhotonIntensityDetector((radians(35), radians(45)), (0, radians(360.0))) ops.detectors['spectrum'] = \ PhotonSpectrumDetector((radians(35), radians(45)), (0, radians(360.0)), 500, (0, 1000)) ops.detectors['prz'] = \ PhotonDepthDetector((radians(0), radians(90)), (0, radians(360.0)), 500) ops.limits.add(TimeLimit(100)) ops.limits.add( UncertaintyLimit(Transition(29, siegbahn='Ka1'), 'x-ray', 0.05)) # Export opss = self.c.convert(ops) self.e.export(opss[0], self.tmpdir)
def testexport_different_opening(self): # Create options mat = Material({ 79: 0.5, 47: 0.5 }, 'Mat1', absorption_energy_eV={ELECTRON: 123.0}) ops = Options() ops.beam.energy_eV = 1234 ops.beam.diameter_m = 25e-9 ops.geometry.body.material = mat ops.limits.add(ShowersLimit(5678)) ops.detectors['xrays'] = \ PhotonIntensityDetector((radians(30), radians(40)), (0, radians(360.0))) ops.detectors['prz'] = \ PhiZDetector((radians(30), radians(50)), (0, radians(360.0)), 750) # Test self.assertRaises(ExporterException, self.e.export_wxroptions, ops)
def testconvert1(self): # Base options ops = Options("Test") ops.beam.origin_m = (0.0, 0.0, 0.09) ops.limits.add(ShowersLimit(1234)) det = PhotonIntensityDetector((radians(35), radians(45)), (0, radians(360.0))) ops.detectors['det1'] = det # Convert opss = self.converter.convert(ops) self.assertEqual(1, len(opss)) self.assertEqual(1, len(opss[0].detectors)) self.assertEqual(1, len(opss[0].limits)) limit = list(ops.limits.iterclass(ShowersLimit))[0] self.assertEqual(1234, limit.showers) self.assertEqual(6, len(opss[0].models))