Skip to content

Commit

Permalink
z5py lacks a pypi package, so make imports conditional constantinpape…
Browse files Browse the repository at this point in the history
  • Loading branch information
pgunn committed Mar 3, 2022
1 parent 615c076 commit 96d4f80
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
9 changes: 7 additions & 2 deletions caiman/base/movies.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
from tqdm import tqdm
from typing import Any, Dict, List, Tuple, Union
import warnings
import z5py
# Flip to normal import if this is ever resolved: https://github.com/constantinpape/z5/issues/146
# import z5py
from zipfile import ZipFile

import caiman as cm
Expand Down Expand Up @@ -1288,7 +1289,7 @@ def play(self,
im.axes.figure.canvas.draw()
pl.pause(1)

if backend == 'notebook':
elif backend == 'notebook':
# First set up the figure, the axis, and the plot element we want to animate
fig = pl.figure()
im = pl.imshow(self[0], interpolation='None', cmap=pl.cm.gray)
Expand Down Expand Up @@ -1685,6 +1686,10 @@ def rgb2gray(rgb):
raise Exception('Key not found in hdf5 file')

elif extension in ('.n5', '.zarr'):
try:
import z5py
except ImportError:
raise Exception("z5py library not available; if you need this functionality use the conda package")
with z5py.File(file_name, "r") as f:
fkeys = list(f.keys())
if len(fkeys) == 1: # If the n5/zarr file we're parsing has only one dataset inside it, ignore the arg and pick that dataset
Expand Down
8 changes: 7 additions & 1 deletion caiman/source_extraction/cnmf/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
import scipy.ndimage.morphology as morph
import tifffile
from typing import List
import z5py
# https://github.com/constantinpape/z5/issues/146
#import z5py

from .initialization import greedyROI
from ...base.rois import com
Expand Down Expand Up @@ -1029,6 +1030,11 @@ def get_file_size(file_name, var_name_hdf5='mov'):
raise Exception('Variable not found. Use one of the above')
T, dims = siz[0], siz[1:]
elif extension in ('.n5', '.zarr'):
try:
import z5py
except:
raise Exception("z5py not available; if you need this use the conda-based setup")

with z5py.File(file_name, "r") as f:
kk = list(f.keys())
if len(kk) == 1:
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ tifffile
tk
tqdm
yapf
z5py
1 change: 0 additions & 1 deletion requirements_gpu.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ tifffile
tk
tqdm
yapf
z5py

0 comments on commit 96d4f80

Please sign in to comment.