Skip to content

Commit

Permalink
MAINT: Cleanup and numpy's warning suppression
Browse files Browse the repository at this point in the history
  • Loading branch information
tritemio committed Sep 30, 2016
1 parent da38d76 commit 17688ef
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions fretbursts/dataload/multi_ch_reader.py
Expand Up @@ -19,33 +19,38 @@

from ..utils.misc import pprint

## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# DATA LOADING
#

def read_int32_int32_file(fname, n_bytes_to_read=-1):
"""Read the data file with 32+32 bit format (int32 version)."""
try: f = open(fname, 'rb')
try:
f = open(fname, 'rb')
except IOError:
fname += '.dat'
f = open(fname, 'rb')

## Reading the header
l1 = f.readline(); l2 = f.readline(); l3 = f.readline()
words_per_photon = l2.split()[-1]
# Reading the header
lines = [f.readline() for _ in range(3)]
words_per_photon = lines[1].split()[-1]
assert words_per_photon == b'2'

## Reading data in int32
# Reading data in int32
bytes_in_file = os.path.getsize(fname) - f.tell()
if n_bytes_to_read < 4:
n_bytes_to_read = bytes_in_file
N_bytes = (int(min(n_bytes_to_read, bytes_in_file))//4)*4
data = np.ndarray(shape=(N_bytes/4,), dtype='>i4', buffer=f.read(N_bytes))
detector = data[::2]+1
ph_times = (data[1::2]-data[1])
assert ((detector < 17)*(detector >= 0)).all()
N_bytes = (int(min(n_bytes_to_read, bytes_in_file)) // 4) * 4
data = np.ndarray(shape=(N_bytes // 4,), dtype='>i4',
buffer=f.read(N_bytes))
detector = data[::2] + 1
ph_times = (data[1::2] - data[1])
assert ((detector < 17) * (detector >= 0)).all()
return ph_times, detector.astype('uint8')

## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# DATA CONVERSION
#

Expand Down Expand Up @@ -195,4 +200,3 @@ def unwind_uni_o(times, det, nch=8, times_nbit=28, debug=True):

## NOTE: write a compare function that takes into account same timestamps
## in donor and acceptor ch.

0 comments on commit 17688ef

Please sign in to comment.