From 96695d50ab5791e1f95dd18d4bc6f3f1b92a1ee4 Mon Sep 17 00:00:00 2001 From: Gabriele Girelli Date: Wed, 30 Oct 2019 12:29:03 +0100 Subject: [PATCH] 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.