def read_data(self, start=None, end=None):
"""read data from file and store it locally"""
nframe = self._find_nframe_from_file()
seek_to_data(self.file_object)
read_start = 0
end_read = nframe * self.nifs * self.nchans
if start is not None:
if start < 0:
read_start = (nframe + start) * self.nifs * self.nchans
elif start >= 0:
read_start = start * self.nifs * self.nchans
if end is not None:
if end < 0:
end_read = (nframe + end) * self.nifs * self.nchans
elif end >= 0:
end_read = end * self.nifs * self.nchans
self.file_object.seek(read_start, os.SEEK_CUR)
nbytes_to_read = end_read - read_start
data = np.fromfile(self.file_object, count=nbytes_to_read, dtype=self.dtype)
nframe = data.size // self.nifs // self.nchans
data = data.reshape((nframe, self.nifs, self.nchans))
if self.nbits < 8:
data = unpack(data, self.nbits)
self.data = data
return self.data
评论列表
文章目录