Skip to content
This repository has been archived by the owner on Apr 16, 2022. It is now read-only.

Commit

Permalink
Py3: ensure computed f.seek indexes are integers
Browse files Browse the repository at this point in the history
  • Loading branch information
telegraphic committed Jun 5, 2018
1 parent 0c3c042 commit 9a9fdff
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions blimpy/file_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,20 +587,20 @@ def read_data(self, f_start=None, f_stop=None,t_start=None, t_stop=None):

# Load binary data
f = open(self.filename, 'rb')
f.seek(self.idx_data)
f.seek(int(self.idx_data))

# now check to see how many integrations requested
n_ints = self.t_stop - self.t_start

# Seek to first integration
f.seek(self.t_start * self._n_bytes * n_ifs * n_chans, 1)
f.seek(int(self.t_start * self._n_bytes * n_ifs * n_chans), 1)

#Loading data
self.data = np.zeros((n_ints, n_ifs, n_chans_selected), dtype=self._d_type)

for ii in range(n_ints):
for jj in range(n_ifs):
f.seek(self._n_bytes * self.chan_start_idx, 1) # 1 = from current location
f.seek(int(self._n_bytes * self.chan_start_idx), 1) # 1 = from current location
dd = np.fromfile(f, count=n_chans_selected, dtype=self._d_type)

# Reverse array if frequency axis is flipped
Expand All @@ -609,7 +609,7 @@ def read_data(self, f_start=None, f_stop=None,t_start=None, t_stop=None):

self.data[ii, jj] = dd

f.seek(self._n_bytes * (n_chans - self.chan_stop_idx), 1) # Seek to start of next block
f.seek(int(self._n_bytes * (n_chans - self.chan_stop_idx)), 1) # Seek to start of next block

def _find_blob_start(self):
"""Find first blob from selection.
Expand Down Expand Up @@ -655,7 +655,7 @@ def read_blob(self,blob_dim,n_blob=0):

#Load binary data
with open(self.filename, 'rb') as f:
f.seek(self.idx_data + self._n_bytes * (blob_start + n_blob*blob_flat_size))
f.seek(int(self.idx_data + self._n_bytes * (blob_start + n_blob*blob_flat_size)))
dd = np.fromfile(f, count=updated_blob_flat_size, dtype=self._d_type)

if dd.shape[0] == updated_blob_flat_size:
Expand All @@ -669,7 +669,7 @@ def read_blob(self,blob_dim,n_blob=0):

#Load binary data
with open(self.filename, 'rb') as f:
f.seek(self.idx_data + self._n_bytes * (blob_start + n_blob*blob_dim[self.time_axis]*self.n_channels_in_file + blobt*self.n_channels_in_file))
f.seek(int(self.idx_data + self._n_bytes * (blob_start + n_blob*blob_dim[self.time_axis]*self.n_channels_in_file + blobt*self.n_channels_in_file)))
dd = np.fromfile(f, count=blob_dim[self.freq_axis], dtype=self._d_type)

blob[blobt] = dd
Expand All @@ -686,7 +686,7 @@ def read_all(self,reverse=True):
raise NotImplementedError('To be implemented')

# go to start of the data
self.filfile.seek(self.datastart)
self.filfile.seek(int(self.datastart))
# read data into 2-D numpy array
# data=np.fromfile(self.filfile,dtype=self.dtype).reshape(self.channels,self.blocksize,order='F')
data=np.fromfile(self.filfile,dtype=self.dtype).reshape(self.blocksize, self.channels)
Expand All @@ -701,7 +701,7 @@ def read_row(self,rownumber,reverse=True):
raise NotImplementedError('To be implemented')

# go to start of the row
self.filfile.seek(self.datastart+self.channels*rownumber*(self.nbits/8))
self.filfile.seek(int(self.datastart+self.channels*rownumber*(self.nbits/8)))
# read data into 2-D numpy array
data=np.fromfile(self.filfile,count=self.channels,dtype=self.dtype).reshape(1, self.channels)
if reverse:
Expand All @@ -715,7 +715,7 @@ def read_rows(self,rownumber,n_rows,reverse=True):
raise NotImplementedError('To be implemented')

# go to start of the row
self.filfile.seek(self.datastart+self.channels*rownumber*(self.nbits/8))
self.filfile.seek(int(self.datastart+self.channels*rownumber*(self.nbits/8)))
# read data into 2-D numpy array
data=np.fromfile(self.filfile,count=self.channels*n_rows,dtype=self.dtype).reshape(n_rows, self.channels)
if reverse:
Expand Down

0 comments on commit 9a9fdff

Please sign in to comment.