Skip to content

Commit

Permalink
feat(andata): handle time index alignment shifts
Browse files Browse the repository at this point in the history
  • Loading branch information
ljgray committed Mar 17, 2023
1 parent d6a0666 commit b03a306
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions ch_util/andata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)):
Expand Down Expand Up @@ -831,6 +839,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():
Expand Down

0 comments on commit b03a306

Please sign in to comment.