Skip to content

Commit

Permalink
Merge pull request #3 from AllenNeuralDynamics/no_harp_warning
Browse files Browse the repository at this point in the history
Added no harp line warning as red title on the plot
  • Loading branch information
ZhixiaoSu authored Aug 1, 2024
2 parents 432af8b + 11510e4 commit cde7831
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 13 deletions.
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ dependencies = [
'fpdf2',
'scipy',
'rich',
'spikeinterface[full]',
'harp-python @ git+https://github.com/jsiegle/harp-python@decode-clock'
'spikeinterface[full]==0.100.7',
'harp-python @ git+https://github.com/jsiegle/harp-python@decode-clock',
'numpy==1.26.4'
]

[project.optional-dependencies]
Expand Down
28 changes: 24 additions & 4 deletions src/aind_ephys_rig_qc/generate_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ def generate_qc_report(
# optionally align to Harp timestamps
print("Aligning timestamps to Harp clock...")
align_timestamps_harp(
directory, pdf=pdf,
directory,
pdf=pdf,
)

print("Creating QC plots...")
Expand Down Expand Up @@ -275,7 +276,8 @@ def create_qc_plots(
pdf.write(h=10, text=f"Duration: {duration} s")
pdf.set_y(65)
pdf.write(
h=10, text=f"Sample Rate: " f"{sample_rate} Hz",
h=10,
text=f"Sample Rate: " f"{sample_rate} Hz",
)
pdf.set_y(70)
pdf.write(h=10, text=f"Channels: {stream.samples.shape[1]}")
Expand Down Expand Up @@ -321,14 +323,22 @@ 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")
print(" 2. A JSON parameters file")
else:
with open(sys.argv[2], "r",) as f:
with open(
sys.argv[2],
"r",
) as f:
parameters = json.load(f)

directory = sys.argv[1]

print("Running generate_report.py with parameters:")
Expand All @@ -338,4 +348,14 @@ def create_qc_plots(
if not os.path.exists(directory):
raise ValueError(f"Data directory {directory} does not exist.")

output_content = output_stream.getvalue()

outfile = os.path.join(directory, "ephys-rig-QC_output.txt")

with open(outfile, "a") as output_file:
output_file.write(
datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "\n"
)
output_file.write(output_content)

generate_qc_report(directory, **parameters)
10 changes: 8 additions & 2 deletions src/aind_ephys_rig_qc/qc_figures.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ def plot_raw_data(


def plot_power_spectrum(
data, start_frames, stream_name, sample_rate, chunk_size=10000,
data,
start_frames,
stream_name,
sample_rate,
chunk_size=10000,
):
"""
Plot the power spectrum of the data
Expand Down Expand Up @@ -250,7 +254,9 @@ def plot_drift(directory, stream_name, block_index=0):
ylim = [np.min(y_locs), np.max(y_locs)]

fig = Figure(figsize=visualization_drift_params["figsize"])
axs_drift = fig.subplots(ncols=recording.get_num_segments(),)
axs_drift = fig.subplots(
ncols=recording.get_num_segments(),
)
# for testing purposes
if recording.get_total_duration() < 3:
visualization_drift_params["n_skip"] = 1
Expand Down
13 changes: 8 additions & 5 deletions src/aind_ephys_rig_qc/temporal_alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,10 @@ def search_harp_line(recording, directory, pdf=None):
# pick the line with even distribution overtime
# and has short inter-event interval
candidate_lines = lines_to_scan[(p_short > 0.5) & (p_value > 0.95)]
plt.suptitle(f"Harp line(s) {candidate_lines}")
if len(candidate_lines) > 0:
plt.suptitle(f"Harp line(s) {candidate_lines}")
else:
plt.suptitle("Harp line not detected!", color="red")

if pdf is not None:
pdf.add_page()
Expand Down Expand Up @@ -312,10 +315,10 @@ def align_timestamps( # noqa
print("Processing stream: ", main_stream_name)
main_stream_source_node_id = main_stream.metadata["source_node_id"]
main_stream_sample_rate = main_stream.metadata["sample_rate"]
if 'PXIe' in main_stream_name and flip_NIDAQ:
if "PXIe" in main_stream_name and flip_NIDAQ:
# flip the NIDAQ stream if sync line is inverted between NIDAQ
# and main stream
print('Flipping NIDAQ stream as main stream...')
print("Flipping NIDAQ stream as main stream...")
main_stream_events = events[
(events.stream_name == main_stream_name)
& (events.processor_id == main_stream_source_node_id)
Expand Down Expand Up @@ -467,8 +470,8 @@ def align_timestamps( # noqa
print("Processing stream: ", stream_name)
source_node_id = stream.metadata["source_node_id"]
sample_rate = stream.metadata["sample_rate"]
if 'PXIe' in stream_name and flip_NIDAQ:
print('Flipping NIDAQ stream...')
if "PXIe" in stream_name and flip_NIDAQ:
print("Flipping NIDAQ stream...")
# flip the NIDAQ stream if sync line is inverted
# between NIDAQ and main stream
events_for_stream = events[
Expand Down

0 comments on commit cde7831

Please sign in to comment.