示例#1
0
 def testconvert_parse_same_layer(self):
     handler = HorizontalLayerSampleHDF5Handler()
     sample = HorizontalLayerSample(COPPER, tilt_rad=0.1, azimuth_rad=0.2)
     layer = sample.add_layer(ZINC, 20e-9)
     sample.add_layer(GALLIUM, 50e-9)
     sample.layers.append(layer)
     sample2 = self.convert_parse_hdf5handler(handler, sample)
     self.assertEqual(sample2, sample)
示例#2
0
 def testconvert_parse_same_material(self):
     handler = HorizontalLayerSampleHDF5Handler()
     sample = HorizontalLayerSample(COPPER, tilt_rad=0.1, azimuth_rad=0.2)
     sample.add_layer(ZINC, 20e-9)
     sample.add_layer(COPPER, 50e-9)
     sample.add_layer(ZINC, 30e-9)
     sample2 = self.convert_parse_hdf5handler(handler, sample)
     self.assertEqual(sample2, sample)
示例#3
0
 def testconvert_vacuum(self):
     handler = HorizontalLayerSampleSeriesHandler()
     sample = HorizontalLayerSample(COPPER, tilt_rad=0.1, azimuth_rad=0.2)
     sample.add_layer(VACUUM, 20e-9)
     sample.add_layer(GALLIUM, 50e-9)
     s = handler.convert(sample)
     self.assertEqual(8, len(s))
示例#4
0
 def testconvert(self):
     handler = HorizontalLayerSampleHtmlHandler()
     sample = HorizontalLayerSample(COPPER, tilt_rad=0.1, azimuth_rad=0.2)
     sample.add_layer(ZINC, 20e-9)
     sample.add_layer(GALLIUM, 50e-9)
     root = handler.convert(sample)
     self.assertEqual(8, len(root.children))
示例#5
0
 def testconvert_parse_vacuum(self):
     handler = HorizontalLayerSampleHDF5Handler()
     sample = HorizontalLayerSample(COPPER, tilt_rad=0.1, azimuth_rad=0.2)
     sample.add_layer(VACUUM, 20e-9)
     sample.add_layer(GALLIUM, 50e-9)
     sample2 = self.convert_parse_hdf5handler(handler, sample)
     self.assertEqual(sample2, sample)
示例#6
0
    def testconvert(self):
        handler = OptionsHtmlHandler()
        options = self.create_basic_options()

        sample = HorizontalLayerSample(COPPER, tilt_rad=0.1, azimuth_rad=0.2)
        sample.add_layer(ZINC, 20e-9)
        sample.add_layer(VACUUM, 20e-9)
        sample.add_layer(GALLIUM, 50e-9)
        options.sample = sample

        detector = PhotonDetector('xray2', 2.2, 3.3)
        analysis = KRatioAnalysis(detector)
        analysis.add_standard_material(29, COPPER)
        analysis.add_standard_material(30, ZINC)
        options.analyses.append(analysis)

        doc = handler.convert(options)
        self.assertEqual(12, len(doc.getElementsByTagName('dt')))
    def setUp(self):
        super().setUp()

        self.s1 = HorizontalLayerSample(COPPER)
        self.s2 = HorizontalLayerSample(None)  # No substrate
        self.s3 = HorizontalLayerSample(COPPER)  # Empty layer

        self.s1.add_layer(ZINC, 123.456)
        self.s1.add_layer(GALLIUM, 456.789)

        self.s2.add_layer(ZINC, 123.456)
        self.s2.add_layer(GALLIUM, 456.789)

        self.s3.add_layer(ZINC, 123.456)
        self.s3.add_layer(GALLIUM, 456.789)
        self.s3.add_layer(COPPER, 456.123)
示例#8
0
def test_horizontallayerssample_ne(sample):
    other = HorizontalLayerSample(ZINC)
    other.add_layer(ZINC, 123.456)
    other.add_layer(GALLIUM, 456.789)
    assert sample != other

    other = HorizontalLayerSample(COPPER)
    other.add_layer(GALLIUM, 456.789)
    assert sample != other

    other = HorizontalLayerSample(COPPER)
    other.add_layer(ZINC, 9999)
    other.add_layer(GALLIUM, 456.789)
    assert sample != other
示例#9
0
def test_horizontallayerssample_eq(sample):
    if sample.has_substrate():
        other = HorizontalLayerSample(COPPER)
        other.add_layer(ZINC, 123.456)
        other.add_layer(GALLIUM, 456.789)
        assert sample == other

    else:
        other = HorizontalLayerSample(None)
        other.add_layer(ZINC, 123.456)
        other.add_layer(GALLIUM, 456.789)
        assert sample == other
示例#10
0
def sample(request):
    sample = HorizontalLayerSample(request.param)
    sample.add_layer(ZINC, 123.456)
    sample.add_layer(GALLIUM, 456.789)
    return sample
