Beispiel #1
0
def simulation():
    program = ProgramMock()
    beam = GaussianBeam(15e3, 10e-9)
    sample = SubstrateSample(Material.pure(29))
    detector = PhotonDetector("xray", math.radians(40.0))
    analyses = [PhotonIntensityAnalysis(detector)]
    tags = ["basic", "test"]
    options = Options(program, beam, sample, analyses, tags)

    results = []

    analysis = PhotonIntensityAnalysis(detector)
    builder = EmittedPhotonIntensityResultBuilder(analysis)
    builder.add_intensity((29, "Ka1"), 1.0, 0.1)
    builder.add_intensity((29, "Ka2"), 2.0, 0.2)
    builder.add_intensity((29, "Kb1"), 4.0, 0.5)
    builder.add_intensity((29, "Kb3"), 5.0, 0.7)
    builder.add_intensity((29, "Kb5I"), 1.0, 0.1)
    builder.add_intensity((29, "Kb5II"), 0.5, 0.1)
    builder.add_intensity((29, "Ll"), 3.0, 0.1)
    results.append(builder.build())

    analysis = KRatioAnalysis(detector)
    builder = KRatioResultBuilder(analysis)
    builder.add_kratio((29, "Ka1"), 1.0, 1.0)
    builder.add_kratio((29, "Ka2"), 2.0, 1.0)
    builder.add_kratio((29, "Kb1"), 0.5, 1.0)
    builder.add_kratio((29, "Kb3"), 1.5, 1.0)
    builder.add_kratio((29, "Kb5I"), 1.0, 1.0)
    builder.add_kratio((29, "Kb5II"), 0.5, 1.0)
    builder.add_kratio((29, "Ll"), 2.0, 1.0)
    results.append(builder.build())

    return Simulation(options, results)
Beispiel #2
0
def project(simulation):
    project = Project()

    # Simulation 1
    sim1 = copy.deepcopy(simulation)
    sim1.options.tags.append("sim1")
    project.add_simulation(sim1)

    # Simulation 2
    sim2 = copy.deepcopy(simulation)
    sim2.options.tags.append("sim2")
    sim2.options.beam.energy_eV = 20e3
    project.add_simulation(sim2)

    # Simulation 3
    sim3 = copy.deepcopy(simulation)
    sim3.options.beam.diameter_m = 20e-9

    analysis = PhotonIntensityAnalysis(sim3.options.detectors[0])
    b = GeneratedPhotonIntensityResultBuilder(analysis)
    b.add_intensity((29, "Ka1"), 10.0, 0.1)
    b.add_intensity((29, "Ka2"), 20.0, 0.2)
    b.add_intensity((29, "Kb1"), 40.0, 0.5)

    sim3.results.append(b.build())
    project.add_simulation(sim3)

    return project
Beispiel #3
0
def testexpand_analyses_to_single_detector():
    det1 = PhotonDetector("det1", 0.1)
    det2 = PhotonDetector("det2", 3.3)

    analyses = [
        PhotonIntensityAnalysis(det1),
        PhotonIntensityAnalysis(det2),
        KRatioAnalysis(det1),
        KRatioAnalysis(det2),
    ]

    combinations = expand_analyses_to_single_detector(analyses)
    assert len(combinations) == 2

    combinations = expand_to_single(analyses)
    assert len(combinations) == 4
Beispiel #4
0
def options():
    program = Casino2Program(number_trajectories=50)
    beam = GaussianBeam(15e3, 10e-9)
    sample = SubstrateSample(Material.pure(29))
    detector = PhotonDetector("xray", math.radians(40.0))
    analyses = [PhotonIntensityAnalysis(detector)]
    tags = ["basic", "test"]
    return Options(program, beam, sample, analyses, tags)
Beispiel #5
0
 def create_basic_options(self):
     beam = self.create_basic_beam()
     sample = self.create_basic_sample()
     analyses = [
         PhotonIntensityAnalysis(self.create_basic_photondetector())
     ]
     limits = [ShowersLimit(100)]
     models = [ElasticCrossSectionModel.RUTHERFORD]
     return Options(self.program, beam, sample, analyses, limits, models)
Beispiel #6
0
def options():
    program = PenepmaProgram(number_trajectories=100)
    program.exporter.dump_interval_s = 2
    beam = CylindricalBeam(15e3, 10e-9)
    sample = SubstrateSample(Material.pure(29))
    detector = PhotonDetector("xray", math.radians(40.0))
    analyses = [PhotonIntensityAnalysis(detector)]
    tags = ["basic", "test"]
    return Options(program, beam, sample, analyses, tags)
