예제 #1
0
    def test_positive_intensity(self):
        """ Test that potential_map raises an error if diffraction intensity is not positive """
        aR1, aR2, aR3 = self.crystal.lattice_vectors
        extent = np.arange(0, 5, 0.1)
        with suppress_warnings():
            plane = plane_mesh(aR3, aR1 + aR2, x1=extent)

        self.I[0] = -1
        with self.assertRaises(ValueError):
            potmap = potential_map(self.q, self.I, self.crystal, plane)
예제 #2
0
    def test_trivial(self):
        """ Test that potential_map calculated from zero intensity is zero everywhere """
        aR1, aR2, aR3 = self.crystal.lattice_vectors
        extent = np.arange(0, 10, 0.1)

        with suppress_warnings():
            plane = plane_mesh(aR3, aR1 + aR2, x1=extent)

        potmap = potential_map(self.q, np.zeros_like(self.I), self.crystal,
                               plane)

        self.assertTrue(np.allclose(potmap, 0))
예제 #3
0
    def test_on_tiff(self):
        """ Test diffread() on tiff files """
        im = np.random.randint(0, 127, size=(512, 512))
        path = Path(".\\test_tif.tif")

        # Annoying low contrast warning
        with suppress_warnings():
            imsave(str(path), im)

        from_skued = diffread(path)
        self.assertTrue(np.allclose(im, from_skued))
        os.remove(path)
예제 #4
0
    def test_shape(self):
        """ Test that potential_map returns a map with the same shape as the mesh """
        aR1, aR2, aR3 = self.crystal.lattice_vectors
        extent = np.arange(0, 5, 0.1)

        with suppress_warnings():
            plane = plane_mesh(aR3, aR1 + aR2, x1=extent)

        potmap = potential_map(self.q, self.I, self.crystal, plane)

        xx, yy, zz = plane
        for arr in plane:
            self.assertTupleEqual(potmap.shape, arr.shape)
예제 #5
0
def test_potential_map_positive_intensity():
    """ Test that potential_map raises an error if diffraction intensity is not positive """
    crystal = Crystal.from_database("vo2-rutile")
    q = np.linspace(1, 5, 256)
    I = powdersim(crystal, q)

    aR1, aR2, aR3 = crystal.lattice_vectors
    extent = np.arange(0, 5, 0.1)
    with suppress_warnings():
        plane = plane_mesh(aR3, aR1 + aR2, x1=extent)

    I[0] = -1
    with pytest.raises(ValueError):
        potmap = potential_map(q, I, crystal, plane)
예제 #6
0
def test_potential_map_trivial():
    """ Test that potential_map calculated from zero intensity is zero everywhere """
    crystal = Crystal.from_database("vo2-rutile")
    q = np.linspace(1, 5, 256)
    I = powdersim(crystal, q)

    aR1, aR2, aR3 = crystal.lattice_vectors
    extent = np.arange(0, 10, 0.1)

    with suppress_warnings():
        plane = plane_mesh(aR3, aR1 + aR2, x1=extent)

    potmap = potential_map(q, np.zeros_like(I), crystal, plane)

    assert np.allclose(potmap, 0)
예제 #7
0
def test_potential_synthesis_positive_intensity():
    """ Test that potential_synthesis raises an error if diffraction intensity is not positive """
    crystal = Crystal.from_database("C")
    reflections = list(combinations_with_replacement(range(-3, 4), 3))
    intensities = [
        np.abs(structure_factor(crystal, *reflection))**2
        for reflection in reflections
    ]

    aR1, aR2, aR3 = crystal.lattice_vectors
    extent = np.arange(0, 5, 0.1)
    with suppress_warnings():
        plane = plane_mesh(aR3, aR1 + aR2, x1=extent)

    intensities[0] = intensities[0] * -1
    with pytest.raises(ValueError):
        potmap = potential_synthesis(reflections, intensities, crystal, plane)
예제 #8
0
def test_potential_map_shape():
    """ Test that potential_map returns a map with the same shape as the mesh """
    crystal = Crystal.from_database("vo2-rutile")
    q = np.linspace(1, 5, 256)
    I = powdersim(crystal, q)

    aR1, aR2, aR3 = crystal.lattice_vectors
    extent = np.arange(0, 5, 0.1)

    with suppress_warnings():
        plane = plane_mesh(aR3, aR1 + aR2, x1=extent)

    potmap = potential_map(q, I, crystal, plane)

    xx, yy, zz = plane
    for arr in plane:
        assert potmap.shape == arr.shape
예제 #9
0
def test_potential_synthesis_trivial():
    """ Test that potential_synthesis calculated from zero intensity is zero everywhere """
    crystal = Crystal.from_database("C")
    reflections = list(combinations_with_replacement(range(-3, 4), 3))
    intensities = [
        np.abs(structure_factor(crystal, *reflection))**2
        for reflection in reflections
    ]

    aR1, aR2, aR3 = crystal.lattice_vectors
    extent = np.arange(0, 10, 0.1)

    with suppress_warnings():
        plane = plane_mesh(aR3, aR1 + aR2, x1=extent)

    potmap = potential_synthesis(reflections, np.zeros_like(intensities),
                                 crystal, plane)

    assert np.allclose(potmap, 0)
예제 #10
0
def test_potential_synthesis_shape():
    """ Test that potential_synthesis returns a map with the same shape as the mesh """
    crystal = Crystal.from_database("C")
    reflections = list(combinations_with_replacement(range(-3, 4), 3))
    intensities = [
        np.abs(structure_factor(crystal, *reflection))**2
        for reflection in reflections
    ]

    aR1, aR2, aR3 = crystal.lattice_vectors
    extent = np.arange(0, 5, 0.1)

    with suppress_warnings():
        plane = plane_mesh(aR3, aR1 + aR2, x1=extent)

    potmap = potential_synthesis(reflections, intensities, crystal, plane)

    xx, yy, zz = plane
    for arr in plane:
        assert potmap.shape == arr.shape