diff --git a/nd2_dask/__init__.py b/nd2_dask/__init__.py index b000dd0..529d85b 100644 --- a/nd2_dask/__init__.py +++ b/nd2_dask/__init__.py @@ -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"] diff --git a/nd2_dask/nd2_reader.py b/nd2_dask/nd2_reader.py index f32ee5c..53f3a14 100644 --- a/nd2_dask/nd2_reader.py +++ b/nd2_dask/nd2_reader.py @@ -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 @@ -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 @@ -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): @@ -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. diff --git a/requirements.txt b/requirements.txt index abc8d57..22a12b0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,6 @@ napari-plugin-engine>=0.1.4 numpy nd2reader -pims-nd2 dask toolz vispy \ No newline at end of file diff --git a/setup.py b/setup.py index 38afbb1..4ad3860 100644 --- a/setup.py +++ b/setup.py @@ -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='ddon0001@student.monash.edu', license='BSD-3',