Exemplo n.º 1
0
def test_validate_sample_verticallayers_invalid(exporter, options):
    sample = VerticalLayerSample(VACUUM, VACUUM)
    sample.add_layer(ZINC, -1.0)

    erracc = ErrorAccumulator()
    exporter._validate_sample_verticallayers(sample, options, erracc)

    assert len(erracc.exceptions) == 3
    assert len(erracc.warnings) == 0
Exemplo n.º 2
0
    def testvalidate_sample_verticallayers_exception(self):
        sample = VerticalLayerSample(VACUUM, VACUUM)
        sample.add_layer(GALLIUM, -1.0)
        self.assertRaises(ValidationError, self.v.validate_sample, sample,
                          self.options)

        errors = set()
        self.v._validate_sample(sample, self.options, errors)
        self.assertEqual(3, len(errors))
Exemplo n.º 3
0
 def testverticallayers9(self):
     sample = VerticalLayerSample(Material.pure(39), Material.pure(40))
     sample.add_layer(Material.pure(41), 20e-9)
     sample.add_layer(Material.pure(42), 20e-9)
     sample.add_layer(Material.pure(44), 20e-9)
     sample.add_layer(Material.pure(45), 20e-9)
     sample.add_layer(Material.pure(46), 20e-9)
     sample.add_layer(Material.pure(47), 20e-9)
     sample.add_layer(Material.pure(48), 20e-9)
     self._run_and_test(sample)
Exemplo n.º 4
0
    def testexport_grainboundaries(self):
        # Options
        mat1 = Material('Mat1', {79: 0.5, 47: 0.5}, 2.0)
        mat2 = Material('Mat2', {29: 0.5, 30: 0.5}, 3.0)
        mat3 = Material('Mat3', {13: 0.5, 14: 0.5}, 4.0)

        sample = VerticalLayerSample(mat1, mat2)
        sample.add_layer(mat3, 25e-9)
        self.options.sample = sample

        # Export
        self.e.export(self.options, self.tmpdir)

        # Test
        filepaths = glob.glob(os.path.join(self.tmpdir, '*.sim'))
        self.assertEqual(1, len(filepaths))

        casfile = File()
        casfile.readFromFilepath(filepaths[0])
        simdata = casfile.getOptionSimulationData()
        regionops = simdata.getRegionOptions()

        self.assertEqual(3, regionops.getNumberRegions())

        region = regionops.getRegion(0)
        elements = list(map(operator.attrgetter('Z'), region.getElements()))
        self.assertAlmostEqual(mat1.density_kg_per_m3 / 1000.0, region.Rho, 4)
        self.assertEqual('Mat1', region.Name)
        self.assertEqual(2, len(elements))
        self.assertTrue(79 in elements)
        self.assertTrue(47 in elements)

        region = regionops.getRegion(1)
        elements = list(map(operator.attrgetter('Z'), region.getElements()))
        self.assertAlmostEqual(mat3.density_kg_per_m3 / 1000.0, region.Rho, 4)
        self.assertEqual('Mat3', region.Name)
        self.assertEqual(2, len(elements))
        self.assertTrue(13 in elements)
        self.assertTrue(14 in elements)

        region = regionops.getRegion(2)
        elements = list(map(operator.attrgetter('Z'), region.getElements()))
        self.assertAlmostEqual(mat2.density_kg_per_m3 / 1000.0, region.Rho, 4)
        self.assertEqual('Mat2', region.Name)
        self.assertEqual(2, len(elements))
        self.assertTrue(29 in elements)
        self.assertTrue(30 in elements)
Exemplo n.º 5
0
async def test_exporter_verticallayers_couple(
    event_loop, exporter, options, tmp_path, dry_run
):
    mat1 = Material("Mat1", {79: 0.5, 47: 0.5}, 2.0)
    mat2 = Material("Mat2", {29: 0.5, 30: 0.5}, 3.0)
    options.sample = VerticalLayerSample(mat1, mat2)

    await exporter.export(options, tmp_path, dry_run=dry_run)
    _test_export(tmp_path, 2, 2, dry_run)
