Session¶
open_session_store ¶
Open a saved session folder or .session.zip as a read-only Session.
Folder sessions keep the existing layout and use
zarr.open_array(str(path / "<stream>.zarr"), mode="r"). Zip sessions use
a zarr.storage.ZipStore and read the same array paths inside the archive.
Source code in myogestic/_session_io.py
iter_labeled_windows ¶
iter_labeled_windows(paths: list[str] | list[Path], stream_name: str, win_seconds: float, hop_seconds: float, classes: set[int] | None = None) -> Iterator[tuple[ndarray, ndarray, int]]
Yield (window, ts, class_index) triples from labeled segments.
window is channels-first (n_channels, n_samples) — the
library's standard signal layout. ts is the matching 1-D
timestamp array. Walks each session's label track, finds the time
interval each label covers (this label's timestamp to next label's
timestamp), and chops that interval into fixed-size windows. Works
for folders and .session.zip sessions.
Source code in myogestic/_session_windows.py
iter_aligned_windows ¶
iter_aligned_windows(paths: list[str] | list[Path], primary_stream: str, aligned_streams: list[str], win_seconds: float, hop_seconds: float, align_window_samples: int = 1) -> Iterator[tuple[ndarray, dict[str, ndarray], ndarray]]
Yield (primary_window, aligned, ts) for regression training.
primary_window is channels-first (n_channels, n_samples).
For each primary window, find the nearest sample in every aligned
stream at the window midpoint and average align_window_samples
around that index.
Source code in myogestic/_session_windows.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
Session ¶
Session(base_path: str = 'sessions')
One recording session on disk: per-stream Zarr arrays + a label track.
Created when the user clicks Record, finalised when they click
Stop. While active, every acquisition thread that has its
stream registered appends to the session's Zarr stores; UI label
clicks emit :class:LabelEvent entries onto the label track.
Closing the session writes meta.json and labels.json
alongside the Zarr folders, and optionally packs the whole tree
into a portable .session.zip.
Layout on disk (one folder per recording, named with the start timestamp)::
sessions/2026-05-17_14-23-05/
emg.zarr/ # shape (n_samples, n_channels)
emg_timestamps.zarr/ # shape (n_samples,) float64
vhi_control.zarr/ # any additional stream
vhi_control_timestamps.zarr/
meta.json # streams_info, app_name, class_names
labels.json # the LabelEvent list
Read sessions back with :func:~myogestic.session.open_session_store,
which transparently handles both folders and .session.zip
archives.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_path
|
str
|
Parent directory; the session creates a
timestamp-named subdirectory inside. Default |
'sessions'
|
Source code in myogestic/_session_core.py
init_stream ¶
init_stream(name: str, info: StreamInfo) -> None
Called once per stream when recording starts.
Source code in myogestic/_session_core.py
append ¶
Called from acquire loop when recording. data: (n_samples, n_channels).
save_meta ¶
Write meta.json + labels.json to the session folder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_name
|
str
|
Identifier for the producing app. |
required |
class_names
|
list[str] | None
|
Optional human-readable names for label class indices. Persisting them makes old sessions self-describing: readers can render labels without an external lookup. |
None
|
Source code in myogestic/_session_core.py
pack_to_zip ¶
pack_to_zip() -> Path
Pack the session folder into a single <name>.session.zip file.
Uses ZIP_STORED (no compression). Zarr chunks are already compressed internally; an outer compression layer would add CPU for little gain.
Source code in myogestic/_session_core.py
get_trials ¶
get_trials(stream_name: str, pre: float = 0.0, post: float = 0.0, class_names: list[str] | None = None) -> list[Recording]
Extract discrete labeled windows for classification training.
Source code in myogestic/_session_core.py
get_continuous ¶
Return full stream data + timestamps for regression training.
LabelEvent
dataclass
¶
One entry in a session's label track: "at LSL time T, the user picked class N".
Recorded whenever the user clicks a class button in
:func:~myogestic.widgets.recording_controls. The label track is
a chronological list of these events; the recording-window
iterators (:func:~myogestic.session.iter_labeled_windows,
:func:~myogestic.session.iter_aligned_windows) walk the track to
decide which sample range gets which class index.
Attributes:
| Name | Type | Description |
|---|---|---|
timestamp |
float
|
LSL clock time (seconds) when the label was emitted.
Use |
class_index |
int
|
Index into the session's |