Пример #1
0
    def __init__(self, settings):
        super().__init__()

        self.settings = settings

        self.builder = OptionsBuilder()
        self._list_options = []
        self._estimated = False
Пример #2
0
 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()))
Пример #3
0
    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()
Пример #4
0
    def testbuild5(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))

        det = PhotonDetector(3.3, 4.4)
        b.add_analysis(KRatioAnalysis(det))

        self.assertEqual(4, len(b))
        self.assertEqual(4, len(b.build()))
Пример #5
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()))
Пример #6
0
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
Пример #7
0
class OptionsModel(QtCore.QObject):

    beamsChanged = QtCore.Signal()
    samplesChanged = QtCore.Signal()
    analysesChanged = QtCore.Signal()
    programsChanged = QtCore.Signal()
    optionsChanged = QtCore.Signal()

    def __init__(self, settings):
        super().__init__()

        self.settings = settings

        self.builder = OptionsBuilder()
        self._list_options = []
        self._estimated = False

    def setSamples(self, samples):
        if self.builder.samples == samples:
            return

        self.builder.samples.clear()
        self.builder.samples.extend(samples)
        # self._calculate()
        self.samplesChanged.emit()
        self.optionsChanged.emit()

    def setBeams(self, beams):
        if self.builder.beams == beams:
            return

        self.builder.beams.clear()
        self.builder.beams.extend(beams)
        # self._calculate()
        self.beamsChanged.emit()
        self.optionsChanged.emit()

    def setAnalyses(self, analyses):
        if self.builder.analyses == analyses:
            return

        self.builder.analyses.clear()
        self.builder.analyses.extend(analyses)
        # self._calculate()
        self.analysesChanged.emit()
        self.optionsChanged.emit()

    def setPrograms(self, programs):
        if self.builder.programs == programs:
            return

        self.builder.programs.clear()
        self.builder.programs.extend(programs)
        # self._calculate()
        self.programsChanged.emit()
        self.optionsChanged.emit()

    def optionsList(self):
        return self.builder.build()

    def iterOptions(self):
        yield from self.builder.iterbuild()

    def optionsCount(self):
        with estimated_builder(self.builder):
            return len(self.builder)
Пример #8
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)
Пример #9
0
    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()