Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
ywkure committed Feb 18, 2021
1 parent b4bcaf8 commit e855db0
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 30 deletions.
6 changes: 3 additions & 3 deletions napari_split_dataset/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Top-level package for napari-split-dataset."""
"""hdf5/split-dataset file reader for napari"""

__author__ = """You Wu"""
__author__ = """You Wu @portugueslab"""
__version__ = "0.1.0"

from ._reader import napari_get_reader
from napari_split_dataset.napari_split_dataset import napari_get_reader
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def napari_get_reader(path):

def read_directory(path):
# read the image stack from a split dataset directory

try:
data = SplitDataset(path)
except (IndexError, KeyError, ValueError):
Expand All @@ -28,30 +27,26 @@ def read_directory(path):
# set contrast limits for 4D data.
# otherwise napari tries to set them after reading everything,
# which would take too long if the data was large.
data_for_contrast = data[
min(2, data.shape[0] - 1) : min(7, data.shape[0]), :, :, :
]
partial = data[min(2, data.shape[0] - 1) : min(7, data.shape[0]), :, :, :]
contrast_limits = (
np.percentile(data_for_contrast, 0.1),
np.percentile(data_for_contrast, 99.9),
np.percentile(partial, 0.1),
np.percentile(partial, 99.9),
)

data = data.as_dask() # read as a dask array
# optional kwargs for the corresponding viewer.add_* method
add_kwargs = {
"contrast_limits": contrast_limits,
}
else:
data = data[:, :, :]
add_kwargs = {}

layer_type = "image" # optional, default is "image"
layer_type = "image" # default
return [(data, add_kwargs, layer_type)]


def read_hdf5(path):
# read the image if the h5 file is an array or part of split dataset files

try:
data = fl.load(path)
except (OSError, RuntimeError):
Expand Down
12 changes: 4 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
with open("README.rst") as readme_file:
readme = readme_file.read()

# with open('HISTORY.rst') as history_file:
# history = history_file.read()

with open("requirements.txt") as f:
requirements = f.read().splitlines()

Expand All @@ -25,13 +22,13 @@
]

setup(
author="You Wu",
author_email="[email protected]",
author="You Wu @portugueslab",
author_email="[email protected]",
python_requires=">=3.5",
classifiers=[
"Development Status :: 2 - Pre-Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
Expand All @@ -42,8 +39,7 @@
description="hdf5/split-dataset file reader for napari",
extras_require=dict(dev=requirements_dev),
install_requires=requirements,
license="GNU General Public License v3",
# long_description=readme + '\n\n' + history,
license="MIT",
include_package_data=True,
keywords="napari_split_dataset",
name="napari_split_dataset",
Expand Down
3 changes: 0 additions & 3 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
"""Unit test package for napari_split_dataset."""
from pathlib import Path

ASSETS_PATH = Path(__file__).parent / "assets"
15 changes: 8 additions & 7 deletions tests/test_napari_split_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

"""Tests for `napari_split_dataset` package."""

from pathlib import Path

import pytest
from dask.array.core import Array
from numpy import ndarray

from napari_split_dataset import _reader
from napari_split_dataset import napari_split_dataset

from . import ASSETS_PATH
ASSETS_PATH = Path(__file__).parent / "assets"


@pytest.mark.parametrize(
Expand All @@ -27,7 +29,7 @@
],
)
def test_reader(path, expected):
reader = _reader.napari_get_reader(path)
reader = napari_split_dataset.napari_get_reader(path)
assert callable(reader) == expected


Expand All @@ -41,7 +43,7 @@ def test_reader(path, expected):
],
)
def test_dir_reader(path, expected):
data = _reader.read_directory(path)
data = napari_split_dataset.read_directory(path)
if isinstance(data, list):
data = data[0][0]
assert isinstance(data, expected)
Expand All @@ -50,15 +52,14 @@ def test_dir_reader(path, expected):
@pytest.mark.parametrize(
"path, expected",
[
(ASSETS_PATH / "sample_4d", type(None)),
(ASSETS_PATH / "random", type(None)),
(ASSETS_PATH / "sample_3d", type(None)),
(ASSETS_PATH / "array.h5", ndarray),
(ASSETS_PATH / "dict_stack.h5", ndarray),
(ASSETS_PATH / "dict_shift.h5", type(None)),
],
)
def test_h5_reader(path, expected):
data = _reader.read_hdf5(path)
data = napari_split_dataset.read_hdf5(path)
if isinstance(data, list):
data = data[0][0]
assert isinstance(data, expected)

0 comments on commit e855db0

Please sign in to comment.