Skip to content

Commit

Permalink
Remove pims-nd2 dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Draga Doncila Pop committed Nov 11, 2020
1 parent bbe8a93 commit b633fad
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 81 deletions.
2 changes: 1 addition & 1 deletion nd2_dask/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
__version__ = "unknown"

# replace the asterisk with named imports
from .nd2_reader import napari_get_pims_reader
from .nd2_reader import napari_get_nd2_reader


__all__ = ["napari_get_reader"]
78 changes: 0 additions & 78 deletions nd2_dask/nd2_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"""
import numpy as np
from nd2reader import ND2Reader
from pims import ND2_Reader
from dask import delayed
import dask.array as da
import toolz as tz
Expand All @@ -32,14 +31,6 @@
]


def get_pims_nd2_vol(nd2_data, c, frame):
nd2_data.default_coords['c']=c
nd2_data.bundle_axes = 'zyx'
v = nd2_data[frame]
v = np.array(v)
return v


def get_nd2reader_nd2_vol(path, c, frame):
with ND2Reader(path) as nd2_data:
nd2_data.default_coords['c']=c
Expand All @@ -48,29 +39,6 @@ def get_nd2reader_nd2_vol(path, c, frame):
v = np.array(v)
return v

# @napari_hook_implementation(specname="napari_get_reader")
def napari_get_pims_reader(path):
"""Returns reader if path is valid .nd2 file, otherwise None
Parameters
----------
path : str or list of str
Path to file, or list of paths.
Returns
-------
function or None
If the path is a recognized nd2 file, return a function that accepts the
same path or list of paths, and returns a list of layer data tuples.
"""

# can only read nd2 files
if not path.endswith(".nd2"):
return None

# otherwise we return the *function* that can read ``path``.
return pims_reader


@napari_hook_implementation(specname="napari_get_reader")
def napari_get_nd2_reader(path):
Expand All @@ -96,52 +64,6 @@ def napari_get_nd2_reader(path):
return nd2_reader


def pims_reader(path, max_retries=30):
"""Take a path or list of paths and return a list of LayerData tuples.
Readers are expected to return data as a list of tuples, where each tuple
is (data, [add_kwargs, [layer_type]]), "add_kwargs" and "layer_type" are
both optional.
Parameters
----------
path : str or list of str
Path to file, or list of paths.
Returns
-------
layer_data : list of tuples
A list of LayerData tuples where each tuple in the list contains
(data, metadata, layer_type), where data is a numpy array, metadata is
a dict of keyword arguments for the corresponding viewer.add_* method
in napari, and layer_type is a lower-case string naming the type of layer.
Both "meta", and "layer_type" are optional. napari will default to
layer_type=="image" if not provided
"""

tries = 0
while tries < max_retries:
try:
nd2_data = ND2_Reader(path)
channels = [nd2_data.metadata[f"plane_{i}"]["name"] for i in range(0, nd2_data.sizes['c'])]
n_timepoints = nd2_data.sizes['t']
frame_shape = nd2_data.frame_shape
frame_dtype = nd2_data.pixel_type
nd2vol = tz.curry(get_pims_nd2_vol)
channel_dict = dict(zip(channels, [[] for _ in range(len(channels))]))
layer_list = get_layer_list(channels, nd2vol, nd2_data, frame_shape, frame_dtype, n_timepoints)

for (data, _, _) in layer_list:
shape = np.asarray(data[0]).shape
break
except Exception as e:
tries += 1
if tries > max_retries:
raise e

return layer_list


def nd2_reader(path):
"""Take a path or list of paths and return a list of LayerData tuples.
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
napari-plugin-engine>=0.1.4
numpy
nd2reader
pims-nd2
dask
toolz
vispy
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def read(fname):

setup(
name='nd2_dask',
version='0.0.2',
version='0.0.3',
author='Draga Doncila Pop',
author_email='[email protected]',
license='BSD-3',
Expand Down

0 comments on commit b633fad

Please sign in to comment.