Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions pims/image_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,24 @@
from skimage.io import imread
except ImportError:
try:
from matplotlib.pyplot import imread
# imread() works differently between scikit-image and matplotlib.
# We don't require users to have scikit-image,
# but if we fall back to matplotlib, make sure the user
# is aware of the consequences.
ski_preferred = ("PIMS image_reader.py could not find scikit-image. "
"Falling back to matplotlib's imread(), which uses floats "
"instead of integers. This may break your scripts. \n"
"(To ignore this warning, include the line "
'"warnings.simplefilter("ignore", RuntimeWarning)" '
"in your script.)")
warnings.warn(RuntimeWarning(ski_preferred))
from imageio import imread
except ImportError:
imread = None
try:
from matplotlib.pyplot import imread
# imread() works differently between scikit-image and matplotlib.
# We don't require users to have scikit-image,
# but if we fall back to matplotlib, make sure the user
# is aware of the consequences.
ski_preferred = ("PIMS image_reader.py could not find either "
"scikit-image or imageio installed. "
"Falling back to matplotlib's imread(), which uses floats "
"instead of integers. This may break your scripts. \n"
"(To ignore this warning, include the line "
'"warnings.simplefilter("ignore", RuntimeWarning)" '
"in your script.)")
warnings.warn(RuntimeWarning(ski_preferred))
except ImportError:
imread = None


class ImageReader(FramesSequence):
Expand Down
7 changes: 5 additions & 2 deletions pims/image_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@
has_skimage = True
except ImportError:
try:
from matplotlib.pyplot import imread
from imageio import imread
except ImportError:
imread = None
try:
from matplotlib.pyplot import imread
except ImportError:
imread = None


class ImageSequence(FramesSequence):
Expand Down
11 changes: 11 additions & 0 deletions pims/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ def _skip_if_no_skimage():
raise nose.SkipTest('skimage not installed. Skipping.')


def _skip_if_no_skimage_or_matplotlib():
try:
import skimage
except ImportError:
try:
import matplotlib
except ImportError:
raise nose.SkipTest('Test requires either matplotlib or'
' scikit-image. Skipping.')


def _skip_if_no_PIL():
import pims.tiff_stack
if not pims.tiff_stack.PIL_available():
Expand Down
5 changes: 3 additions & 2 deletions pims/tests/test_imseq.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

from pims.tests.test_common import (_image_series,
clean_dummy_png, save_dummy_png,
_skip_if_no_skimage, _skip_if_no_imread)
_skip_if_no_skimage, _skip_if_no_imread,
_skip_if_no_skimage_or_matplotlib)

path, _ = os.path.split(os.path.abspath(__file__))
path = os.path.join(path, 'data')
Expand Down Expand Up @@ -107,7 +108,7 @@ def tearDown(self):

class TestImageSequenceNaturalSorting(_image_series, unittest.TestCase):
def setUp(self):
_skip_if_no_imread()
_skip_if_no_skimage_or_matplotlib()
self.filepath = os.path.join(path, 'image_sequence')
self.filenames = ['T76S3F1.png', 'T76S3F20.png',
'T76S3F3.png', 'T76S3F4.png',
Expand Down