From 2c15a3ecbea9a1dd78ebbc01ee48b49162fcd170 Mon Sep 17 00:00:00 2001 From: ljgray Date: Fri, 24 Feb 2023 17:30:16 -0800 Subject: [PATCH] feat(andata): handle time index alignment shifts --- ch_util/andata.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/ch_util/andata.py b/ch_util/andata.py index 4f518c83..8765ed1d 100644 --- a/ch_util/andata.py +++ b/ch_util/andata.py @@ -215,17 +215,21 @@ def time(self): if ( self.index_map["time"].dtype == np.float32 - # Already a calculated timestamp. or self.index_map["time"].dtype == np.float64 ): + # Already a calculated timestamp. return self.index_map["time"][:] else: time = _timestamp_from_fpga_cpu( self.index_map["time"]["ctime"], 0, self.index_map["time"]["fpga_count"] ) - # Shift from lower edge to centres. - time += abs(np.median(np.diff(time)) / 2) + + alignment = self.index_attrs["time"].get("alignment", 0) + + if alignment != 0: + time = time + alignment * abs(np.median(np.diff(time)) / 2) + return time @classmethod @@ -302,6 +306,10 @@ def from_acq_h5( **kwargs ) + # Set an attribute on the time axis specifying alignment + if "time" in data.index_map: + data.index_attrs["time"]["alignment"] = 1 + finally: # Close any files opened in this function. for ii in range(len(acq_files)): @@ -840,6 +848,7 @@ def _from_acq_h5_distributed( # Create index map data.create_index_map(name, index_map) + memh5.copyattrs(local_data.index_attrs[name], data.index_attrs[name]) # Copy over reverse maps for name, reverse_map in local_data.reverse_map.items():