From c37a691fbc28f776f309028c44e9af68077edc4f Mon Sep 17 00:00:00 2001 From: Henri Payno Date: Mon, 12 Sep 2022 09:07:58 +0200 Subject: [PATCH 1/2] fix _generic_path_getter: url can be None and entry provided (if configuration provided from a configuration file) --- nxtomomill/converter/hdf5/acquisition/baseacquisition.py | 4 ++-- .../converter/hdf5/acquisition/standardacquisition.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/nxtomomill/converter/hdf5/acquisition/baseacquisition.py b/nxtomomill/converter/hdf5/acquisition/baseacquisition.py index 9efd054..6db0177 100644 --- a/nxtomomill/converter/hdf5/acquisition/baseacquisition.py +++ b/nxtomomill/converter/hdf5/acquisition/baseacquisition.py @@ -468,8 +468,8 @@ class BaseAcquisition: def _get_electric_current(self, root_node) -> list: """retrieve electric current provide a time stamp for each of them""" - if self._root_url is None: - _logger.warning("no root url. Unable to read rotation motor") + if root_node is None: + _logger.warning("no root url. Unable to read electric current") return None, None else: grps = [ diff --git a/nxtomomill/converter/hdf5/acquisition/standardacquisition.py b/nxtomomill/converter/hdf5/acquisition/standardacquisition.py index bc01ccb..0dd64ed 100644 --- a/nxtomomill/converter/hdf5/acquisition/standardacquisition.py +++ b/nxtomomill/converter/hdf5/acquisition/standardacquisition.py @@ -509,7 +509,6 @@ class StandardAcquisition(BaseAcquisition): end_time = self._get_end_time(entry) if end_time is not None: end_time = datetime.fromisoformat(end_time) - if has_frames: self._register_frame_timestamp(entry, start_time, end_time) @@ -697,9 +696,8 @@ class StandardAcquisition(BaseAcquisition): :param H5group entry: user can provide directly an entry to be used as an open h5Group """ url = self.parent_root_url() or self.root_url - if url is None: - return None - self._check_has_metadata(url) + if url is not None: + self._check_has_metadata(url) def process(h5_group): if h5_group is not None and path in h5_group: @@ -708,6 +706,8 @@ class StandardAcquisition(BaseAcquisition): getattr(_logger, level)(message) if entry is None: + if url is None: + return None with EntryReader(url) as h5_group: return process(h5_group) else: -- GitLab From 808d7ee10fff8dca68da8de61c0fea2824037578 Mon Sep 17 00:00:00 2001 From: Henri Payno Date: Mon, 12 Sep 2022 10:56:39 +0200 Subject: [PATCH 2/2] `deduce_machine_electric_current`: speed up: skip call to `get_closest_timestamps` if the current time stamp is already in the latest found interval --- nxtomomill/converter/hdf5/acquisition/utils.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/nxtomomill/converter/hdf5/acquisition/utils.py b/nxtomomill/converter/hdf5/acquisition/utils.py index 055a15d..a9607f4 100644 --- a/nxtomomill/converter/hdf5/acquisition/utils.py +++ b/nxtomomill/converter/hdf5/acquisition/utils.py @@ -196,14 +196,24 @@ def deduce_machine_electric_current( ) res = [] + + ts1 = ts2 = None for timestamp in timestamps: if not isinstance(timestamp, numpy.datetime64): raise TypeError( f"elements of timestamps are expected to be instances of {numpy.datetime64} and not {type(timestamp)}" ) - (ts1, w1), (ts2, w2) = get_closest_timestamps(timestamp) + # if we can ts1 research + if ts1 is not None and ts2 is not None and ts1 < timestamp < ts2: + delta = ts2 - ts1 + w1 = 1 - (timestamp - ts1) / delta + w2 = 1 - (ts2 - timestamp) / delta + else: + (ts1, w1), (ts2, w2) = get_closest_timestamps(timestamp) ec1 = knowned_machine_electric_current.get(ts1) assert ec1 is not None ec2 = knowned_machine_electric_current.get(ts2, 0.0) - res.append(ec1 * w1 + ec2 * w2) + current_at_timestamp = ec1 * w1 + ec2 * w2 + res.append(current_at_timestamp) + return tuple(res) -- GitLab