From f220515eb6fa438f45c432530290c8b840e150ff Mon Sep 17 00:00:00 2001 From: Lorenzo ZOLFANELLI Date: Mon, 28 Mar 2022 16:17:49 +0200 Subject: [PATCH] complete fork: nd2reader -> nd2reader2 --- nd2reader/__init__.py | 5 --- nd2reader2/__init__.py | 5 +++ {nd2reader => nd2reader2}/artificial.py | 2 +- {nd2reader => nd2reader2}/common.py | 31 ++++++++++++------- .../common_raw_metadata.py | 2 +- {nd2reader => nd2reader2}/exceptions.py | 0 {nd2reader => nd2reader2}/label_map.py | 0 {nd2reader => nd2reader2}/legacy.py | 2 +- {nd2reader => nd2reader2}/parser.py | 8 ++--- {nd2reader => nd2reader2}/raw_metadata.py | 4 +-- {nd2reader => nd2reader2}/reader.py | 4 +-- {nd2reader => nd2reader2}/stitched.py | 0 setup.py | 14 ++++----- test.py | 2 +- tests/test_artificial.py | 6 ++-- tests/test_common.py | 6 ++-- tests/test_label_map.py | 4 +-- tests/test_legacy.py | 6 ++-- tests/test_parser.py | 6 ++-- tests/test_raw_metadata.py | 8 ++--- tests/test_reader.py | 8 ++--- tests/test_version.py | 2 +- 22 files changed, 66 insertions(+), 59 deletions(-) delete mode 100644 nd2reader/__init__.py create mode 100644 nd2reader2/__init__.py rename {nd2reader => nd2reader2}/artificial.py (99%) rename {nd2reader => nd2reader2}/common.py (90%) rename {nd2reader => nd2reader2}/common_raw_metadata.py (98%) rename {nd2reader => nd2reader2}/exceptions.py (100%) rename {nd2reader => nd2reader2}/label_map.py (100%) rename {nd2reader => nd2reader2}/legacy.py (99%) rename {nd2reader => nd2reader2}/parser.py (98%) rename {nd2reader => nd2reader2}/raw_metadata.py (98%) rename {nd2reader => nd2reader2}/reader.py (98%) rename {nd2reader => nd2reader2}/stitched.py (100%) diff --git a/nd2reader/__init__.py b/nd2reader/__init__.py deleted file mode 100644 index 8354a47..0000000 --- a/nd2reader/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -from os import path -from nd2reader.reader import ND2Reader -from nd2reader.legacy import Nd2 - -__version__ = '3.2.3' diff --git a/nd2reader2/__init__.py b/nd2reader2/__init__.py new file mode 100644 index 0000000..c712cb9 --- /dev/null +++ b/nd2reader2/__init__.py @@ -0,0 +1,5 @@ +from os import path +from nd2reader2.reader import ND2Reader +from nd2reader2.legacy import Nd2 + +__version__ = '3.2.3' diff --git a/nd2reader/artificial.py b/nd2reader2/artificial.py similarity index 99% rename from nd2reader/artificial.py rename to nd2reader2/artificial.py index 861c613..9f8aa04 100644 --- a/nd2reader/artificial.py +++ b/nd2reader2/artificial.py @@ -3,7 +3,7 @@ import six import numpy as np import struct -from nd2reader.common import check_or_make_dir +from nd2reader2.common import check_or_make_dir from os import path global_labels = ['image_attributes', 'image_text_info', 'image_metadata', diff --git a/nd2reader/common.py b/nd2reader2/common.py similarity index 90% rename from nd2reader/common.py rename to nd2reader2/common.py index df5ddcf..927e8d3 100644 --- a/nd2reader/common.py +++ b/nd2reader2/common.py @@ -1,10 +1,11 @@ import os import struct import array +import functools from datetime import datetime import six import re -from nd2reader.exceptions import InvalidVersionError +from nd2reader2.exceptions import InvalidVersionError def get_version(fh): @@ -144,7 +145,7 @@ def _parse_double(data): return struct.unpack("d", data.read(8))[0] -def _parse_string(data): +def _parse_string(data, utf8encode=True): """ Args: @@ -163,9 +164,12 @@ def _parse_string(data): value += next_data try: - decoded = value.decode("utf16")[:-1].encode("utf8") + decoded = value.decode("utf16")[:-1] except UnicodeDecodeError: - decoded = value.decode('utf8').encode("utf8") + decoded = value.decode('utf8') + + if utf8encode: + decoded = decoded.encode("utf8") return decoded @@ -209,7 +213,7 @@ def parse_date(text_info): return None -def _parse_metadata_item(data, cursor_position): +def _parse_metadata_item(data, cursor_position, utf8encode=True): """Reads hierarchical data, analogous to a Python dict. Args: @@ -223,7 +227,7 @@ def _parse_metadata_item(data, cursor_position): new_count, length = struct.unpack("=1.6.2', 'six>=1.4', 'xmltodict>=0.9.2', 'PIMS>=0.5.0' ], - version="3.2.3-zolfa-dev0", + version="0.0.1", description='A tool for reading ND2 files produced by NIS Elements', - author='Ruben Verweij', - author_email='ruben@lighthacking.nl', - url='https://github.com/rbnvrw/nd2reader', - download_url='https://github.com/rbnvrw/nd2reader/tarball/%s' % "3.2.3-zolfa-dev0", + author='Lorenzo Zolfanelli', + author_email='dev@zolfa.nl', + url='https://projects.lilik.it/zolfa/nd2reader2', + download_url='https://github.com/rbnvrw/nd2reader2/tarball/%s' % "0.0.1", keywords=['nd2', 'nikon', 'microscopy', 'NIS Elements'], classifiers=['Development Status :: 5 - Production/Stable', 'Intended Audience :: Science/Research', diff --git a/test.py b/test.py index e5a6d6c..46e56b1 100644 --- a/test.py +++ b/test.py @@ -3,4 +3,4 @@ from os import path file_path = path.abspath(__file__) tests_path = path.join(path.abspath(path.dirname(file_path)), "tests") -nose.main(argv=[path.abspath(__file__), "--with-coverage", "--cover-erase", "--cover-package=nd2reader", tests_path]) +nose.main(argv=[path.abspath(__file__), "--with-coverage", "--cover-erase", "--cover-package=nd2reader2", tests_path]) diff --git a/tests/test_artificial.py b/tests/test_artificial.py index e9d2b29..247dcbe 100644 --- a/tests/test_artificial.py +++ b/tests/test_artificial.py @@ -3,10 +3,10 @@ from os import path import six import struct -from nd2reader.artificial import ArtificialND2 -from nd2reader.common import get_version, parse_version, parse_date, _add_to_metadata, _parse_unsigned_char, \ +from nd2reader2.artificial import ArtificialND2 +from nd2reader2.common import get_version, parse_version, parse_date, _add_to_metadata, _parse_unsigned_char, \ _parse_unsigned_int, _parse_unsigned_long, _parse_double, check_or_make_dir -from nd2reader.exceptions import InvalidVersionError +from nd2reader2.exceptions import InvalidVersionError class TestArtificial(unittest.TestCase): diff --git a/tests/test_common.py b/tests/test_common.py index 8e13aaa..c21eb7c 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -5,11 +5,11 @@ import array import six import struct -from nd2reader.artificial import ArtificialND2 -from nd2reader.common import get_version, parse_version, parse_date, _add_to_metadata, _parse_unsigned_char, \ +from nd2reader2.artificial import ArtificialND2 +from nd2reader2.common import get_version, parse_version, parse_date, _add_to_metadata, _parse_unsigned_char, \ _parse_unsigned_int, _parse_unsigned_long, _parse_double, check_or_make_dir, _parse_string, _parse_char_array, \ get_from_dict_if_exists, read_chunk -from nd2reader.exceptions import InvalidVersionError +from nd2reader2.exceptions import InvalidVersionError class TestCommon(unittest.TestCase): diff --git a/tests/test_label_map.py b/tests/test_label_map.py index 1f58fd6..c1a9c12 100644 --- a/tests/test_label_map.py +++ b/tests/test_label_map.py @@ -1,6 +1,6 @@ import unittest -from nd2reader.label_map import LabelMap -from nd2reader.artificial import ArtificialND2 +from nd2reader2.label_map import LabelMap +from nd2reader2.artificial import ArtificialND2 class TestLabelMap(unittest.TestCase): diff --git a/tests/test_legacy.py b/tests/test_legacy.py index 4c938cd..b363f52 100644 --- a/tests/test_legacy.py +++ b/tests/test_legacy.py @@ -1,9 +1,9 @@ import unittest import warnings -from nd2reader.legacy import Nd2 -from nd2reader.reader import ND2Reader -from nd2reader.artificial import ArtificialND2 +from nd2reader2.legacy import Nd2 +from nd2reader2.reader import ND2Reader +from nd2reader2.artificial import ArtificialND2 class TestLegacy(unittest.TestCase): diff --git a/tests/test_parser.py b/tests/test_parser.py index c0b4ddf..ee61367 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -1,8 +1,8 @@ import unittest from os import path -from nd2reader.artificial import ArtificialND2 -from nd2reader.common import check_or_make_dir -from nd2reader.parser import Parser +from nd2reader2.artificial import ArtificialND2 +from nd2reader2.common import check_or_make_dir +from nd2reader2.parser import Parser import urllib.request diff --git a/tests/test_raw_metadata.py b/tests/test_raw_metadata.py index c21e0fe..a364952 100644 --- a/tests/test_raw_metadata.py +++ b/tests/test_raw_metadata.py @@ -1,10 +1,10 @@ import unittest import six -from nd2reader.artificial import ArtificialND2 -from nd2reader.label_map import LabelMap -from nd2reader.raw_metadata import RawMetadata -from nd2reader.common_raw_metadata import parse_roi_shape, parse_roi_type, parse_dimension_text_line +from nd2reader2.artificial import ArtificialND2 +from nd2reader2.label_map import LabelMap +from nd2reader2.raw_metadata import RawMetadata +from nd2reader2.common_raw_metadata import parse_roi_shape, parse_roi_type, parse_dimension_text_line class TestRawMetadata(unittest.TestCase): diff --git a/tests/test_reader.py b/tests/test_reader.py index c28399d..2a4ce76 100644 --- a/tests/test_reader.py +++ b/tests/test_reader.py @@ -3,10 +3,10 @@ import numpy as np import struct from pims import Frame -from nd2reader.artificial import ArtificialND2 -from nd2reader.exceptions import EmptyFileError, InvalidFileType -from nd2reader.reader import ND2Reader -from nd2reader.parser import Parser +from nd2reader2.artificial import ArtificialND2 +from nd2reader2.exceptions import EmptyFileError, InvalidFileType +from nd2reader2.reader import ND2Reader +from nd2reader2.parser import Parser class TestReader(unittest.TestCase): diff --git a/tests/test_version.py b/tests/test_version.py index fedfeeb..16de58e 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -1,5 +1,5 @@ import unittest -from nd2reader import __version__ as VERSION +from nd2reader2 import __version__ as VERSION class TestVersion(unittest.TestCase):