Exemplo n.º 6
0
def create_model_sample(data, density_start = None, density_end = None):
    elements_data = get_elements_data(data)
    
    colors = generate_colors(steps = len(data) - 1)
    densities = generate_densities(elements_data, density_start, density_end)
    
    material_start, material_end = generate_end_materials(elements_data, colors, density_start, density_end)
    
    sample = VerticalLayerSample(material_start, material_end)
    
    # Iterate through all regions
    for i in range(1, len(data) - 1): # create the remaining regions (in the middle)
        density = densities[i]
        color = colors[i]
        material = Material(
                            name = f'region_{i}',
                            composition = to_weight_fraction(dict(elements_data.iloc[i])),
                            density_kg_per_m3 = density,
                            color = color)
        sample.add_layer(material, thickness_m = data[THICKNESS].iloc[i] / 1e6) # thickness is in micrometer
        
    # creating dummy materials to match template
    dummy_material = Material.from_formula('H', color = None, density_kg_per_m3 = MIN_DENSITY)
    for i in range(TEMPLATE_NUM_REGIONS - len(data)):
        sample.add_layer(dummy_material, thickness_m = MIN_THICKNESS)
    
    return sample
Exemplo n.º 7
0
def _create_samples():
    yield SubstrateSample(Material.pure(39))

    for number_layers in range(1, 10 + 1):
        sample = HorizontalLayerSample(Material.pure(39))
        for i in range(number_layers):
            sample.add_layer(Material.pure(40 + i), 20e-9)
        yield sample

    for number_layers in range(0, 9 + 1):
        sample = VerticalLayerSample(Material.pure(39), Material.pure(40))
        for i in range(number_layers):
            sample.add_layer(Material.pure(40 + i), 20e-9)
        yield sample
Exemplo n.º 8
0
    def _validate_sample_verticallayers(self, sample, options, errors):
        left_material = \
            self._validate_sample_verticallayers_left_material(sample.left_material, options, errors)
        right_material = \
            self._validate_sample_verticallayers_left_material(sample.right_material, options, errors)
        layers = \
            self._validate_sample_verticallayers_layers(sample.layers, options, errors)
        depth_m = \
            self._validate_sample_verticallayers_depth_m(sample.depth_m, options, errors)
        tilt_rad = \
            self._validate_sample_base_tilt_rad(sample.tilt_rad, options, errors)
        azimuth_rad = \
            self._validate_sample_base_azimuth_rad(sample.azimuth_rad, options, errors)

        return VerticalLayerSample(left_material, right_material, layers, depth_m, tilt_rad, azimuth_rad)
Exemplo n.º 9
0
def _create_samples(number_layers=2):
    yield SubstrateSample(Material.pure(39))

    yield InclusionSample(Material.pure(39), Material.pure(40), 20e-9)

    sample = HorizontalLayerSample(Material.pure(39))
    for i in range(number_layers):
        sample.add_layer(Material.pure(50 + i), 20e-9)
    yield sample

    sample = VerticalLayerSample(Material.pure(39), Material.pure(40))
    for i in range(number_layers):
        sample.add_layer(Material.pure(40 + i), 20e-9)
    yield sample

    yield SphereSample(Material.pure(39), 20e-9)
Exemplo n.º 10
0
    assert len(ax.collections) == 0


