Skip to content

Commit

Permalink
Fix validation of single rising + falling edge pair for stim_running …
Browse files Browse the repository at this point in the history
…signal
  • Loading branch information
bjhardcastle committed Feb 8, 2024
1 parent 8ba7f13 commit 9005ad7
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/npc_sync/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def validate(
camstim: bool = True,
mvr: bool = True,
barcodes: bool = True,
licks: bool = True,
licks: bool = False,
opto: bool = False,
audio: bool = False,
) -> None:
Expand Down Expand Up @@ -212,10 +212,7 @@ def validate(

def _check_line(self, label_or_index: str | int) -> None:
"""Verify line is present and has events, or raise AssertionError."""
try:
stats = self.line_stats(label_or_index)
except IndexError:
raise AssertionError(f"Sync file has no line {label_or_index}")
stats = self.line_stats(label_or_index)
if stats is None:
raise AssertionError(f"Sync file has no events on line {label_or_index}")

Expand Down Expand Up @@ -660,15 +657,18 @@ def line_stats(self, line, print_results=True) -> dict[str, Any] | None:
logger.info("*" * 70)
return None
# period
period = self.period(line)
try:
period = self.period(line)
except IndexError: # not enough edges
period = {}

avg_period = period["avg"]
max_period = period["max"]
min_period = period["min"]
period_sd = period["sd"]
avg_period = period.get("avg")
max_period = period.get("max")
min_period = period.get("min")
period_sd = period.get("sd")

# freq
avg_freq = self.frequency(line)
avg_freq = self.frequency(line) if period else None

# duty cycle
duty_cycle = self.duty_cycle(line)
Expand Down Expand Up @@ -749,7 +749,6 @@ def frequency(
"""
Returns the average frequency of a line.
"""

period = self.period(line, edge)
return 1.0 / period["avg"]

Expand Down

0 comments on commit 9005ad7

Please sign in to comment.