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(name="Test") ops.beam = PencilBeam(1234) ops.detectors['bse'] = BackscatteredElectronEnergyDetector(1000, (0, 1234)) ops.detectors['photon'] = \ PhotonSpectrumDetector((radians(35), radians(45)), (0, radians(360.0)), 1000, (12.34, 56.78)) ops.limits.add(ShowersLimit(5678)) ops.limits.add(TimeLimit(60)) # Convert opss = self.converter.convert(ops) # Test self.assertEqual(1, len(opss)) self.assertAlmostEqual(1234, opss[0].beam.energy_eV, 4) self.assertEqual(1, len(opss[0].detectors)) det = ops.detectors['bse'] self.assertAlmostEqual(0, det.limits_eV[0], 4) self.assertAlmostEqual(1234, det.limits_eV[1], 4) self.assertEqual(1000, det.channels) self.assertEqual(1, len(opss[0].limits)) limit = list(ops.limits.iterclass(ShowersLimit))[0] self.assertEqual(5678, limit.showers) self.assertEqual(7, len(opss[0].models))
def _run(self, element): self._update_status(0.1, "Check version") if self.is_cancelled(): return version = self._read_version(element) if version != VERSION: raise ValueError("Incompatible version: %s != %s" % (version, VERSION)) self._update_status(0.13, "Reading name") if self.is_cancelled(): return name = self._read_name(element) options = Options(name) self._update_status(0.16, "Reading UUID") if self.is_cancelled(): return options._uuid = self._read_uuid(element) self._update_status(0.2, "Reading programs") if self.is_cancelled(): return options.programs.update(self._read_programs(element)) self._update_status(0.3, "Reading beams") if self.is_cancelled(): return options.beam = self._read_beams(element) self._update_status(0.4, "Reading geometries") if self.is_cancelled(): return options.geometry = self._read_geometries(element) self._update_status(0.6, "Reading detectors") if self.is_cancelled(): return options.detectors.update(self._read_detectors(element)) self._update_status(0.8, "Reading limits") if self.is_cancelled(): return options.limits.update(self._read_limits(element)) self._update_status(0.9, "Reading models") if self.is_cancelled(): return options.models.update(self._read_models(element)) return options
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 testconvert_pencilbeam(self): # Base options ops = Options(name="Test") ops.beam = PencilBeam(1234) ops.limits.add(ShowersLimit(100)) ops.detectors['trajectories'] = TrajectoryDetector(False) # Convert opss = self.converter.convert(ops) # Test self.assertEqual(1, len(opss)) self.assertAlmostEqual(1234, opss[0].beam.energy_eV, 4) self.assertAlmostEqual(0.0, opss[0].beam.diameter_m, 4) self.assertEqual(5, len(opss[0].models))
def testconvert_pencilbeam(self): # Base options ops = Options(name="Test") ops.beam = PencilBeam(1234) ops.detectors['det1'] = TimeDetector() ops.limits.add(TimeLimit(100)) # Convert with warnings.catch_warnings(record=True) as ws: opss = self.converter.convert(ops) # 7 warning: # PencilBeam -> GaussianBeam # Set default models (6) self.assertEqual(1, len(opss)) self.assertEqual(7, len(ws)) # Test self.assertAlmostEqual(1234, opss[0].beam.energy_eV, 4) self.assertAlmostEqual(0.0, opss[0].beam.diameter_m, 4) self.assertEqual(6, len(opss[0].models))
def testconvert_pencilbeam(self): # Base options ops = Options(name="Test") ops.beam = PencilBeam(1234) ops.limits.add(ShowersLimit(100)) ops.detectors['trajectories'] = TrajectoryDetector(False) # Convert with warnings.catch_warnings(record=True) as ws: opss = self.converter.convert(ops) # 7 warning: # PencilBeam -> GaussianBeam # Set default models (6) self.assertEqual(1, len(opss)) self.assertEqual(7, len(ws)) # Test self.assertAlmostEqual(1234, opss[0].beam.energy_eV, 4) self.assertAlmostEqual(0.0, opss[0].beam.diameter_m, 4) self.assertEqual(6, len(opss[0].models))