Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timestamp Alignment(3/4): Modify time axis alignment attribute when reading acq data #52

Merged
merged 1 commit into from
Apr 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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():
Expand Down