@pytest.mark.parametrize(
    "sample,perspective,expected_path_count",
    [
        (SubstrateSample(MATERIAL_DS), Perspective.XY, 1),
        (SubstrateSample(MATERIAL_DS), Perspective.XZ, 1),
        (SubstrateSample(MATERIAL_DS), Perspective.YZ, 1),
        (InclusionSample(MATERIAL_DS, MATERIAL_RG, 0.5), Perspective.XY, 2),
        (InclusionSample(MATERIAL_DS, MATERIAL_RG, 0.5), Perspective.XZ, 2),
        (InclusionSample(MATERIAL_DS, MATERIAL_RG, 0.5), Perspective.YZ, 2),
        (HorizontalLayerSample(MATERIAL_DS, LAYERS), Perspective.XY, 1),
        (HorizontalLayerSample(MATERIAL_DS, LAYERS), Perspective.XZ, 5),
        (HorizontalLayerSample(MATERIAL_DS, LAYERS), Perspective.YZ, 5),
        (VerticalLayerSample(MATERIAL_DS, MATERIAL_AU,
                             LAYERS), Perspective.XY, 6),
        (VerticalLayerSample(MATERIAL_DS, MATERIAL_AU,
                             LAYERS), Perspective.XZ, 6),
        (VerticalLayerSample(MATERIAL_DS, MATERIAL_AU,
                             LAYERS), Perspective.YZ, 1),
        (SphereSample(MATERIAL_DS, 0.5), Perspective.XY, 1),
        (SphereSample(MATERIAL_DS, 0.5), Perspective.XZ, 1),
        (SphereSample(MATERIAL_DS, 0.5), Perspective.YZ, 1),
    ],
)
def test_samplefigure_draw_sample(samplefigure, ax, sample, perspective,
                                  expected_path_count):
    samplefigure.sample = sample
    samplefigure.perspective = perspective

    samplefigure.draw(ax)
Exemplo n.º 11
0
 def test_compose_sample_vlayer(self):
     sample = VerticalLayerSample(self.mat_ds, self.mat_rg, self.layer)
     self._compose_sample(sample, (6, 1, 6))
Exemplo n.º 12
0
 def testverticallayers2(self):
     sample = VerticalLayerSample(Material.pure(39), Material.pure(40))
     self._run_and_test(sample)
Exemplo n.º 13
0
    def plot(self):
        tilt_rad = math.radians(self._slider_tilt_deg.value())
        rotation_rad = math.radians(self._slider_rotation_deg.value())

        layer = [
            Layer(RE, 10e-9),
            Layer(OS, 15e-9),
            Layer(IR, 20e-9),
            Layer(PT, 5e-9)
        ]

        sample_cls = self._combo_sample.currentData()

        if sample_cls == SubstrateSample:
            sample = SubstrateSample(DS,
                                     tilt_rad=tilt_rad,
                                     rotation_rad=rotation_rad)
        elif sample_cls == InclusionSample:
            sample = InclusionSample(DS,
                                     AU,
                                     0.5e-6,
                                     tilt_rad=tilt_rad,
                                     rotation_rad=rotation_rad)
        elif sample_cls == HorizontalLayerSample:
            sample = HorizontalLayerSample(DS,
                                           layer,
                                           tilt_rad=tilt_rad,
                                           rotation_rad=rotation_rad)
        elif sample_cls == VerticalLayerSample:
            sample = VerticalLayerSample(DS,
                                         RG,
                                         layer,
                                         tilt_rad=tilt_rad,
                                         rotation_rad=rotation_rad)
        elif sample_cls == SphereSample:
            sample = SphereSample(AU,
                                  0.5e-6,
                                  tilt_rad=tilt_rad,
                                  rotation_rad=rotation_rad)
        else:
            sample = None

        beam_cls = self._combo_beam.currentData()

        if beam_cls == GaussianBeam:
            beams = [GaussianBeam(42.0, 5e-9)]
        else:
            beams = []

        # trajectory_cls = self._combo_trajectory.currentData()

        # TODO handle trajectories
        trajectories = []

        sf = SampleFigure(sample, beams, trajectories)

        if self.radio_yz.isChecked():
            sf.perspective = Perspective.YZ
        elif self.radio_xy.isChecked():
            sf.perspective = Perspective.XY
        else:
            sf.perspective = Perspective.XZ

        self._figure.clf()

        ax = self._figure.add_subplot(111)

        ax.xaxis.set_visible(False)
        ax.yaxis.set_visible(False)

        sf.draw(ax)

        scalebar = ScaleBar(1.0, location="lower left")
        ax.add_artist(scalebar)

        self._canvas.draw_idle()
Exemplo n.º 14
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)
Exemplo n.º 15
0
 def testvalidate_sample_verticallayers(self):
     sample = VerticalLayerSample(COPPER, ZINC)
     sample.add_layer(GALLIUM, 1.0)
     sample2 = self.v.validate_sample(sample, self.options)
     self.assertEqual(sample2, sample)
     self.assertIsNot(sample2, sample)