API Reference¶
Session readers¶
Batch loading¶
murineshiftwork.readers.batch.load_session(session_dir, *, acquisition_name=None, acquisition_dir=None)
¶
Read one session directory and return a structured MswSession.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_dir
|
Path to the session directory (the innermost directory containing MSW artifact files). |
required | |
acquisition_name
|
str | None
|
Optional name of the parent acquisition container.
Set automatically by |
None
|
acquisition_dir
|
Path | None
|
Optional path to the parent acquisition container.
Set automatically by |
None
|
Returns:
| Type | Description |
|---|---|
MswSession
|
Populated |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no recognised MSW files are found in |
murineshiftwork.readers.batch.load_acquisition(acquisition_dir)
¶
Load all sessions inside a single acquisition container directory.
Reads acquisition_manifest.yaml if present; otherwise discovers
session directories by name pattern (__ separator). Sessions are
returned sorted by datetime_str.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
acquisition_dir
|
Path to the acquisition container (a directory whose children are individual session directories). |
required |
Returns:
| Type | Description |
|---|---|
list[MswSession]
|
List of |
list[MswSession]
|
that cannot be parsed are logged and skipped. |
murineshiftwork.readers.batch.load_subject(subject_dir)
¶
Load all sessions under a subject directory.
Walks one level of subdirectories. Direct session directories (containing
MSW artifact files) are loaded with load_session; subdirectories that
look like acquisition containers are loaded with load_acquisition.
Sessions are returned sorted by datetime_str.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subject_dir
|
Path to the subject root directory. |
required |
Returns:
| Type | Description |
|---|---|
list[MswSession]
|
List of |
list[MswSession]
|
chronologically. Unreadable directories are logged and skipped. |
Session model¶
murineshiftwork.readers.models.MswSession
¶
Bases: BaseModel
All data and metadata for one MSW session directory.
Attributes:
| Name | Type | Description |
|---|---|---|
session_dir |
Path
|
Absolute path to the session directory. |
basename |
str
|
Session basename ( |
subject |
str
|
Animal identifier extracted from the basename. |
datetime_str |
str
|
Raw datetime string extracted from the basename. |
task |
str
|
Task name extracted from the basename. |
namespace_version |
str | None
|
Namespace version string ( |
artifact_format |
str
|
One of |
msw_version |
str
|
MSW software version recorded in |
df |
DataFrame | None
|
Trial-by-trial DataFrame, or |
settings_task |
dict[str, Any] | None
|
Task settings dict ( |
settings_process |
dict[str, Any] | None
|
Process settings dict ( |
settings_stage |
dict[str, Any] | None
|
Stage / reward settings dict, if present. |
settings_ephys |
dict[str, Any] | None
|
Host-session / ephys linking block, if present. |
subprotocols |
list[dict] | None
|
List of subprotocol dicts from |
is_complete |
bool
|
|
is_ephys |
bool
|
|
session_type |
str
|
Task-type label from the session container name
( |
acquisition_name |
str | None
|
Name of the parent acquisition container, set by
|
acquisition_dir |
Path | None
|
Path to the parent acquisition container, set by
|
acq_type = ''
class-attribute
instance-attribute
¶
acquisition_dir = None
class-attribute
instance-attribute
¶
acquisition_name = None
class-attribute
instance-attribute
¶
artifact_format
instance-attribute
¶
basename
instance-attribute
¶
datetime_str
instance-attribute
¶
df = None
class-attribute
instance-attribute
¶
host_session_name
property
¶
Name of the host/ephys session container, or None if standalone.
is_complete
instance-attribute
¶
is_ephys
instance-attribute
¶
metadata = None
class-attribute
instance-attribute
¶
model_config = ConfigDict(arbitrary_types_allowed=True)
class-attribute
instance-attribute
¶
msw_version
instance-attribute
¶
namespace_version
instance-attribute
¶
session_dir
instance-attribute
¶
session_type = ''
class-attribute
instance-attribute
¶
settings_ephys = None
class-attribute
instance-attribute
¶
settings_process = None
class-attribute
instance-attribute
¶
settings_stage = None
class-attribute
instance-attribute
¶
settings_task = None
class-attribute
instance-attribute
¶
subject
instance-attribute
¶
subprotocols = None
class-attribute
instance-attribute
¶
task
instance-attribute
¶
to_dict()
¶
Validation¶
murineshiftwork.readers.validate.ValidationResult
dataclass
¶
info = field(default_factory=list)
class-attribute
instance-attribute
¶
issues = field(default_factory=list)
class-attribute
instance-attribute
¶
msw_version = 'unknown'
class-attribute
instance-attribute
¶
passed = True
class-attribute
instance-attribute
¶
session_dir
instance-attribute
¶
warnings = field(default_factory=list)
class-attribute
instance-attribute
¶
__init__(session_dir, msw_version='unknown', passed=True, issues=list(), warnings=list(), info=list())
¶
_fail(msg)
¶
_info(msg)
¶
_warn(msg)
¶
print_summary()
¶
murineshiftwork.readers.validate.validate_session(session_dir, verbose=True)
¶
Validate MSW file completeness for a session directory.
murineshiftwork.readers.container.validate_session_container(container, running_is_issue=False)
¶
Reconcile a container's on-disk acquisitions against its manifest.
Enumerates acquisitions, computes per-acquisition completeness, and reports
disk/manifest mismatches: acquisitions present on disk but unregistered
(e.g. an old manifest predating camera registration), and acquisitions
listed in the manifest but missing on disk (a dangling or aborted capture).
Manifest statuses other than a normal end (complete/stopped) go to
status_issues; running only when running_is_issue is set, since a
live session is legitimately running. Entries with location: remote live
on another host: they go to remote, not in_manifest_not_on_disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
container
|
str | Path
|
The session container directory. |
required |
running_is_issue
|
bool
|
Report entries still |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
SessionContainerReport
|
class: |
murineshiftwork.namespace.manifest.ACQUISITION_STATUSES = ('running', 'complete', 'stopped', 'aborted', 'interrupted', 'partial', 'failed')
module-attribute
¶
Status vocabulary of a session manifest acquisition entry.
running: written at start; still there after exit means the process died.complete: the task reached its own end (e.g. a trial limit).stopped: the operator ended the session (Ctrl-C); the normal end for tasks with no trial limit.aborted: the task raised and the session was ended on the error.interrupted: the process died; set when the next session on the same setup finds the stalerunningentry.partial: camera peers only; some cameras failed, the others recorded.failed: camera peers only; no camera recorded.
The writers do not enforce it (status stays a free string); validators do.
An entry with location: remote (plus e.g. host, path, backend,
set via extra) was recorded on another host and has no local directory.
Low-level reader¶
murineshiftwork.readers.session.read_session_data(session_dir=None)
¶
Read raw session data from a directory, dispatching on artifact format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_dir
|
Path to the session directory. |
None
|
Returns:
| Type | Description |
|---|---|
|
Dict with keys: |
|
|
|
|
|
recorded the barcode settings), |
|
|
|
|
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If no registered reader handles the detected artifact format. |
AssertionError
|
If |
Namespace utilities¶
murineshiftwork.namespace.paths.generate_session_paths(subject, task, basepath, acq_type='msw', acq_version=1, session_type=None, version=CURRENT_NAMESPACE_VERSION, default_subject='_test_subject', linked_to=None, datetime_str=None, printout=True)
¶
Generate a validated session path dictionary (v4 namespace).
Builds the session container (subject__datetime[__session_type]) and
acquisition basename (subject__datetime__acq_type[__vN]), then derives
all associated paths under basepath.
Tasks whose name starts with _test__ are redirected to
default_subject so test runs do not pollute real subject directories.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subject
|
str
|
Animal/subject identifier. Must not contain |
required |
task
|
str
|
Task name. Used for the |
required |
basepath
|
str | Path
|
Root data directory. |
required |
acq_type
|
str
|
Acquisition type identifier ( |
'msw'
|
acq_version
|
int | None
|
Integer format version appended as |
1
|
session_type
|
str | None
|
Optional task-type label appended to the session
container: |
None
|
version
|
str
|
Datetime precision format -- |
CURRENT_NAMESPACE_VERSION
|
default_subject
|
str
|
Subject name used when task starts with |
'_test_subject'
|
linked_to
|
str | None
|
Override the entire session container name verbatim. |
None
|
datetime_str
|
str | None
|
Re-use an existing datetime string instead of generating
a new one. Pass |
None
|
printout
|
bool
|
Print generated paths to stdout. |
True
|
Returns:
| Type | Description |
|---|---|
dict
|
Dict with keys: |
dict
|
|
dict
|
precision), |
dict
|
|
dict
|
|
murineshiftwork.namespace.paths.parse_session_basename(basename)
¶
Parse a session/acquisition basename into subject, datetime, task.
Compatibility shim over parse_acquisition_basename(). Returns the same keys as the original function: subject, datetime, datetime_str, task, namespace_version.
IO codec¶
murineshiftwork.io.save_trial_data(trial_data_list, filepath)
¶
Save a list of trial dicts to a JSONL file.
Replaces any existing file atomically: every trial is encoded first, then the file is
written to a temporary sibling and swapped in with os.replace, so a crash or an
unencodable trial never leaves a truncated file behind (the previous contents survive).
The first line is a version header; subsequent lines are one JSON object per trial.
Numpy arrays are converted to lists; tuples are encoded as {"__tuple__": [...]}
so they survive the round-trip through load_trial_data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trial_data_list
|
list
|
List of per-trial dicts as returned by the task. |
required |
filepath
|
str | Path
|
Destination path (parent directories are created if absent). |
required |
murineshiftwork.io.load_trial_data(filepath)
¶
Load trial dicts from a JSONL file written by save_trial_data.
Skips the version header line and restores {"__tuple__": [...]}
sentinels back to Python tuples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
Path to the |
required |
Returns:
| Type | Description |
|---|---|
list
|
List of per-trial dicts with tuples restored. |
Namespace migration¶
murineshiftwork.namespace.migrate.run(data_root, opts=None)
¶
Migrate (or, by default, dry-run) a data root and return the report.
Raises:
| Type | Description |
|---|---|
DataRootError
|
|
murineshiftwork.namespace.migrate.audit(data_root, subjects=None)
¶
Census the namespace tokens on disk (read-only) and flag anomalies.
Scans everything, test (_-prefixed) subjects included. Prints the
distinct acq_type / task / session_type / legacy session_ / version
tokens with counts, and warns on acq_types outside the closed enum and on
test/calibration tasks missing the leading _. Domain tokens are reported
but not flagged.
Returns:
| Type | Description |
|---|---|
int
|
|
dict
|
it can gate an |
Raises:
| Type | Description |
|---|---|
DataRootError
|
|