def test_freq2(shape): x = [np.linspace(0, 1, s) if s > 1 else np.array([0]) for s in shape] y = to_recip(from_recip(x)) z = from_recip(to_recip(x)) for i in range(len(shape)): assert abs(x[i] - y[i] + y[i].min()).max() < 1e-6 assert abs(x[i] - z[i] + z[i].min()).max() < 1e-6
def FT(self, y, out=None): """ Parameters ---------- y : `numpy.ndarray`, (nx, ny, nz, 3) or list of arrays of shape [(nx,), (ny,), (nz,)] Mesh of Fourier coordinates at which to evaluate the probe density out : `numpy.ndarray`, (nx, ny, nz), optional If provided then computation is performed inplace Returns ------- out : `numpy.ndarray`, (nx, ny, nz) An array equal to `FourierTransform(probe)(y)` """ if hasattr(y, "shape"): y_start = y[(0, ) * (y.ndim - 1)] y_end = y[(-1, ) * (y.ndim - 1)] y = [ linspace(y_start[i], y_end[i], y.shape[i], endpoint=True) for i in range(3) ] x = from_recip(y) ft = get_DFT(x, y)[0] tmp = ft(self(x, out=out)) if out is None: out = tmp else: out[...] = tmp return out
def __init__(self, accelerating_voltage, detector, reciprocal_mesh=False, debye_waller_factors=None): self.wavelength = get_electron_wavelength(accelerating_voltage) # Always store a 'real' mesh self.detector = detector if not reciprocal_mesh else from_recip( detector) if debye_waller_factors: raise NotImplementedError('Not implemented for this simulator') self.debye_waller_factors = debye_waller_factors or {}
def test_freq(shape, dX, rX, dY, rY): x, y = get_recip_points(len(shape), shape, dX, rX, dY, rY) X, Y = from_recip(y), to_recip(x) assert len(x) == len(shape) assert len(y) == len(shape) assert len(X) == len(shape) assert len(Y) == len(shape) for i in range(len(shape)): assert y[i].size == x[i].size if shape[i] is None: if dX[i] is not None: assert abs(x[i].item(1) - x[i].item(0)) <= dX[i] + 1e-8 if rY[i] is not None: assert y[i].ptp() >= rY[i] - 1e-8 if rX[i] is not None: assert x[i].ptp() >= rX[i] - 1e-8 if dY[i] is not None: assert abs(y[i].item(1) - y[i].item(0)) <= dY[i] + 1e-8 np.testing.assert_allclose(x[i], X[i], 1e-5) np.testing.assert_allclose(y[i], Y[i], 1e-5)
def FT(self, y, out=None): """Returns the Fourier transform of func on the mesh `y`. Again, if `out` is provided then computation is `inplace`. If `y` is a list of arrays then it is converted into a mesh first. If this function is not overridden then an approximation is made using `func` and the `fft`. Parameters ---------- y : numpy.ndarray, (nx, ny, nz, 3) or list of arrays of shape [(nx,), (ny,), (nz,)] Mesh of Fourier coordinates at which to evaluate the probe density. out : numpy.ndarray, (nx, ny, nz), optional If provided then computation is performed inplace. Returns ------- out : numpy.ndarray, (nx, ny, nz) An array equal to `FourierTransform(probe)(y)`. """ if hasattr(y, "shape"): y_start = y[(0, ) * (y.ndim - 1)] y_end = y[(-1, ) * (y.ndim - 1)] y = [ linspace(y_start[i], y_end[i], y.shape[i], endpoint=True) for i in range(3) ] x = from_recip(y) ft = get_DFT(x, y)[0] tmp = ft(self(x, out=out)) if out is None: out = tmp else: out[...] = tmp return out
def __init__(self, accelerating_voltage, detector, reciprocal_mesh=False): self.wavelength = get_electron_wavelength(accelerating_voltage) # Always store a 'real' mesh self.detector = detector if not reciprocal_mesh else from_recip(detector)