Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
34 changes: 32 additions & 2 deletions spikewrap/structure/_raw_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,50 @@ def raw_is_loaded(self) -> bool:
# Sync Channel
# ---------------------------------------------------------------------------

def plot_sync_channel(self, show: bool) -> list[matplotlib.lines.Line2D]:
def plot_sync_channel(
self,
time_range: tuple[float, float] | None = None,
use_seconds: bool = False,
show: bool = True,
) -> list[matplotlib.lines.Line2D]:
Comment thread
Thashira marked this conversation as resolved.
"""
TODO
----
- move this into _visualise
- make it cleaner / look nicer.
"""

traces = self.get_sync_channel()

plot = plt.plot(traces)
rec = self._raw[canon.grouped_shankname()]
fs = float(rec.get_sampling_frequency())

if time_range is not None:
start_frame = int(time_range[0] * fs) if use_seconds else int(time_range[0])
end_frame = int(time_range[1] * fs) if use_seconds else int(time_range[1])

end_frame = min(end_frame, len(traces))
plot_data = traces[start_frame:end_frame]
time_axis = np.linspace(
time_range[0], time_range[0] + len(plot_data) / fs, len(plot_data)
)
else:
plot_data = traces
time_axis = np.linspace(0, len(traces) / fs, len(traces))

fig, ax = plt.subplots(figsize=(12, 4))
plot = ax.plot(time_axis, plot_data, color="crimson", linewidth=1.5)

ax.set_title(f"Sync Channel: {self._run_name}", fontsize=12, fontweight="bold")
ax.set_xlabel("Time (s)", fontsize=10)
Comment thread
Thashira marked this conversation as resolved.
ax.set_ylabel("Voltage / Logic Level", fontsize=10)
ax.grid(True, alpha=0.3)

if show:
plt.show()

plot = plt.plot(traces)

Comment thread
Thashira marked this conversation as resolved.
Outdated
return plot

def get_sync_channel(self) -> np.ndarray:
Expand Down
10 changes: 8 additions & 2 deletions spikewrap/structure/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,11 @@ def get_sync_channel(self, run_idx: int):
return self._raw_runs[run_idx].get_sync_channel()

def plot_sync_channel(
self, run_idx: int, show: bool = True
self,
run_idx: int,
time_range: tuple[float, float] | None = (0, 10),
Comment thread
Thashira marked this conversation as resolved.
use_seconds: bool = False,
show: bool = True,
) -> list[matplotlib.lines.Line2D]:
Comment thread
Thashira marked this conversation as resolved.
"""
Plot the sync channel for the run.
Expand All @@ -643,7 +647,9 @@ def plot_sync_channel(
"""
Comment thread
Thashira marked this conversation as resolved.
self._assert_sync_channel_checks()

return self._raw_runs[run_idx].plot_sync_channel(show)
return self._raw_runs[run_idx].plot_sync_channel(
time_range=time_range, use_seconds=use_seconds, show=show
)

def silence_sync_channel(
self, run_idx: int, periods_to_silence: list[tuple]
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ python =
extras =
dev
commands =
pytest -v --color=yes --cov=swc_epys --cov-report=xml
pytest -v --color=yes --cov=spikewrap --cov-report=xml
Loading