class TestHorizontalLayerSample(TestCase):
    def setUp(self):
        super().setUp()

        self.s1 = HorizontalLayerSample(COPPER)
        self.s2 = HorizontalLayerSample(None)  # No substrate
        self.s3 = HorizontalLayerSample(COPPER)  # Empty layer

        self.s1.add_layer(ZINC, 123.456)
        self.s1.add_layer(GALLIUM, 456.789)

        self.s2.add_layer(ZINC, 123.456)
        self.s2.add_layer(GALLIUM, 456.789)

        self.s3.add_layer(ZINC, 123.456)
        self.s3.add_layer(GALLIUM, 456.789)
        self.s3.add_layer(COPPER, 456.123)

    def testskeleton(self):
        # Horizontal layers 1
        self.assertTrue(self.s1.has_substrate())
        self.assertEqual(COPPER, self.s1.substrate_material)

        self.assertEqual(2, len(self.s1.layers))
        self.assertEqual(ZINC, self.s1.layers[0].material)
        self.assertAlmostEqual(123.456, self.s1.layers[0].thickness_m, 4)
        self.assertEqual(GALLIUM, self.s1.layers[1].material)
        self.assertAlmostEqual(456.789, self.s1.layers[1].thickness_m, 4)

        # Horizontal layers 2
        self.assertFalse(self.s2.has_substrate())

        self.assertEqual(2, len(self.s2.layers))
        self.assertEqual(ZINC, self.s2.layers[0].material)
        self.assertAlmostEqual(123.456, self.s2.layers[0].thickness_m, 4)
        self.assertEqual(GALLIUM, self.s2.layers[1].material)
        self.assertAlmostEqual(456.789, self.s2.layers[1].thickness_m, 4)

        # Horizontal layers 3
        self.assertTrue(self.s3.has_substrate())
        self.assertEqual(COPPER, self.s3.substrate_material)

        self.assertEqual(3, len(self.s3.layers))
        self.assertEqual(ZINC, self.s3.layers[0].material)
        self.assertAlmostEqual(123.456, self.s3.layers[0].thickness_m, 4)
        self.assertEqual(GALLIUM, self.s3.layers[1].material)
        self.assertAlmostEqual(456.789, self.s3.layers[1].thickness_m, 4)
        self.assertEqual(COPPER, self.s3.layers[2].material)
        self.assertAlmostEqual(456.123, self.s3.layers[2].thickness_m, 4)

    def testsubstrate(self):
        self.s1.substrate_material = VACUUM
        self.assertFalse(self.s1.has_substrate())

    def testmaterials(self):
        self.assertEqual(3, len(self.s1.materials))
        self.assertEqual(2, len(self.s2.materials))
        self.assertEqual(3, len(self.s3.materials))

    def testlayers_zpositions_m(self):
        # Horizontal layers 1
        zpositions_m = self.s1.layers_zpositions_m
        self.assertEqual(len(self.s1.layers), len(zpositions_m))

        zmin_m, zmax_m = zpositions_m[0]
        self.assertAlmostEqual(-123.456, zmin_m, 4)
        self.assertAlmostEqual(0.0, zmax_m, 4)

        zmin_m, zmax_m = zpositions_m[1]
        self.assertAlmostEqual(-123.456 - 456.789, zmin_m, 4)
        self.assertAlmostEqual(-123.456, zmax_m, 4)

        # Horizontal layers 2
        zpositions_m = self.s2.layers_zpositions_m
        self.assertEqual(len(self.s2.layers), len(zpositions_m))

        zmin_m, zmax_m = zpositions_m[0]
        self.assertAlmostEqual(-123.456, zmin_m, 4)
        self.assertAlmostEqual(0.0, zmax_m, 4)

        zmin_m, zmax_m = zpositions_m[1]
        self.assertAlmostEqual(-123.456 - 456.789, zmin_m, 4)
        self.assertAlmostEqual(-123.456, zmax_m, 4)

        # Horizontal layers 3
        zpositions_m = self.s3.layers_zpositions_m
        self.assertEqual(len(self.s3.layers), len(zpositions_m))

        zmin_m, zmax_m = zpositions_m[0]
        self.assertAlmostEqual(-123.456, zmin_m, 4)
        self.assertAlmostEqual(0.0, zmax_m, 4)

        zmin_m, zmax_m = zpositions_m[1]
        self.assertAlmostEqual(-123.456 - 456.789, zmin_m, 4)
        self.assertAlmostEqual(-123.456, zmax_m, 4)

        zmin_m, zmax_m = zpositions_m[2]
        self.assertAlmostEqual(-123.456 - 456.789 - 456.123, zmin_m, 4)
        self.assertAlmostEqual(-123.456 - 456.789, zmax_m, 4)

    def test__eq__(self):
        s1 = HorizontalLayerSample(COPPER)
        s1.add_layer(ZINC, 123.456)
        s1.add_layer(GALLIUM, 456.789)
        self.assertEqual(s1, self.s1)

    def test__ne__(self):
        s1 = HorizontalLayerSample(ZINC)
        s1.add_layer(ZINC, 123.456)
        s1.add_layer(GALLIUM, 456.789)
        self.assertNotEqual(s1, self.s1)

        s1 = HorizontalLayerSample(COPPER)
        s1.add_layer(GALLIUM, 456.789)
        self.assertNotEqual(s1, self.s1)

        s1 = HorizontalLayerSample(COPPER)
        s1.add_layer(ZINC, 124.456)
        s1.add_layer(GALLIUM, 456.789)
        self.assertNotEqual(s1, self.s1)
    def test__ne__(self):
        s1 = HorizontalLayerSample(ZINC)
        s1.add_layer(ZINC, 123.456)
        s1.add_layer(GALLIUM, 456.789)
        self.assertNotEqual(s1, self.s1)

        s1 = HorizontalLayerSample(COPPER)
        s1.add_layer(GALLIUM, 456.789)
        self.assertNotEqual(s1, self.s1)

        s1 = HorizontalLayerSample(COPPER)
        s1.add_layer(ZINC, 124.456)
        s1.add_layer(GALLIUM, 456.789)
        self.assertNotEqual(s1, self.s1)