def estimated_builder(builder): program_mock_added = False if not builder.programs: builder.add_program(ProgramMock()) program_mock_added = True beam_mock_added = False if not builder.beams: builder.add_beam(PencilBeam(10e3)) beam_mock_added = True sample_mock_added = False if not builder.samples: builder.add_sample(SubstrateSample(Material.pure(26))) sample_mock_added = True try: yield builder finally: if program_mock_added: builder.programs.clear() if beam_mock_added: builder.beams.clear() if sample_mock_added: builder.samples.clear()
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 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 _create_standard_options(self, options): builder = OptionsBuilder(tags=[TAG_STANDARD]) program = copy.copy(options.program) builder.add_program(program) beam = PencilBeam(energy_eV=options.beam.energy_eV, particle=options.beam.particle) builder.add_beam(beam) for material in options.sample.materials: for z in material.composition: standard = self.get_standard_material(z) builder.add_sample(SubstrateSample(standard)) analysis = PhotonIntensityAnalysis(self.photon_detector) builder.add_analysis(analysis) return builder.build()
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))
samplefigure.draw(ax) assert len(ax.collections) == 1 assert len(ax.collections[0]._paths) == expected_path_count @pytest.mark.parametrize( "beam,perspective,expected_path_count", [ (GaussianBeam(1, 1), Perspective.XY, 1), (GaussianBeam(1, 1), Perspective.XZ, 1), (GaussianBeam(1, 1), Perspective.YZ, 1), (CylindricalBeam(1, 1), Perspective.XY, 1), (CylindricalBeam(1, 1), Perspective.XZ, 1), (CylindricalBeam(1, 1), Perspective.YZ, 1), (PencilBeam(1), Perspective.XY, 1), (PencilBeam(1), Perspective.XZ, 1), (PencilBeam(1), Perspective.YZ, 1), ], ) def test_samplefigure_draw_beam(samplefigure, ax, beam, perspective, expected_path_count): samplefigure.beams.append(beam) samplefigure.perspective = perspective samplefigure.draw(ax) assert len(ax.collections) == 1 assert len(ax.collections[0]._paths) == expected_path_count
async def test_exporter_beam_pencil(event_loop, exporter, options, tmp_path, dry_run): options.beam = PencilBeam(10e3) await exporter.export(options, tmp_path, dry_run=dry_run) _test_export(tmp_path, 1, 1, dry_run)