Skip to content

Commit

Permalink
Update method for trimming unmatched sync events
Browse files Browse the repository at this point in the history
  • Loading branch information
jsiegle committed Aug 29, 2024
1 parent cde7831 commit d6ab682
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
14 changes: 5 additions & 9 deletions src/aind_ephys_rig_qc/generate_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ def generate_qc_report(
"""

output_stream = io.StringIO()
sys.stdout = output_stream

pdf = PdfReport("aind-ephys-rig-qc v" + package_version)
pdf.add_page()
pdf.set_font("Helvetica", "B", size=12)
Expand Down Expand Up @@ -323,12 +320,9 @@ def create_qc_plots(


if __name__ == "__main__":
output_stream = io.StringIO()
sys.stdout = output_stream
output_stream = io.StringIO()
sys.stdout = output_stream
output_stream = io.StringIO()
sys.stdout = output_stream



if len(sys.argv) != 3:
print("Two input arguments are required:")
print(" 1. A data directory")
Expand All @@ -348,6 +342,8 @@ def create_qc_plots(
if not os.path.exists(directory):
raise ValueError(f"Data directory {directory} does not exist.")

output_stream = io.StringIO()
sys.stdout = output_stream
output_content = output_stream.getvalue()

outfile = os.path.join(directory, "ephys-rig-QC_output.txt")
Expand Down
2 changes: 1 addition & 1 deletion src/aind_ephys_rig_qc/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"timestamp_alignment_method" : "harp",
"original_timestamp_filename" : "original_timestamps.npy",
"plot_drift_map" : false,
"flip_NIDAQ" : false
"flip_NIDAQ" : true
}
38 changes: 23 additions & 15 deletions src/aind_ephys_rig_qc/temporal_alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,13 @@ def align_timestamps( # noqa
events_for_stream[condition].index
)

# remove inconstant events between main and curr stream
# remove inconsistent events between streams

print(
f"Before removal: {len(events_for_stream)} "
+ f"local times, {len(main_stream_times)} "
+ "main times"
)

if len(main_stream_events) != len(events_for_stream):
print(
Expand All @@ -540,23 +546,26 @@ def align_timestamps( # noqa
)
first_main_event_ts = (
main_stream_events.sample_number.values[0]
- main_stream_start_sample
) / main_stream_sample_rate
print(first_main_event_ts)
first_curr_event_ts = (
events_for_stream.sample_number.values[0]
- sample_numbers[0]
) / sample_rate
print(first_curr_event_ts)
offset = np.abs(
first_main_event_ts - first_curr_event_ts
)
print(offset)
print(
"First event in main and current stream"
+ " are not aligned. Off by "
+ f"{offset:.2f} s"
)

if offset > 0.1:
# bigger than 0.1s so that
# it should not be the same event
print(
"First event in main and current stream"
+ " are not aligned. Off by "
+ f"{offset:.2f} s"
)

# remove first event from the stream
# with the most events
if len(main_stream_events) > len(
Expand All @@ -566,18 +575,15 @@ def align_timestamps( # noqa
"Removing first event in main stream"
)
main_stream_events = main_stream_events[1:]
main_stream_times = main_stream_times[1:]
else:
print(
"Removing first event in"
+ " current stream"
)
events_for_stream = events_for_stream[1:]
else:
print(
"First event in main and current stream"
" are aligned. Off by "
f"{offset:.2f} s"
)

# remove last event from the stream
# with the most events
if len(main_stream_events) > len(
Expand All @@ -587,6 +593,7 @@ def align_timestamps( # noqa
main_stream_events = main_stream_events[
:-1
]
main_stream_times = main_stream_times[:-1]
else:
print(
"Removing last event in current stream"
Expand All @@ -599,8 +606,9 @@ def align_timestamps( # noqa
)

print(
f"Total events for {stream_name}: "
+ f"{len(events_for_stream)}"
f"After removal: {len(events_for_stream)} "
+ f"local times, {len(main_stream_times)} "
+ "main times"
)

if pdf is not None:
Expand Down

0 comments on commit d6ab682

Please sign in to comment.