Beispiel #7
0
def test_validate_analysis_photonintensity(exporter, options):
    detector = PhotonDetector("test", 1.0, 1.0)
    analysis = PhotonIntensityAnalysis(detector)

    erracc = ErrorAccumulator()
    exporter._validate_analysis_photonintensity(analysis, options, erracc)

    assert len(erracc.exceptions) == 0
    assert len(erracc.warnings) == 0
Beispiel #8
0
    def testvalidate_analysis_photonintensity_exception(self):
        detector = PhotonDetector('', 2.0, -1.0)
        analysis = PhotonIntensityAnalysis(detector)
        self.assertRaises(ValidationError, self.v.validate_analysis, analysis,
                          self.options)

        errors = set()
        self.v._validate_analysis(analysis, self.options, errors)
        self.assertEqual(3, len(errors))
Beispiel #9
0
 def create_basic_photonintensityresult(self):
     analysis = PhotonIntensityAnalysis(self.create_basic_photondetector())
     b = EmittedPhotonIntensityResultBuilder(analysis)
     b.add_intensity((29, 'Ka1'), 1.0, 0.1)
     b.add_intensity((29, 'Ka2'), 2.0, 0.2)
     b.add_intensity((29, 'Kb1'), 4.0, 0.5)
     b.add_intensity((29, 'Kb3'), 5.0, 0.7)
     b.add_intensity((29, 'Kb5I'), 1.0, 0.1)
     b.add_intensity((29, 'Kb5II'), 0.5, 0.1)
     b.add_intensity((29, 'Ll'), 3.0, 0.1)
     return b.build()
Beispiel #10
0
def options():
    """
    Creates basic options using the mock program.
    """
    program = ProgramMock()
    beam = GaussianBeam(15e3, 10e-9)
    sample = SubstrateSample(Material.pure(29))
    detector = PhotonDetector("xray", math.radians(40.0))
    analyses = [PhotonIntensityAnalysis(detector)]
    tags = ["basic", "test"]
    return Options(program, beam, sample, analyses, tags)
Beispiel #11
0
def builder():
    detector = PhotonDetector("det", 1.1, 2.2)
    analysis = PhotonIntensityAnalysis(detector)

    builder = EmittedPhotonIntensityResultBuilder(analysis)
    builder.add_intensity((13, "Ka1"), 1.0, 0.1)
    builder.add_intensity((13, "Ka2"), 2.0, 0.2)
    builder.add_intensity((13, "Kb1"), 4.0, 0.5)
    builder.add_intensity((13, "Kb3"), 5.0, 0.7)
    builder.add_intensity((13, "Ll"), 3.0, 0.1)
    return builder
Beispiel #12
0
    def testbuild4(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))
        b.add_analysis(PhotonIntensityAnalysis(det))

        self.assertEqual(2, len(b))
        self.assertEqual(2, len(b.build()))
Beispiel #13
0
    def create_basic_project(self):
        project = Project()

        sim1 = self.create_basic_simulation()
        project.add_simulation(sim1)

        sim2 = self.create_basic_simulation()
        sim2.options.beam.energy_eV = 20e3
        project.add_simulation(sim2)

        analysis = PhotonIntensityAnalysis(self.create_basic_photondetector())
        b = GeneratedPhotonIntensityResultBuilder(analysis)
        b.add_intensity((29, 'Ka1'), 10.0, 0.1)
        b.add_intensity((29, 'Ka2'), 20.0, 0.2)
        b.add_intensity((29, 'Kb1'), 40.0, 0.5)

        sim3 = self.create_basic_simulation()
        sim3.options.beam.diameter_m = 20e-9
        sim3.results.append(b.build())
        project.add_simulation(sim3)

        return project
Beispiel #14
0
    def _validate_analysis_photonintensity(self, analysis, options, errors):
        photon_detector = \
            self._validate_detector_photon(analysis.photon_detector, options, errors)

        return PhotonIntensityAnalysis(photon_detector)
Beispiel #15
0
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)
Beispiel #16
0
 def testvalidate_analysis_photonintensity(self):
     detector = PhotonDetector('det', 1.1, 2.2)
     analysis = PhotonIntensityAnalysis(detector)
     analysis2 = self.v.validate_analysis(analysis, self.options)
     self.assertEqual(analysis2, analysis)
     self.assertIsNot(analysis2, analysis)