diff --git a/nxtomomill/converter/hdf5/acquisition/baseacquisition.py b/nxtomomill/converter/hdf5/acquisition/baseacquisition.py index 9efd0540c98e539bc4de6490b31939968444708a..6db0177574759476918e27c27858df89e6cabc7a 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 bc01ccbe668992b513920c15727da4dc39287ae8..0dd64ed687837f4f0f04fa75a524a8092570f1b3 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: diff --git a/nxtomomill/converter/hdf5/acquisition/utils.py b/nxtomomill/converter/hdf5/acquisition/utils.py index 055a15d3b184b670af0e49da53368bf1124ac174..a9607f41a2fec2c4fc5bb1e10704cde0317dece4 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)