From df1cf09e363cf6ea1b9e4d87337b77469ea16dfb Mon Sep 17 00:00:00 2001 From: Gabriele Girelli Date: Wed, 30 Oct 2019 12:29:03 +0100 Subject: [PATCH 1/4] Using Z slice coordinates from Z-data instead of Z-levels and show warning in case of mismatch --- nd2reader/raw_metadata.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/nd2reader/raw_metadata.py b/nd2reader/raw_metadata.py index 321136d..2e7c428 100644 --- a/nd2reader/raw_metadata.py +++ b/nd2reader/raw_metadata.py @@ -2,6 +2,7 @@ import re import xmltodict import six import numpy as np +import warnings from nd2reader.common import read_chunk, read_array, read_metadata, parse_date, get_from_dict_if_exists from nd2reader.common_raw_metadata import parse_dimension_text_line, parse_if_not_none, parse_roi_shape, parse_roi_type, get_loops_from_data, determine_sampling_interval @@ -160,7 +161,12 @@ class RawMetadata(object): Returns: list: the z levels, just a sequence from 0 to n. """ - return self._parse_dimension(r""".*?Z\((\d+)\).*?""") + z_levels = self._parse_dimension(r""".*?Z\((\d+)\).*?""") + if 0 == len(z_levels): + z_levels = range(len(parse_if_not_none(self.z_data, self._parse_z_coordinates))) + if 0 != z_levels: + warnings.warn("Z-levels details missing in metadata. Using Z-coordinates instead.") + return z_levels def _parse_z_coordinates(self): """The coordinate in micron for all z planes. From bec47a5fb624fcd920e1b35cee7d3db00e3e9586 Mon Sep 17 00:00:00 2001 From: Gabriele Girelli Date: Thu, 31 Oct 2019 16:09:29 +0100 Subject: [PATCH 2/4] Update raw_metadata.py --- nd2reader/raw_metadata.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nd2reader/raw_metadata.py b/nd2reader/raw_metadata.py index 2e7c428..72720f7 100644 --- a/nd2reader/raw_metadata.py +++ b/nd2reader/raw_metadata.py @@ -163,7 +163,11 @@ class RawMetadata(object): """ z_levels = self._parse_dimension(r""".*?Z\((\d+)\).*?""") if 0 == len(z_levels): - z_levels = range(len(parse_if_not_none(self.z_data, self._parse_z_coordinates))) + z_levels = parse_if_not_none(self.z_data, self._parse_z_coordinates) + if isinstance(z_levels, type(None)): + z_levels = [] + else: + z_levels = range(len(z_levels)) if 0 != z_levels: warnings.warn("Z-levels details missing in metadata. Using Z-coordinates instead.") return z_levels From 898dd09e14fbf2e6b31ce84a3e42e84ba4d25d0b Mon Sep 17 00:00:00 2001 From: Gabriele Girelli Date: Fri, 1 Nov 2019 10:13:59 +0100 Subject: [PATCH 3/4] Update raw_metadata.py Changed isinstance to is. Fixed condition triggering warning. --- nd2reader/raw_metadata.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nd2reader/raw_metadata.py b/nd2reader/raw_metadata.py index 72720f7..a37497a 100644 --- a/nd2reader/raw_metadata.py +++ b/nd2reader/raw_metadata.py @@ -164,11 +164,11 @@ class RawMetadata(object): z_levels = self._parse_dimension(r""".*?Z\((\d+)\).*?""") if 0 == len(z_levels): z_levels = parse_if_not_none(self.z_data, self._parse_z_coordinates) - if isinstance(z_levels, type(None)): + if z_levels is None: z_levels = [] else: z_levels = range(len(z_levels)) - if 0 != z_levels: + if 0 != len(z_levels): warnings.warn("Z-levels details missing in metadata. Using Z-coordinates instead.") return z_levels From 399b42e383d0fd7adf80c0c1a5245a8ad5eb49c7 Mon Sep 17 00:00:00 2001 From: Gabriele Girelli Date: Fri, 1 Nov 2019 11:40:40 +0100 Subject: [PATCH 4/4] Update raw_metadata.py --- nd2reader/raw_metadata.py | 1 - 1 file changed, 1 deletion(-) diff --git a/nd2reader/raw_metadata.py b/nd2reader/raw_metadata.py index a37497a..2b8f22c 100644 --- a/nd2reader/raw_metadata.py +++ b/nd2reader/raw_metadata.py @@ -168,7 +168,6 @@ class RawMetadata(object): z_levels = [] else: z_levels = range(len(z_levels)) - if 0 != len(z_levels): warnings.warn("Z-levels details missing in metadata. Using Z-coordinates instead.") return z_levels