Esempio n. 1
0
 def test_take_slices(self):
     """Test take_slices with 90 & 270 degrees y & z rotations."""
     # Slices
     orientations = np.vstack(
         [cst.quaty90, cst.quaty270, cst.quatz90, cst.quatz270])
     slices = ps.take_n_slices(self.volume, self.voxel_length,
                               self.pixel_momentum, orientations)
     assert xp.allclose(slices[0, ::-1, :, :].swapaxes(0, 2), self.volume)
     assert xp.allclose(slices[1, :, :, ::-1].swapaxes(0, 2), self.volume)
     assert xp.allclose(slices[2, :, ::-1, :].swapaxes(0, 1), self.volume)
     assert xp.allclose(slices[3, ::-1, :, :].swapaxes(0, 1), self.volume)
Esempio n. 2
0
def test_distance_change():
    """Test distance property change."""
    det = ps.SimpleSquareDetector(
        N_pixel=1024, det_size=0.1, det_distance=0.2)
    distance_1 = det.distance
    pixel_position_1 = det.pixel_position.copy()
    det.distance *= 2
    assert np.isclose(det.distance, distance_1*2)
    assert xp.allclose(det.pixel_position[..., 0],
                       pixel_position_1[..., 0])  # X unchanged
    assert xp.allclose(det.pixel_position[..., 1],
                       pixel_position_1[..., 1])  # Y unchanged
    assert xp.allclose(det.pixel_position[..., 2],
                       pixel_position_1[..., 2]*2)  # Z doubled
Esempio n. 3
0
def test_get_weight_and_index_center_even():
    """Test get_weight_and_index centering for even-sized meshes."""
    pixel_position = xp.zeros((1,3), dtype=float)
    voxel_length = 1.
    voxel_num_1d = 4
    index, weight = mapping.get_weight_and_index(
        pixel_position, voxel_length, voxel_num_1d)
    assert xp.all(index[0][0] == xp.array([1, 1, 1]))
    assert xp.allclose(weight[0], 0.125)
Esempio n. 4
0
 def distance(self, value):
     if not xp.allclose(self.orientation, xp.array([0, 0, 1])):
         raise NotImplementedError(
             "Detector distance setter only implemented for "
             "detector orientations along the z axis.")
     self.pixel_position[..., 2] *= value / self._distance
     self._distance = value
     if self._has_beam:  # Update pixel_position_reciprocal & co
         self.initialize_pixels_with_beam(beam=self._beam)
Esempio n. 5
0
def test_get_weight_and_index_off_center():
    """Test get_weight_and_index for off-centered points."""
    pixel_position = xp.array([[0.1, 0.2, 0.3]])
    voxel_length = 2.
    voxel_num_1d = 5
    index, weight = mapping.get_weight_and_index(
        pixel_position, voxel_length, voxel_num_1d)
    assert xp.all(index[0][0] == xp.array([2, 2, 2]))
    assert xp.isclose(weight.sum(), 1.)
    assert xp.allclose(xp.dot(weight[0], index[0]),
                       xp.array([ 2.05, 2.1 , 2.15]))
Esempio n. 6
0
 def test_take_slice_default_orientation(self):
     """Test take_slice with the default orientation."""
     orientation = cst.quat1
     slice_ = ps.take_slice(self.volume, self.voxel_length,
                            self.pixel_momentum, orientation)
     assert xp.allclose(slice_, self.volume)
Esempio n. 7
0
 def test_pattern_2x_k_symetry(self):
     """Test k symmetry of volume with 2 atoms along x."""
     assert xp.allclose(self.volume_2x, self.volume_2x[:, ::-1, :])
Esempio n. 8
0
 def test_pixel_position_x_sep(self):
     x_diff = self.det.pixel_position[:, 1:, :, 0] \
         - self.det.pixel_position[:, :-1, :, 0]
     assert xp.allclose(x_diff, self.sep)
Esempio n. 9
0
 def test_pattern_1_hk_symetry(self):
     """Test h-k symmetry of volume with 1 atom."""
     assert xp.allclose(self.volume_1, xp.swapaxes(self.volume_1, 0, 1))
Esempio n. 10
0
 def test_pattern_1_l_symetry(self):
     """Test l symmetry of volume with 1 atom."""
     assert xp.allclose(self.volume_1, self.volume_1[:, :, ::-1])
Esempio n. 11
0
 def test_pattern_1_vs_2z_particles(self):
     """Test diffraction equivalence of 1-2 atoms along z axis."""
     assert xp.allclose(
         (self.volume_2z - 4*self.volume_1)[:, :, self.mesh_length//2], 0.)
Esempio n. 12
0
 def test_pattern_2y_lh_symetry(self):
     """Test l-h symmetry of volume with 2 atoms along y."""
     assert xp.allclose(self.volume_2y, xp.swapaxes(self.volume_2y, 2, 0))
Esempio n. 13
0
 def test_pattern_2x_kl_symetry(self):
     """Test k-l symmetry of volume with 2 atoms along x."""
     assert xp.allclose(self.volume_2x, xp.swapaxes(self.volume_2x, 1, 2))
Esempio n. 14
0
 def test_pattern_2z_hk_symetry(self):
     """Test h-k symmetry of volume with 2 atoms along z."""
     assert xp.allclose(self.volume_2z, xp.swapaxes(self.volume_2z, 0, 1))
Esempio n. 15
0
 def test_pixel_position_y_sep(self):
     y_diff = self.det.pixel_position[:, :, 1:, 1] \
         - self.det.pixel_position[:, :, :-1, 1]
     assert xp.allclose(y_diff, self.sep)
Esempio n. 16
0
 def test_take_slice_z_orientation(self):
     """Test take_slice with 180 degrees z rotation."""
     orientation = cst.quatz
     slice_ = ps.take_slice(self.volume, self.voxel_length,
                            self.pixel_momentum, orientation)
     assert xp.allclose(slice_[::-1, ::-1, :], self.volume)
Esempio n. 17
0
 def test_take_slice_x270_orientation(self):
     """Test take_slice with 270 degrees x rotation."""
     orientation = cst.quatx270
     slice_ = ps.take_slice(self.volume, self.voxel_length,
                            self.pixel_momentum, orientation)
     assert xp.allclose(slice_[:, ::-1, :].swapaxes(1, 2), self.volume)
Esempio n. 18
0
 def test_pattern_1_kl_symetry(self):
     """Test k-l symmetry of volume with 1 atom."""
     assert xp.allclose(self.volume_1, xp.swapaxes(self.volume_1, 1, 2))
Esempio n. 19
0
 def test_pattern_1_lh_symetry(self):
     """Test l-h symmetry of volume with 1 atom."""
     assert xp.allclose(self.volume_1, xp.swapaxes(self.volume_1, 2, 0))
Esempio n. 20
0
 def test_pixel_position_z(self):
     assert xp.allclose(self.det.pixel_position[..., 2], self.distance)