예제 #1
0
파일: test_nfft.py 프로젝트: ekeberg/pynfft
 def test_nfft_direct(self):
     a = numpy.random.random(self._size)
     coordinates = -0.5 + numpy.random.random(100)
     ft_nfft = nfft.nfft(a, 1., coordinates, use_direct=False)
     ft_nfft_direct = nfft.nfft(a, 1., coordinates, use_direct=True)
     numpy.testing.assert_almost_equal(ft_nfft,
                                       ft_nfft_direct,
                                       decimal=self._decimals)
예제 #2
0
파일: test_nfft.py 프로젝트: ekeberg/pynfft
 def test_nfft_1d(self):
     a = numpy.random.random(self._size)
     ft_nfft = nfft.nfft(a, 1., self._coord_1d)
     ft_fftw = numpy.fft.fftshift(numpy.fft.fft(numpy.fft.fftshift(a)))
     numpy.testing.assert_almost_equal(ft_nfft,
                                       ft_fftw,
                                       decimal=self._decimals)
def serie_single_processor(serie):
    id_datalist = list(
        filter((lambda dat: dat['designator'] == 'Id'), serie['data']))
    t_datalist = list(
        filter((lambda dat: dat['designator'] == 'T(s)'), serie['data']))
    id_arr = np.array(id_datalist[0]['data'][0])
    t_arr = np.array(t_datalist[0]['data'][0])
    if (len(id_arr) % 2) != 0:
        sys.stdout.writelines(strip_non_ascii(serie['title']) + '\n\n')
        sys.stdout.flush()
    fs = 1 / np.average(np.diff(t_arr))

    N = len(t_arr)
    if N % 2 == 0:
        dft_two_sided = np.real(nfft.nfft(np.arange(-0.5, 0.5, 1 / N), id_arr))
    else:
        dft_two_sided = np.real(nfft.ndft(t_arr, id_arr))
    dft_one_sided = 2 * dft_two_sided[1:math.ceil(N / 2)]
    psd = (1 / (2 * math.pi * N)) * np.square(dft_one_sided)
    f = np.arange(0, math.pi * fs, (2 * math.pi * fs) / N)[1:]
    logpsd = 10 * np.log10(psd)
    plt.semilogx(f, logpsd)
    plt.title("Power Spectral Density of: " + serie['title'])
    plt.autoscale('both', tight=True)
    plt.ylabel('PSD(A^2/Hz)')
    plt.xlabel('f(Hz)')

    outputdir = PureWindowsPath(sys.argv[2])
    filename = Path(outputdir /
                    PureWindowsPath("psd\\" + serie['title'] + ".png"))
    plt.savefig(filename, dpi=600)
    plt.close()
예제 #4
0
def calculate_diffraction(scattering_factor_density, density_pixel_size, rotation,
                          image_shape, wavelength, detector_distance, pixel_size):
    base_coordinates = ewald_coordinates(image_shape, wavelength, detector_distance, pixel_size)
    rotated_coordinates = _rotations.rotate_array(rotation, base_coordinates)
    largest_distance_in_fourier_space = 1./(2.*density_pixel_size)
    scaled_coordinates = rotated_coordinates * 0.5 / largest_distance_in_fourier_space
    diffraction = _nfft.nfft(scattering_factor_density, scaled_coordinates)
    return diffraction.reshape(image_shape)
예제 #5
0
def apply_nfft(t, x):
    ids = np.logical_not(np.isnan(x))
    if np.sum(ids)%2 != 0:
        ids[np.where(ids)[-1]] = False
    try:
        f = nfft(t[ids], x[ids])
    except:
        f = np.fft.rfft(x[ids], norm='ortho')
    return(t[ids], x[ids], f)
예제 #6
0
def calculate_diffraction(scattering_factor_density, density_pixel_size,
                          rotation, image_shape, wavelength, detector_distance,
                          pixel_size):
    import nfft as _nfft
    base_coordinates = ewald_coordinates(image_shape, wavelength,
                                         detector_distance, pixel_size)
    rotated_coordinates = _rotmodule.rotate_array(rotation, base_coordinates)
    diffraction = _nfft.nfft(scattering_factor_density, density_pixel_size,
                             rotated_coordinates)
    return diffraction.reshape(image_shape)
예제 #7
0
def math_ops(time_array_epoch, temp_array, humi_array):
    ret_dict = {}
    # Derivative (C/minute)
    ret_dict['derivative_temp'] = 3600 * np.gradient(
        temp_array, time_array_epoch)  #degs/hour
    # Fourier (Only on the last p=2^k samples)
    k = int(np.log(len(time_array_epoch)) / np.log(2))
    t_window = time_array_epoch[-2**k:] - time_array_epoch[-2**k]
    t_hat = nfft.nfft(temp_array[-2**k:], t_window)
    #freqHz = (0:1:length(X_mag)-1)*Fs/N; Fs=sampling rate, N = sample size
    # freq = np.arange(2**k)*(time_array_epoch[-1] - time_array_epoch[-2**k])/(60*60*24)
    ret_dict['fourier'] = t_hat.real
    return ret_dict
