Exemple #1
0
def test_validate_sample_horizontallayers_invalid(exporter, options):
    sample = HorizontalLayerSample(COPPER)
    sample.add_layer(ZINC, -1.0)

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

    assert len(erracc.exceptions) == 1
    assert len(erracc.warnings) == 0
Exemple #2
0
    def testvalidate_sample_horizontallayers_exception(self):
        sample = HorizontalLayerSample(COPPER)
        sample.add_layer(ZINC, -1.0)
        self.assertRaises(ValidationError, self.v.validate_sample, sample,
                          self.options)

        errors = set()
        self.v._validate_sample(sample, self.options, errors)
        self.assertEqual(1, len(errors))
Exemple #3
0
 def testhorizontallayers8(self):
     sample = HorizontalLayerSample(Material.pure(39))
     sample.add_layer(Material.pure(40), 20e-9)
     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)
     self._run_and_test(sample)
Exemple #4
0
    def testexport_multilayers1(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 = HorizontalLayerSample(mat1)
        sample.add_layer(mat2, 25e-9)
        sample.add_layer(mat3, 55e-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(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)

        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(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)
Exemple #5
0
async def test_exporter_horizontallayers(
    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 = HorizontalLayerSample(mat1)
    options.sample.add_layer(mat2, 10e-9)

    await exporter.export(options, tmp_path, dry_run=dry_run)
    _test_export(tmp_path, 2, 2, dry_run)
Exemple #6
0
    def _validate_sample_horizontallayers(self, sample, options, errors):
        substrate_material = \
            self._validate_sample_horizontallayers_substrate_material(sample.substrate_material, options, errors)
        layers = \
            self._validate_sample_horizontallayers_layers(sample.layers, 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 HorizontalLayerSample(substrate_material, layers, tilt_rad, azimuth_rad)
Exemple #7
0
def run():  # pragma: no cover
    import sys
    from pymontecarlo.options.beam import GaussianBeam
    from pymontecarlo.options.sample import HorizontalLayerSample
    from pymontecarlo.options.material import Material

    app = QtWidgets.QApplication(sys.argv)

    widget = SampleFigureWidget()

    sample = HorizontalLayerSample(Material.pure(29))
    sample.add_layer(Material.pure(30), 10e-9)
    widget.setSample(sample)

    beam = GaussianBeam(15e3, 5e-9)
    widget.addBeam(beam)

    mainwindow = QtWidgets.QMainWindow()
    mainwindow.setCentralWidget(widget)
    mainwindow.show()

    app.exec_()
Exemple #8
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
Exemple #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)
Exemple #10
0
def test_samplefigure_draw_nothing(samplefigure, ax):
    samplefigure.draw(ax)
    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):
Exemple #11
0
 def test_compose_sample_hlayer(self):
     sample = HorizontalLayerSample(self.mat_ds, self.layer)
     self._compose_sample(sample, (5, 5, 1))
Exemple #12
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()
Exemple #13
0
 def testvalidate_sample_horizontallayers_empty_layer(self):
     sample = HorizontalLayerSample(COPPER)
     sample.add_layer(ZINC, 1.0)
     sample.add_layer(VACUUM, 2.0)
     sample2 = self.v.validate_sample(sample, self.options)
     self.assertEqual(1, len(sample2.layers))
Exemple #14
0
 def testvalidate_sample_horizontallayers(self):
     sample = HorizontalLayerSample(COPPER)
     sample.add_layer(ZINC, 1.0)
     sample2 = self.v.validate_sample(sample, self.options)
     self.assertEqual(sample2, sample)
     self.assertIsNot(sample2, sample)