Skip to content

Commit

Permalink
Supporting cascaded files (#30)
Browse files Browse the repository at this point in the history
* Bump version to 0.3.5

* Supporting sif_version 65564 without confidence

* Removed unecessary option

* Supporting extra files
  • Loading branch information
fujiisoup authored Feb 20, 2024
1 parent 80b41a9 commit ad6509d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
15 changes: 13 additions & 2 deletions sif_parser/_sif_open.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ def _read_until(fp, terminator=' '):
word += c
return word

def _skip_spaces(fp):
'''Read until something other than space or line end '''
while True:
offset = fp.tell()
c = _to_string(fp.read(1))
if c not in [' ', '\n']:
fp.seek(offset)
return fp
raise ValueError('Reached the end of the file')

def _read_int(fp):
return int(_read_until(fp, ' '))

Expand Down Expand Up @@ -199,10 +209,11 @@ def _open(fp):
tile = []
info['xbin'] = xbin
info['ybin'] = ybin


fp = _skip_spaces(fp)
for f in range(no_images):
info['timestamp_of_{0:d}'.format(f)] = int(fp.readline())

offset = fp.tell()
try: # remove extra 0 if it exits.
flag = int(fp.readline())
Expand Down
3 changes: 2 additions & 1 deletion testings/test_open.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# data directories that will be tested
DATA_DIR = THIS_DIR + '/sif_parser_testdata/'
PUBLIC_DATA_DIR = THIS_DIR + '/public_testdata/'
EXTRA_DATA_DIR = THIS_DIR + '/extra_data/'

import PIL.Image
import numpy as np
Expand All @@ -21,7 +22,7 @@


filenames = []
for d in [DATA_DIR, PUBLIC_DATA_DIR]:
for d in [DATA_DIR, PUBLIC_DATA_DIR, EXTRA_DATA_DIR]:
if os.path.exists(d):
files = os.listdir(d)
filenames += [d + f for f in files if f[-4:] in ['.sif', '.SIF']]
Expand Down

0 comments on commit ad6509d

Please sign in to comment.