예제 #8
0
def compute_nfft(sample_instants, sample_values):
    '''
    Following the procedure from the linked stackoverflow, compute a 
    nonuniform fft.
    '''
    N = len(sample_instants)
    T = sample_instants[-1] - sample_instants[0]
    x = numpy.linspace(0.0, 1.0 / (2.0 * T), N // 2)
    y = nfft.nfft(sample_instants, sample_values)
    y = 2.0 / N * numpy.abs(y[0:N // 2])
    #plt.plot(x, y)
    #plt.show()
    return (x, y)
예제 #9
0
파일: test_nfft.py 프로젝트: ekeberg/pynfft
 def test_nfft_2d(self):
     a = numpy.random.random((self._size, ) * 2)
     ft_nfft = nfft.nfft(a, 1., [[
         self._coord_1d[self._2d_coord[0][0]],
         self._coord_1d[self._2d_coord[0][1]]
     ],
                                 [
                                     self._coord_1d[self._2d_coord[1][0]],
                                     self._coord_1d[self._2d_coord[1][1]]
                                 ]])
     ft_fftw = numpy.fft.fftshift(numpy.fft.fft2(numpy.fft.fftshift(a)))
     numpy.testing.assert_almost_equal(
         ft_nfft, ft_fftw[(self._2d_coord[0][0], self._2d_coord[1][0]),
                          (self._2d_coord[0][1], self._2d_coord[1][1])])
예제 #10
0
    def get_slice_and_rot(self, rot=None, output_type="complex"):
        """Calculate the slice of the specified rot or if no rot is given
        use a random rotation. Both the slice and the rotation in returned.
        The output type can be either "complex" or "intensity". "Complex"
        returns the wave field and "intensity" returns the absolute square
        of the wave field."""
        if rot is None:
            rot = rotations.random_quaternion()
        coordinates = self._rotated_coordinates(rot)

        pattern_flat = _nfft.nfft(self._real_volume, coordinates)

        pattern = pattern_flat.reshape((self._image_side, )*2)
        if output_type == "complex":
            return pattern, rot
        elif output_type == "intensity":
            return abs(pattern**2), rot
예제 #11
0
    def get_slice_and_rot(self, rot=None, output_type="complex"):
        """Calculate the slice of the specified rot or if no rot is given
        use a random rotation. Both the slice and the rotation in returned.
        The output type can be either "complex" or "intensity". "Complex"
        returns the wave field and "intensity" returns the absolute square
        of the wave field."""
        if rot is None:
            rot = rotmodule.random_quaternion()
        coordinates = self._rotated_coordinates(rot)

        pattern_flat = _nfft.nfft(self._real_volume,
                                  self._real_pixel_size,
                                  coordinates)

        pattern = pattern_flat.reshape(self._image_shape)
        if output_type == "complex":
            return pattern, rot
        elif output_type == "intensity":
            return abs(pattern**2), rot
예제 #12
0
파일: test_nfft.py 프로젝트: FXIhub/condor
 def test_nfft_2d(self):
     a = numpy.random.random((self._size, )*2)
     ft_nfft = nfft.nfft(a, [[self._coord_1d[self._2d_coord[0][0]], self._coord_1d[self._2d_coord[0][1]]],
                             [self._coord_1d[self._2d_coord[1][0]], self._coord_1d[self._2d_coord[1][1]]]])
     ft_fftw = numpy.fft.fftshift(numpy.fft.fft2(numpy.fft.fftshift(a)))
     numpy.testing.assert_almost_equal(ft_nfft, ft_fftw[(self._2d_coord[0][0], self._2d_coord[1][0]), (self._2d_coord[0][1], self._2d_coord[1][1])])
예제 #13
0
파일: test_nfft.py 프로젝트: FXIhub/condor
 def test_nfft_1d(self):
     a = numpy.random.random(self._size)
     ft_nfft = nfft.nfft(a, self._coord_1d)
     ft_fftw = numpy.fft.fftshift(numpy.fft.fft(numpy.fft.fftshift(a)))
     numpy.testing.assert_almost_equal(ft_nfft, ft_fftw, decimal=self._decimals)
예제 #14
0
파일: test_nfft.py 프로젝트: FXIhub/condor
 def test_nfft_direct(self):
     a = numpy.random.random(self._size)
     coordinates = -0.5+numpy.random.random(100)
     ft_nfft = nfft.nfft(a, coordinates, use_direct=False)
     ft_nfft_direct = nfft.nfft(a, coordinates, use_direct=True)
     numpy.testing.assert_almost_equal(ft_nfft, ft_nfft_direct, decimal=self._decimals)