def get_virtual_electron_diffraction(self, calibration, shape, sigma): """Obtain a virtual electron diffraction signal that consists of one virtual diffraction pattern for each segment. The virtual diffraction pattern is composed of Gaussians centered at each vector position. If given, the integrated intensities of each vector will be taken into account by multiplication with the Gaussians. Parameters ---------- calibration : float Reciprocal space calibration in inverse Angstrom per pixel. shape : tuple Shape of the signal, (shape_x, shape_y) in pixels, where shape_x and shape_y are integers. sigma : float The standard deviation of the Gaussians in inverse Angstrom per pixel. 'calibration' is a decent starting value. Returns ------- virtual_ed : ElectronDiffraction2D Virtual electron diffraction signal consisting of one virtual diffraction pattern for each segment. """ vectors = self.vectors_of_segments.data segments = self.segments.data num_segments = np.shape(segments)[0] if self.intensities is None: raise ValueError("The VDFSegment does not have the attribute " "intensities, required for this method.") else: intensities = self.intensities # TODO: Refactor this to use the diffsims simulation to plot functionality size_x, size_y = shape[0], shape[1] cx, cy = -size_x / 2 * calibration, -size_y / 2 * calibration x, y = np.indices((size_x, size_y)) x, y = x * calibration + cx, y * calibration + cy virtual_ed = np.zeros((size_x, size_y, num_segments)) for i in range(num_segments): # Allow plotting for segments that are only associated with # one vector. if np.shape(np.shape(vectors[i]))[0] <= 1: virtual_ed[..., i] = get_gaussian2d( intensities[i], vectors[i][..., 0], vectors[i][..., 1], x=x, y=y, sigma=sigma, ) # Allow plotting for segments associated with several vectors. else: virtual_ed[..., i] = sum( list( map( lambda a, xo, yo: get_gaussian2d( a, xo, yo, x=x, y=y, sigma=sigma), intensities[i], vectors[i][..., 0], vectors[i][..., 1], ))) virtual_ed = ElectronDiffraction2D(virtual_ed.T) return virtual_ed
def test_get_gaussian2d(a, xo, yo, x, y, sigma, gauss_shape_expt): gauss = get_gaussian2d(a, xo, yo, x, y, sigma) assert isinstance(gauss, np.ndarray) assert gauss.dtype == float np.testing.assert_equal(gauss.shape, gauss_shape_expt)