def readSpec(cls, filename): """Read a sigpyproc format ``.spec`` file. Parameters ---------- filename : str the name of the ``.spec`` file to read Returns ------- :class:`~sigpyproc.FourierSeries.FourierSeries` an array containing the whole file contents Notes ----- 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 = Header.parseSigprocHeader(filename) hdrlen = header["hdrlen"] f = File(filename, "r", nbits=32) f.seek(hdrlen) data = np.fromfile(f, dtype="complex32") return cls(data, header)
def test_parseSigprocHeader(self, timfile): header = Header.parseSigprocHeader(filename=timfile) assert header.nbits == 32 assert header.source_name == "Mystery_PSR" assert header.telescope_id == 6 assert header.machine_id == 4 assert header.ra == "16:43:38.1000" assert header.dec == "-12:24:58.7000" assert header.nsamples == 66250 assert header.nchans == 1
def __init__(self, filename): self.filename = filename self.header = Header.parseSigprocHeader(self.filename) self._file = File(filename, "r", self.header.nbits) self.itemsize = np.dtype(self.header.dtype).itemsize if self.header.nbits in {1, 2, 4}: self.bitfact = 8 // self.header.nbits else: self.bitfact = 1 self.sampsize = self.header.nchans * self.itemsize // self.bitfact super().__init__()
def readTim(cls, filename): """Read a sigproc format ``.tim`` file. Parameters ---------- filename : str the name of the ``.tim`` file to read Returns ------- :class:`~sigpyproc.TimeSeries.TimeSeries` a new TimeSeries object """ header = Header.parseSigprocHeader(filename) nbits = header["nbits"] hdrlen = header["hdrlen"] f = File(filename, "r", nbits=nbits) f.seek(hdrlen) data = np.fromfile(f, dtype=header["dtype"]).astype(np.float32, copy=False) return cls(data, header)
def test_getDMdelays(self, filfile): header = Header.parseSigprocHeader(filename=filfile) delays_time = header.getDMdelays(dm=100, in_samples=False) delays_samp = header.getDMdelays(dm=100, in_samples=True) np.testing.assert_equal(delays_samp.mean(), 193.3125) np.testing.assert_allclose(delays_time.mean(), 0.013913)
def test_prepOutfile(self, filfile, tmpfile): myheader = Header.parseSigprocHeader(filename=filfile) outfile = myheader.prepOutfile(tmpfile) out_header = Header.parseSigprocHeader(filename=outfile.name) np.testing.assert_equal(out_header.SPPHeader(), myheader.SPPHeader())