Skip to content

Commit 30ec61b

Browse files
committed
REF Rebase pims.open on imageio
1 parent 621028e commit 30ec61b

File tree

2 files changed

+45
-40
lines changed

2 files changed

+45
-40
lines changed

pims/api.py

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -167,51 +167,56 @@ def open(sequence, **kwargs):
167167
>>> frame_count = len(video) # Number of frames in video
168168
>>> frame_shape = video.frame_shape # Pixel dimensions of video
169169
"""
170+
# check if it is an ImageSequence
170171
files = glob.glob(sequence)
171172
if len(files) > 1:
172173
# todo: test if ImageSequence can read the image type,
173174
# delegate to subclasses as needed
174175
return ImageSequence(sequence, **kwargs)
175176

176-
_, ext = os.path.splitext(sequence)
177-
if ext is None or len(ext) < 2:
178-
raise UnknownFormatError(
179-
"Could not detect your file type because it did not have an "
180-
"extension. Try specifying a loader class, e.g. "
181-
"Video({0})".format(sequence))
182-
ext = ext.lower()[1:]
183-
184-
# list all readers derived from the pims baseclasses
185-
all_handlers = chain(_recursive_subclasses(FramesSequence),
186-
_recursive_subclasses(FramesSequenceND))
187-
# keep handlers that support the file ext. use set to avoid duplicates.
188-
eligible_handlers = set(h for h in all_handlers
189-
if ext and ext in map(_drop_dot, h.class_exts()))
190-
if len(eligible_handlers) < 1:
191-
raise UnknownFormatError(
192-
"Could not autodetect how to load a file of type {0}. "
193-
"Try manually "
194-
"specifying a loader class, e.g. Video({1})".format(ext, sequence))
195-
196-
def sort_on_priority(handlers):
197-
# This uses optional priority information from subclasses
198-
# > 10 means that it will be used instead of than built-in subclasses
199-
def priority(cls):
200-
try:
201-
return cls.class_priority
202-
except AttributeError:
203-
return 10
204-
return sorted(handlers, key=priority, reverse=True)
205-
206-
exceptions = ''
207-
for handler in sort_on_priority(eligible_handlers):
208-
try:
209-
return handler(sequence, **kwargs)
210-
except Exception as e:
211-
message = '{0} errored: {1}'.format(str(handler), str(e))
212-
warn(message)
213-
exceptions += message + '\n'
214-
raise UnknownFormatError("All handlers returned exceptions:\n" + exceptions)
177+
# the rest of the Reader choosing logic is handled by imageio
178+
return WrapImageIOReader(get_reader(sequence, **kwargs))
179+
#
180+
#
181+
# _, ext = os.path.splitext(sequence)
182+
# if ext is None or len(ext) < 2:
183+
# raise UnknownFormatError(
184+
# "Could not detect your file type because it did not have an "
185+
# "extension. Try specifying a loader class, e.g. "
186+
# "Video({0})".format(sequence))
187+
# ext = ext.lower()[1:]
188+
#
189+
# # list all readers derived from the pims baseclasses
190+
# all_handlers = chain(_recursive_subclasses(FramesSequence),
191+
# _recursive_subclasses(FramesSequenceND))
192+
# # keep handlers that support the file ext. use set to avoid duplicates.
193+
# eligible_handlers = set(h for h in all_handlers
194+
# if ext and ext in map(_drop_dot, h.class_exts()))
195+
# if len(eligible_handlers) < 1:
196+
# raise UnknownFormatError(
197+
# "Could not autodetect how to load a file of type {0}. "
198+
# "Try manually "
199+
# "specifying a loader class, e.g. Video({1})".format(ext, sequence))
200+
#
201+
# def sort_on_priority(handlers):
202+
# # This uses optional priority information from subclasses
203+
# # > 10 means that it will be used instead of than built-in subclasses
204+
# def priority(cls):
205+
# try:
206+
# return cls.class_priority
207+
# except AttributeError:
208+
# return 10
209+
# return sorted(handlers, key=priority, reverse=True)
210+
#
211+
# exceptions = ''
212+
# for handler in sort_on_priority(eligible_handlers):
213+
# try:
214+
# return handler(sequence, **kwargs)
215+
# except Exception as e:
216+
# message = '{0} errored: {1}'.format(str(handler), str(e))
217+
# warn(message)
218+
# exceptions += message + '\n'
219+
# raise UnknownFormatError("All handlers returned exceptions:\n" + exceptions)
215220

216221

217222
class UnknownFormatError(Exception):

pims/tests/test_bioformats.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test_bool(self):
4242

4343
def test_open(self):
4444
self.v.close()
45-
self.v = pims.open(self.filename)
45+
self.v = pims.open(self.filename, format='Bioformats')
4646

4747
def test_integer_attributes(self):
4848
self.check_skip()

0 commit comments

Comments
 (0)