def test_toFFTFile(self, fourier_data, tim_header): myFS = FourierSeries(fourier_data, Header(tim_header)) fftfile, inffile = myFS.toFFTFile(basename="temp_test") assert os.path.isfile(fftfile) assert os.path.isfile(inffile) os.remove(fftfile) os.remove(inffile)
def test_readFFT(self, fourier_data, tim_header): myFS = FourierSeries(fourier_data, Header(tim_header)) fftfile, inffile = myFS.toFFTFile(basename="temp_test") mynewFS = FourierSeries.readFFT(filename=fftfile) assert mynewFS.header.nbits == 32 assert mynewFS.header.source_name == "test" np.testing.assert_allclose(np.mean(mynewFS), 135.61371, atol=0.01) os.remove(fftfile) os.remove(inffile)
def readFFT(filename, inf=None): """Read a presto .fft format file. :param filename: the name of the file to read :type filename: :func:`str` :params inf: the name of the corresponding .inf file (def=None) :type inf: :func:`str` :return: an array containing the whole file contents :rtype: :class:`~sigpyproc.FourierSeries.FourierSeries` .. note:: If inf=None, the function will look for a corresponding file with the same basename which has the .inf file extension. """ basename = os.path.splitext(filename)[0] if inf is None: inf = "%s.inf" % (basename) if not os.path.isfile(inf): raise IOError, "No corresponding inf file found" header = parseInfHeader(inf) f = File(filename, "r", nbits=32) data = np.fromfile(f, dtype="float32") header["basename"] = basename header["inf"] = inf header["filename"] = filename return FourierSeries(data, header)
def rFFT(self): """Perform 1-D real to complex forward FFT. :return: output of FFTW3 :rtype: :class:`~sigpyproc.FourierSeries.FourierSeries` """ if self.size % 2 == 0: fftsize = self.size else: fftsize = self.size - 1 fft_ar = np.empty(fftsize + 2, dtype="float32") lib.rfft(as_c(self), as_c(fft_ar), fftsize) return FourierSeries(fft_ar, self.header.newHeader())
def readSpec(filename): """Read a sigpyproc format spec file. :param filename: the name of the file to read :type filename: :func:`str` :return: an array containing the whole file contents :rtype: :class:`~sigpyproc.FourierSeries.FourierSeries` .. note:: This is not setup to handle ``.spec`` files such as are created by Sigprocs seek module. To do this would require a new header parser for that file format. """ header = parseSigprocHeader(filename) hdrlen = header["hdrlen"] f = File(filename, "r", nbits=32) f.seek(hdrlen) data = np.fromfile(f, dtype="complex32") return FourierSeries(data, header)
def test_fourierSeries(self, fourier_data, tim_header): myFS = FourierSeries(fourier_data, Header(tim_header)) assert myFS.header.nbits == 32 assert myFS.header.source_name == "test" assert myFS.shape == (10002, ) np.testing.assert_allclose(np.mean(myFS), 135.61371, atol=0.01)
def test_toFile(self, fourier_data, tim_header): myFS = FourierSeries(fourier_data, Header(tim_header)) outfile = myFS.toFile() assert os.path.isfile(outfile) os.remove(outfile)
def test_iFFT(self, fourier_data, tim_header, tim_data): myFS = FourierSeries(fourier_data, Header(tim_header)) myTim = myFS.iFFT() np.testing.assert_allclose(myTim, tim_data, atol=0.01)