diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a05ede5 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ + +The MIT License (MIT) + +Copyright (c) 2020 Draga Doncila Pop + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..0439384 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,6 @@ +include LICENSE +include README.md +include requirements.txt + +recursive-exclude * __pycache__ +recursive-exclude * *.py[co] diff --git a/README.md b/README.md new file mode 100644 index 0000000..ef212a0 --- /dev/null +++ b/README.md @@ -0,0 +1,57 @@ +# napari-sentinel-zip + +[![License](https://img.shields.io/pypi/l/napari-sentinel-zip.svg?color=green)](https://github.com/napari/napari-sentinel-zip/raw/master/LICENSE) +[![PyPI](https://img.shields.io/pypi/v/napari-sentinel-zip.svg?color=green)](https://pypi.org/project/napari-sentinel-zip) +[![Python Version](https://img.shields.io/pypi/pyversions/napari-sentinel-zip.svg?color=green)](https://python.org) +[![tests](https://github.com/DragaDoncila/napari-sentinel-zip/workflows/tests/badge.svg)](https://github.com/DragaDoncila/napari-sentinel-zip/actions) +[![codecov](https://codecov.io/gh/DragaDoncila/napari-sentinel-zip/branch/master/graph/badge.svg)](https://codecov.io/gh/DragaDoncila/napari-sentinel-zip) + +Stacks and opens Sentinel mission zip archives for one tile across different timepoints. + +---------------------------------- + +This [napari] plugin was generated with [Cookiecutter] using with [@napari]'s [cookiecutter-napari-plugin] template. + + + +## Installation + +You can install `napari-sentinel-zip` via [pip]: + + pip install napari-sentinel-zip + +## Contributing + +Contributions are very welcome. Tests can be run with [tox], please ensure +the coverage at least stays the same before you submit a pull request. + +## License + +Distributed under the terms of the [MIT] license, +"napari-sentinel-zip" is free and open source software + +## Issues + +If you encounter any problems, please [file an issue] along with a detailed description. + +[napari]: https://github.com/napari/napari +[Cookiecutter]: https://github.com/audreyr/cookiecutter +[@napari]: https://github.com/napari +[MIT]: http://opensource.org/licenses/MIT +[BSD-3]: http://opensource.org/licenses/BSD-3-Clause +[GNU GPL v3.0]: http://www.gnu.org/licenses/gpl-3.0.txt +[GNU LGPL v3.0]: http://www.gnu.org/licenses/lgpl-3.0.txt +[Apache Software License 2.0]: http://www.apache.org/licenses/LICENSE-2.0 +[Mozilla Public License 2.0]: https://www.mozilla.org/media/MPL/2.0/index.txt +[cookiecutter-napari-plugin]: https://github.com/napari/cookiecutter-napari-plugin +[file an issue]: https://github.com/DragaDoncila/napari-sentinel-zip/issues +[napari]: https://github.com/napari/napari +[tox]: https://tox.readthedocs.io/en/latest/ +[pip]: https://pypi.org/project/pip/ +[PyPI]: https://pypi.org/ \ No newline at end of file diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..2c2e537 --- /dev/null +++ b/docs/index.md @@ -0,0 +1,3 @@ +# Welcome to napari-sentinel-zip + +Stacks and opens Sentinel mission zip archives for one tile across different timepoints. diff --git a/mkdocs.yml b/mkdocs.yml new file mode 100644 index 0000000..9616198 --- /dev/null +++ b/mkdocs.yml @@ -0,0 +1,10 @@ +site_name: napari-sentinel-zip +site_description: Stacks and opens Sentinel mission zip archives for one tile across different timepoints. +site_author: Draga Doncila Pop + +theme: readthedocs + +repo_url: https://github.com/DragaDoncila/napari-sentinel-zip + +pages: +- Home: index.md diff --git a/napari_sentinel_zip/__init__.py b/napari_sentinel_zip/__init__.py new file mode 100644 index 0000000..1f84f71 --- /dev/null +++ b/napari_sentinel_zip/__init__.py @@ -0,0 +1,10 @@ +try: + from ._version import version as __version__ +except ImportError: + __version__ = "unknown" + +# replace the asterisk with named imports +from .napari_sentinel_zip import napari_get_reader + + +__all__ = ["napari_get_reader"] diff --git a/napari_sentinel_zip/_tests/__init__.py b/napari_sentinel_zip/_tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/napari_sentinel_zip/_tests/test_napari_sentinel_zip.py b/napari_sentinel_zip/_tests/test_napari_sentinel_zip.py new file mode 100644 index 0000000..c91914a --- /dev/null +++ b/napari_sentinel_zip/_tests/test_napari_sentinel_zip.py @@ -0,0 +1,30 @@ +import numpy as np +from napari_napari_sentinel_zip import napari_get_reader + + +# tmp_path is a pytest fixture +def test_reader(tmp_path): + """An example of how you might test your plugin.""" + + # write some fake data using your supported file format + my_test_file = str(tmp_path / "myfile.npy") + original_data = np.random.rand(20, 20) + np.save(my_test_file, original_data) + + # try to read it back in + reader = napari_get_reader(my_test_file) + assert callable(reader) + + # make sure we're delivering the right format + layer_data_list = reader(my_test_file) + assert isinstance(layer_data_list, list) and len(layer_data_list) > 0 + layer_data_tuple = layer_data_list[0] + assert isinstance(layer_data_tuple, tuple) and len(layer_data_tuple) > 0 + + # make sure it's the same as it started + np.testing.assert_allclose(original_data, layer_data_tuple[0]) + + +def test_get_reader_pass(): + reader = napari_get_reader("fake.file") + assert reader is None diff --git a/napari_sentinel_zip/napari_sentinel_zip.py b/napari_sentinel_zip/napari_sentinel_zip.py new file mode 100644 index 0000000..60f5073 --- /dev/null +++ b/napari_sentinel_zip/napari_sentinel_zip.py @@ -0,0 +1,79 @@ +""" +This module is an example of a barebones numpy reader plugin for napari. + +It implements the ``napari_get_reader`` hook specification, (to create +a reader plugin) but your plugin may choose to implement any of the hook +specifications offered by napari. +see: https://napari.org/docs/plugins/hook_specifications.html + +Replace code below accordingly. For complete documentation see: +https://napari.org/docs/plugins/for_plugin_developers.html +""" +import numpy as np +from napari_plugin_engine import napari_hook_implementation + + +@napari_hook_implementation +def napari_get_reader(path): + """A basic implementation of the napari_get_reader hook specification. + + Parameters + ---------- + path : str or list of str + Path to file, or list of paths. + + Returns + ------- + function or None + If the path is a recognized format, return a function that accepts the + same path or list of paths, and returns a list of layer data tuples. + """ + if isinstance(path, list): + # reader plugins may be handed single path, or a list of paths. + # if it is a list, it is assumed to be an image stack... + # so we are only going to look at the first file. + path = path[0] + + # if we know we cannot read the file, we immediately return None. + if not path.endswith(".npy"): + return None + + # otherwise we return the *function* that can read ``path``. + return reader_function + + +def reader_function(path): + """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 + """ + # handle both a string and a list of strings + paths = [path] if isinstance(path, str) else path + # load all files into array + arrays = [np.load(_path) for _path in paths] + # stack arrays into single array + data = np.squeeze(np.stack(arrays)) + + # optional kwargs for the corresponding viewer.add_* method + # https://napari.org/docs/api/napari.components.html#module-napari.components.add_layers_mixin + add_kwargs = {} + + layer_type = "image" # optional, default is "image" + return [(data, add_kwargs, layer_type)] diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..88c9ed4 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +napari_plugin_engine>=0.1.4 +numpy \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..5113221 --- /dev/null +++ b/setup.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os +import codecs +from setuptools import setup, find_packages + + +def read(fname): + file_path = os.path.join(os.path.dirname(__file__), fname) + return codecs.open(file_path, encoding='utf-8').read() + + +# Add your dependencies in requirements.txt +# Note: you can add test-specific requirements in tox.ini +requirements = [] +with open('requirements.txt') as f: + for line in f: + stripped = line.split("#")[0].strip() + if len(stripped) > 0: + requirements.append(stripped) + + +# https://github.com/pypa/setuptools_scm +use_scm = {"write_to": "napari_napari_sentinel_zip/_version.py"} + +setup( + name='napari-sentinel-zip', + author='Draga Doncila Pop', + author_email='ddon0001@student.monash.edu', + license='MIT', + url='https://github.com/DragaDoncila/napari-sentinel-zip', + description='Stacks and opens Sentinel mission zip archives for one tile across different timepoints.', + long_description=read('README.md'), + long_description_content_type='text/markdown', + packages=find_packages(), + python_requires='>=3.6', + install_requires=requirements, + use_scm_version=use_scm, + setup_requires=['setuptools_scm'], + classifiers=[ + 'Development Status :: 4 - Beta', + 'Intended Audience :: Developers', + 'Topic :: Software Development :: Testing', + 'Programming Language :: Python', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: Implementation :: CPython', + 'Programming Language :: Python :: Implementation :: PyPy', + 'Operating System :: OS Independent', + 'License :: OSI Approved :: MIT License', + ], + entry_points={ + 'napari.plugin': [ + 'sentinel-zip = napari_napari_sentinel_zip', + ], + }, +) diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..5cbeb41 --- /dev/null +++ b/tox.ini @@ -0,0 +1,21 @@ +# For more information about tox, see https://tox.readthedocs.io/en/latest/ +[tox] +envlist = py{36,37,38}-{linux,macos,windows} + +[gh-actions] +python = + 3.6: py36 + 3.7: py37 + 3.8: py38 + +[gh-actions:env] +PLATFORM = + ubuntu-latest: linux + macos-latest: macos + windows-latest: windows + +[testenv] +commands = pytest -v --cov=./ --cov-report=xml +deps = + pytest-cov # https://pytest-cov.readthedocs.io/en/latest/ + pytest # https://docs.pytest.org/en/latest/contents.html \ No newline at end of file