Exemple #1
0
 def test_makeInf(self, inffile, tmpfile):
     myheader = Header.parseInfHeader(filename=inffile)
     myheader.makeInf(outfile=tmpfile)
     with open(inffile, 'r') as file_inf:
         infdata = file_inf.read()
     with open(tmpfile, 'r') as file_tmp:
         tmpdata = file_tmp.read()
     np.testing.assert_string_equal(tmpdata, infdata)
Exemple #2
0
 def test_parseInfHeader(self, inffile):
     header = Header.parseInfHeader(filename=inffile)
     assert header.nbits == 32
     assert header.source_name == "Mystery_PSR"
     assert header.telescope_id == 6
     assert header.machine_id == 9
     assert header.src_raj == 164338.1
     assert header.src_dej == -122458.7
     assert header.nsamples == 66250
     assert header.nchans == 1
Exemple #3
0
    def readDat(cls, filename, inf=None):
        """Read a presto format ``.dat`` file.

        Parameters
        ----------
        filename : str
            the name of the ``.dat`` file to read
        inf : str, optional
            the name of the corresponding ``.inf`` file, by default None

        Returns
        -------
        :class:`~sigpyproc.TimeSeries.TimeSeries`
            a new TimeSeries object

        Raises
        ------
        IOError
            If no ``.inf`` file found in the same directory of ``.dat`` file.

        Notes
        -----
        If inf=None, then the associated .inf file must be in the same directory.
        """
        datfile = os.path.realpath(filename)
        basename, ext = os.path.splitext(datfile)
        if inf is None:
            inf = f"{basename}.inf"
        if not os.path.isfile(inf):
            raise IOError("No corresponding .inf file found")
        header = Header.parseInfHeader(inf)
        f = File(filename, "r", nbits=32)
        data = np.fromfile(f, dtype=np.float32)
        header["basename"] = basename
        header["inf"]      = inf
        header["filename"] = filename
        header["nsamples"] = data.size
        return cls(data, header)
Exemple #4
0
    def readFFT(cls, filename, inf=None):
        """Read a presto format ``.fft`` file.

        Parameters
        ----------
        filename : str
            the name of the ``.fft`` file to read
        inf : str, optional
            the name of the corresponding ``.inf`` file, by default None

        Returns
        -------
        :class:`~sigpyproc.FourierSeries.FourierSeries`
            an array containing the whole file contents

        Raises
        ------
        IOError
            If no ``.inf`` file found in the same directory of ``.fft`` file.

        Notes
        -----
        If inf=None, then the associated .inf file must be in the same directory.
        """
        fftfile = os.path.realpath(filename)
        basename, ext = os.path.splitext(fftfile)
        if inf is None:
            inf = f"{basename}.inf"
        if not os.path.isfile(inf):
            raise IOError("No corresponding inf file found")
        header = 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 cls(data, header)