def testbuild(self): b = OptionsBuilder() b.add_program(self.program) b.add_beam(self.create_basic_beam()) b.add_sample(self.create_basic_sample()) self.assertEqual(1, len(b)) self.assertEqual(1, len(b.build()))
def _create_standard_options(self, options): builder = OptionsBuilder() builder.add_program(options.program) beam = GaussianBeam(energy_eV=options.beam.energy_eV, diameter_m=0.0, 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)) for limit in options.limits: builder.add_limit(options.program, limit) for model in options.models: builder.add_model(options.program, model) analysis = PhotonIntensityAnalysis(self.photon_detector) builder.add_analysis(analysis) return builder.build()
def build_options(samples, beams, analysis, program): options_builder = OptionsBuilder() options_builder.add_program(program) for sample in samples: options_builder.add_sample(sample) for beam in beams: options_builder.add_beam(beam) options_builder.add_analysis(analysis) options = options_builder.build() return options
def testbuild3(self): b = OptionsBuilder() b.add_program(self.program) b.add_beam(self.create_basic_beam()) b.add_sample(self.create_basic_sample()) det = self.create_basic_photondetector() b.add_analysis(KRatioAnalysis(det)) self.assertEqual(2, len(b)) self.assertEqual(2, len(b.build()))
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 main(argv=None): options_builder = OptionsBuilder() program = Casino2Program() program.number_trajectories = 1000 options_builder.add_program(program) beam_builder = GaussianBeamBuilder() beam_builder.add_energy_eV(15e3) beam_builder.add_diameter_m(10e-9) beam_builder.add_linescan_x(-1e-07, 1e-07, 5e-08) beams = beam_builder.build() print("beams", beams) options_builder.beams.extend(beams) mat1 = Material.pure(26) mat2 = Material.pure(14) sample = VerticalLayerSample(mat1, mat2) options_builder.add_sample(sample) photon_detector = PhotonDetector("xray", math.radians(35.0)) # analysis = KRatioAnalysis(photon_detector) analysis = PhotonIntensityAnalysis(photon_detector) options_builder.add_analysis(analysis) list_options = options_builder.build() # Run simulation project = Project() # for options in opt: with LocalSimulationRunner(project, max_workers=3) as runner: futures = runner.submit(*list_options) print("{} simulations launched".format(len(futures))) while not runner.wait(1): print(runner.progress) print("{} simulations succeeded".format(runner.done_count)) print("{} simulations failed".format(runner.failed_count)) for future in runner.failed_futures: print(future.exception()) # Results project.recalculate() print("{} were simulated".format(len(project.simulations))) ################################################################################################ ### Ab hier wird es relevant ### ################################################################################################ # Hier werden die Ergebnisse gespeichert data_all = [] for simulation in project.simulations: # results = simulation.results position = simulation.options.beam.x0_m for unkresult in simulation.find_result(EmittedPhotonIntensityResult): for xrayline, unkintensity in unkresult.items(): # z = xrayline.atomic_number data = unkintensity.nominal_value data_all.append((xrayline, position, data)) results = {} # Zu jeder simulierten Röntgenlinie wird der Datensatz in einem Dictionary gespeichert for x, p, d in data_all: if not x in results: results[x] = [] results[x].append((p, d)) # Sortiere Werte und gebe sie aus sorted_results = [] for k, v in results.items(): v.sort(key=lambda t: t[0]) print("{}\t{}".format(k, v)) print(v) plot_results(k, v) sorted_results.append((k, v)) return sorted_results print(sorted_results)