def randn(shape): """""" values = np.random.randn(*shape) coords = [] dims = [] for ix in range(len(shape)): dims.append(str(ix)) coords.append(np.arange(shape[ix])) return nddata.nddata_core(values, dims, coords)
def ones(shape, dtype=None): """""" values = np.ones(shape, dtype=dtype) coords = [] dims = [] for ix in range(len(shape)): dims.append(str(ix)) coords.append(np.arange(shape[ix])) return nddata.nddata_core(values, dims, coords)
dt = data.coords[index][1] - data.coords[index][0] n_pts = zero_fill_factor * len(data.coords[index]) f = (1. / (n_pts * dt)) * np.r_[0:n_pts] if shift == True: f -= (1. / (2 * dt)) # if convert_to_ppm: # nmr_frequency = data.attrs['nmr_frequency'] # f /= (nmr_frequency / 1.e6) data.values = np.fft.fft(data.values, n=n_pts, axis=index) if shift: data.values = np.fft.fftshift(data.values, axes=index) data.coords[index] = f return data if __name__ == '__main__': x = np.r_[0:10] y = np.r_[0:20] z = np.r_[0:15] data = nddata.nddata_core( np.array(range(len(x) * len(y) * len(z))).reshape( len(x), len(y), len(z)), ['x', 'y', 'z'], [x, y, z]) out = fourier_transform(data, {'dim': 'x'}) print(out)
index = data.dims.index(dim) dt = data.coords[index][1] - data.coords[index][0] n_pts = zero_fill_factor * len(data.coords[index]) f = (1.0 / (n_pts * dt)) * np.r_[0:n_pts] if shift == True: f -= 1.0 / (2 * dt) data.values = np.fft.fft(data.values, n=n_pts, axis=index) if shift: data.values = np.fft.fftshift(data.values, axes=index) data.coords[index] = f return data if __name__ == "__main__": x = np.r_[0:10] y = np.r_[0:20] z = np.r_[0:15] data = nddata.nddata_core( np.array(range(len(x) * len(y) * len(z))).reshape( len(x), len(y), len(z)), ["x", "y", "z"], [x, y, z], ) out = fourier_transform(data, {"dim": "x"}) print(out)