diff --git a/test/test_images_io.py b/test/test_images_io.py index eb3c98b5..761c8a23 100644 --- a/test/test_images_io.py +++ b/test/test_images_io.py @@ -284,6 +284,19 @@ def test_to_tif_roundtrip_multipage(tmpdir, eng): assert allclose(data.toarray(), loaded.toarray()) +def test_to_tiff_roundtrip_multipage(tmpdir, eng): + a = [arange(24, dtype='int16').reshape((2, 3, 4)), arange(24, dtype='int16').reshape((2, 3, 4))] + data = fromlist(a, engine=eng) + data.totif(os.path.join(str(tmpdir), 'images'), prefix='image') + # rename to tiff + for filename in glob.iglob(os.path.join(str(tmpdir), 'images', '*.tif')): + os.rename(filename, filename[:-4] + '.tiff') + files = [os.path.basename(f) for f in glob.glob(str(tmpdir) + '/images/image*')] + assert sorted(files) == ['image-00000.tiff', 'image-00001.tiff'] + loaded = fromtif(os.path.join(str(tmpdir), 'images')) + assert allclose(data.toarray(), loaded.toarray()) + + def test_to_tif_roundtrip_8bit(tmpdir, eng): a = [arange(8, dtype='uint8').reshape((4, 2))] data = fromlist(a, engine=eng) @@ -303,6 +316,6 @@ def test_to_tif_roundtrip_16bit(tmpdir, eng): def test_from_example(eng): return data = fromexample('fish', engine=eng) - assert allclose(data.shape, (20, 76, 87, 2)) + assert allclose(data.shape, (20, 2, 76, 87)) data = fromexample('mouse', engine=eng) assert allclose(data.shape, (20, 64, 64)) \ No newline at end of file diff --git a/test/test_readers.py b/test/test_readers.py index 17942ce3..82117970 100644 --- a/test/test_readers.py +++ b/test/test_readers.py @@ -74,3 +74,24 @@ def test_local_recursive_nested(tmpdir): make(tmpdir, filenames) actual = LocalFileReader().list(str(tmpdir), recursive=True) assert parse(actual) == expected + + +def test_tif_tiff_flat(tmpdir): + filenames = ['b.tif', 'a.tif', 'c.tiff'] + expected = ['a.tif', 'b.tif', 'c.tiff'] + make(tmpdir, filenames) + actual = LocalParallelReader().list(str(tmpdir), ext='tif', recursive=False) + assert parse(actual) == expected + actual = LocalParallelReader().list(str(tmpdir), ext='tif', recursive=True) + assert parse(actual) == expected + + +def test_tif_tiff_recursive(tmpdir): + filenames = ['foo/b.tif', 'foo/bar/q.tiff', 'bar/a', 'c.tif', 'd.tiff'] + expected = ['c.tif', 'd.tiff'] + make(tmpdir, filenames) + actual = LocalParallelReader().list(str(tmpdir), ext='tif', recursive=False) + assert parse(actual) == expected + expected = ['c.tif', 'd.tiff', 'b.tif', 'q.tiff'] + actual = LocalParallelReader().list(str(tmpdir), ext='tif', recursive=True) + assert parse(actual) == expected diff --git a/thunder/readers.py b/thunder/readers.py index b1e0f33a..67c7e03e 100644 --- a/thunder/readers.py +++ b/thunder/readers.py @@ -76,7 +76,11 @@ def listrecursive(path, ext=None): filenames = set() for root, dirs, files in os.walk(path): if ext: - files = fnmatch.filter(files, '*.' + ext) + if ext == 'tif' or ext == 'tiff': + tmp = fnmatch.filter(files, '*.' + 'tiff') + files = tmp + fnmatch.filter(files, '*.' + 'tif') + else: + files = fnmatch.filter(files, '*.' + ext) for filename in files: filenames.add(os.path.join(root, filename)) filenames = list(filenames) @@ -89,13 +93,17 @@ def listflat(path, ext=None): """ if os.path.isdir(path): if ext: - files = glob.glob(os.path.join(path, '*.' + ext)) + if ext == 'tif' or ext == 'tiff': + files = glob.glob(os.path.join(path, '*.tif')) + files = files + glob.glob(os.path.join(path, '*.tiff')) + else: + files = glob.glob(os.path.join(path, '*.' + ext)) else: files = [os.path.join(path, fname) for fname in os.listdir(path)] else: files = glob.glob(path) # filter out directories - files = [fpath for fpath in files if not os.path.isdir(fpath)] + files = [fpath for fpath in files if not isinstance(fpath, list) and not os.path.isdir(fpath)] return sorted(files) def uri_to_path(uri): @@ -341,7 +349,12 @@ def getfiles(self, path, ext=None, start=None, stop=None, recursive=False): bucket, parse[2], prefix=parse[3], postfix=parse[4], recursive=recursive) keylist = [key.name for key in keys] if ext: - keylist = [keyname for keyname in keylist if keyname.endswith(ext)] + if ext == 'tif' or ext == 'tiff': + keylist = [keyname for keyname in keylist if keyname.endswith('tif')] + keylist.append([keyname for keyname in keylist if keyname.endswith('tiff')]) + else: + keylist = [keyname for keyname in keylist if keyname.endswith(ext)] + keylist.sort() keylist = select(keylist, start, stop)