Skip to content

Commit 349df57

Browse files
committed
int division returns floor. fixes #16
1 parent 2650fa7 commit 349df57

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

wfdb/_rdann.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def rdann(recordname, annot, sampfrom=0, sampto=[], anndisp=1):
5959
# First 2 bytes indicate dt=0 and anntype=NOTE. Next 2 indicate auxlen and anntype=AUX. Then follows "## time resolution: "
6060
if [testbytes[i] for i in [0, 1]+list(range(3, 24))]==[0, 88, 252, 35, 35, 32, 116, 105, 109, 101, 32, 114, 101, 115, 111, 108, 117, 116, 105, 111, 110, 58, 32]: # The file's leading bytes match the expected pattern for encoding fs.
6161
auxlen=testbytes[2] # Length of the auxilliary string that includes the fs written into the file.
62-
testbytes=filebytes[:(12+math.ceil(auxlen/2)),:].flatten()
62+
testbytes=filebytes[:(12+math.ceil(auxlen/2.)),:].flatten()
6363
annfs=int("".join([chr(char) for char in testbytes[24:auxlen+4]]))
6464
bpi=0.5*(auxlen+12+(auxlen & 1)) # byte pair index to start reading actual annotations.
6565

@@ -100,11 +100,11 @@ def rdann(recordname, annot, sampfrom=0, sampto=[], anndisp=1):
100100
bpi=bpi+1
101101
elif AT==63: # AUX
102102
auxlen=filebytes[bpi,0] # length of aux string. Max 256? No need to check other bits of second byte?
103-
auxbytes=filebytes[bpi+1:bpi+1+math.ceil(auxlen/2), :].flatten() # The aux bytes
103+
auxbytes=filebytes[bpi+1:bpi+1+math.ceil(auxlen/2.), :].flatten() # The aux bytes
104104
if auxlen&1:
105105
auxbytes=auxbytes[:-1]
106106
aux[ai]="".join([chr(char) for char in auxbytes]) # The aux string
107-
bpi=bpi+1+math.ceil(auxlen/2)
107+
bpi=bpi+1+math.ceil(auxlen/2.)
108108
# Only aux and sub are reset between annotations. Chan and num keep previous value if missing.
109109
AT=filebytes[bpi,1] >> 2
110110

wfdb/_rdsamp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ def processwfdbbytes(fp, fmt, siglen, nsig, sampsperframe, floorsamp=0):
425425

426426
elif fmt=='310': # Three 10 bit samples packed into 4 bytes with 2 bits discarded
427427

428-
nbytesload=int(((nsamp)+2)/3)*4 # The number of bytes needed to be loaded given the number of samples needed
428+
nbytesload=int(((nsamp)+2)/3.)*4 # The number of bytes needed to be loaded given the number of samples needed
429429
if (nsamp-1)%3==0:
430430
nbytesload-=2
431431
sigbytes=np.fromfile(fp, dtype=np.dtype(datatypes[fmt]), count=nbytesload).astype('uint') # Loaded as unsigned 1 byte blocks
@@ -471,7 +471,7 @@ def processwfdbbytes(fp, fmt, siglen, nsig, sampsperframe, floorsamp=0):
471471
sig=(sig/sampsperframe).astype('int')
472472

473473
elif fmt=='311': # Three 10 bit samples packed into 4 bytes with 2 bits discarded
474-
nbytesload=int((nsamp-1)/3)+nsamp+1
474+
nbytesload=int((nsamp-1)/3.)+nsamp+1
475475
sigbytes=np.fromfile(fp, dtype=np.dtype(datatypes[fmt]), count=nbytesload).astype('uint') # Loaded as unsigned 1 byte blocks
476476

477477
if tsampsperframe==nsig: # No extra samples/frame
@@ -539,7 +539,7 @@ def processwfdbbytes(fp, fmt, siglen, nsig, sampsperframe, floorsamp=0):
539539

540540
# Bytes required to hold each sample (including wasted space) for different wfdb formats
541541
bytespersample={'8': 1, '16': 2, '24': 3, '32': 4, '61': 2,
542-
'80': 1, '160':2, '212': 1.5, '310': 4/3, '311': 4/3}
542+
'80': 1, '160':2, '212': 1.5, '310': 4/3., '311': 4/3.}
543543

544544
# Values that correspond to NAN (Format 8 has no NANs)
545545
wfdbInvalids={'16': -32768, '24': -8388608, '32': -2147483648, '61': -32768,

0 commit comments

Comments
 (0)