def setUp(self): TestCase.setUp(self) self.tmpdir = tempfile.mkdtemp() self.c = Converter() self.e = Exporter()
class TestPenelopeConverter(TestCase): def setUp(self): TestCase.setUp(self) self.converter = Converter((0.1, 0.2), 51.2, 53.4) def tearDown(self): TestCase.tearDown(self) def testskeleton(self): self.assertTrue(True) 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_nolimit(self): # Base options ops = Options(name="Test") # Convert opss = self.converter.convert(ops) # Test self.assertEqual(0, len(opss))
def setUp(self): TestCase.setUp(self) self.outputdir = tempfile.mkdtemp() self.workdir = tempfile.mkdtemp() ops = Options('test') ops.detectors['time'] = TimeDetector() ops.limits.add(ShowersLimit(1)) self.ops = Converter().convert(ops)[0] self.worker = Worker(program)
def setUp(self): TestCase.setUp(self) self.converter = Converter((0.1, 0.2), 51.2, 53.4)
class TestPenelopeExporter(TestCase): def setUp(self): TestCase.setUp(self) self.tmpdir = tempfile.mkdtemp() self.c = Converter() self.e = Exporter() def tearDown(self): TestCase.tearDown(self) shutil.rmtree(self.tmpdir, ignore_errors=True) 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 test_append_photon_detectors_maxlimit(self): ops = Options() ops.limits.add(TimeLimit(100)) for i in range(MAX_PHOTON_DETECTORS + 1): ops.detectors['det%i' % i] = \ PhotonSpectrumDetector((radians(i), radians(45)), (0, radians(360.0)), 500, (0, 1000)) opss = self.c.convert(ops) self.assertRaises(ExporterException, self.e.export, opss[0], self.tmpdir) def test_append_photon_detectors_maxchannels(self): ops = Options() ops.limits.add(TimeLimit(100)) ops.detectors['spectrum'] = \ PhotonSpectrumDetector((radians(35), radians(45)), (0, radians(360.0)), 50000, (0, 1000)) opss = self.c.convert(ops) self.e.export(opss[0], self.tmpdir) def test_photon_depth_detector(self): # Create ops = Options(name='test1') ops.beam.energy_eV = 30e3 ops.geometry.body.material = PenelopeMaterial.pure(29) ops.detectors['prz'] = \ PhotonDepthDetector((radians(0), radians(90)), (0, radians(360.0)), 500, [Transition(29, siegbahn='Ka1')]) ops.limits.add(TimeLimit(100)) # Export opss = self.c.convert(ops) self.e.export(opss[0], self.tmpdir) def testinteraction_forcing(self): ops = Options() ops.beam.energy_eV = 30e3 intfor = InteractionForcing(ELECTRON, HARD_ELASTIC, -40) ops.geometry.material = PenelopeMaterial.pure( 29, interaction_forcings=[intfor]) ops.detectors['det1'] = TimeDetector() ops.limits.add(TimeLimit(100)) opss = self.c.convert(ops) self.e.export(opss[0], self.tmpdir)
class TestPenelopeExporter(TestCase): def setUp(self): TestCase.setUp(self) self.tmpdir = tempfile.mkdtemp() self.c = Converter() self.e = Exporter() def tearDown(self): TestCase.tearDown(self) shutil.rmtree(self.tmpdir, ignore_errors=True) 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 test_append_photon_detectors_maxlimit(self): ops = Options() ops.limits.add(TimeLimit(100)) for i in range(MAX_PHOTON_DETECTORS + 1): ops.detectors['det%i' % i] = \ PhotonSpectrumDetector((radians(i), radians(45)), (0, radians(360.0)), 500, (0, 1000)) opss = self.c.convert(ops) self.assertRaises(ExporterException, self.e.export, opss[0], self.tmpdir) def test_append_photon_detectors_maxchannels(self): ops = Options() ops.limits.add(TimeLimit(100)) ops.detectors['spectrum'] = \ PhotonSpectrumDetector((radians(35), radians(45)), (0, radians(360.0)), 50000, (0, 1000)) opss = self.c.convert(ops) self.e.export(opss[0], self.tmpdir) def test_photon_depth_detector(self): # Create ops = Options(name='test1') ops.beam.energy_eV = 30e3 ops.geometry.body.material = PenelopeMaterial.pure(29) ops.detectors['prz'] = \ PhotonDepthDetector((radians(0), radians(90)), (0, radians(360.0)), 500, [Transition(29, siegbahn='Ka1')]) ops.limits.add(TimeLimit(100)) # Export opss = self.c.convert(ops) self.e.export(opss[0], self.tmpdir) def testinteraction_forcing(self): ops = Options() ops.beam.energy_eV = 30e3 intfor = InteractionForcing(ELECTRON, HARD_ELASTIC, -40) ops.geometry.material = PenelopeMaterial.pure(29, interaction_forcings=[intfor]) ops.detectors['det1'] = TimeDetector() ops.limits.add(TimeLimit(100)) opss = self.c.convert(ops) self.e.export(opss[0], self.tmpdir)