IO¶
Path classes and data loaders for VneuroTK.
Path Classes¶
Bases: VTKPath
Path class for ephys session-level data.
Follows the naming convention::
{root}/sessions/{session_id}/{dtype}_{session_id}[_probe{N}].{ext}
The fpath property points to a file under sessions/.
Auxiliary properties raw_dir and nwb_path expose the raw/
and nwb/ subdirectories for convenience.
VTKPath fields subject, task, run, desc, and suffix
are inherited but not used by fpath; use session_id and dtype
instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
Path
|
Root project directory (e.g. |
required |
session_id
|
str
|
Full session identifier, e.g. |
None
|
dtype
|
str
|
Data type. Must be one of :data: |
None
|
probe
|
int
|
Probe index (0-based). |
None
|
extension
|
str
|
File extension. Must be one of :data: |
None
|
Source code in src/vneurotk/io/path.py
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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
fpath
property
¶
Full path to the session-level analysis file.
Returns:
| Type | Description |
|---|---|
Path
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
nwb_path
property
¶
Path to the NWB intermediate file for this session.
Returns:
| Type | Description |
|---|---|
Path
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
raw_dir
property
¶
Raw data directory for this session.
Returns:
| Type | Description |
|---|---|
Path
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
session_dir
property
¶
Directory containing this session's analysis files.
Returns:
| Type | Description |
|---|---|
Path
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
__post_init__()
¶
Validate dtype and extension.
Source code in src/vneurotk/io/path.py
from_components(root, date, subject, paradigm, region, dtype=None, probe=None, extension='h5')
classmethod
¶
Build an EphysPath from individual session components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
str or Path
|
Root project directory. |
required |
date
|
str
|
Session date, e.g. |
required |
subject
|
str
|
Subject name, e.g. |
required |
paradigm
|
str
|
Paradigm string including optional block/run marker,
e.g. |
required |
region
|
str
|
Brain region, e.g. |
required |
dtype
|
str
|
Data type (see :data: |
None
|
probe
|
int
|
Probe index (0-based). |
None
|
extension
|
str
|
File extension. Default |
'h5'
|
Returns:
| Type | Description |
|---|---|
EphysPath
|
|
Source code in src/vneurotk/io/path.py
load(pre_load=False)
¶
Load this Ephys session into a :class:~vneurotk.neuro.base.BaseData.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pre_load
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
BaseData
|
|
Source code in src/vneurotk/io/path.py
Bases: VTKPath
Path class for MNE data.
Inherits all attributes from VTKPath. Sets modality to 'mne' by default. Constructs MNE-style file paths.
Source code in src/vneurotk/io/path.py
fpath
property
¶
Construct MNE-style file path.
Returns:
| Type | Description |
|---|---|
Path
|
Full file path in MNE format: root/sub-{subject}ses-{session}_task-{task}_run-{run}}.{extension |
load(pre_load=False)
¶
Load this MNE recording into a :class:~vneurotk.neuro.base.BaseData.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pre_load
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
BaseData
|
|
Source code in src/vneurotk/io/path.py
Base path class for VneuroTK data sources.
Attributes:
| Name | Type | Description |
|---|---|---|
root |
Path
|
Root directory for the data. |
session |
str | None
|
Session identifier. |
subject |
str | None
|
Subject identifier. |
task |
str | None
|
Task identifier. |
run |
str | None
|
Run identifier. |
desc |
str | None
|
Description identifier. |
probe |
int | None
|
Probe number (ephys only). |
suffix |
str | None
|
File suffix. |
extension |
str | None
|
File extension. |
modality |
str | None
|
Data modality (ephys, mne, bids). |
Source code in src/vneurotk/io/path.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 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 | |
fpath
property
¶
Construct full file path.
Returns:
| Type | Description |
|---|---|
Path
|
Full file path constructed from attributes. |
__post_init__()
¶
load(pre_load=False)
¶
Load data described by this path into a :class:BaseData.
For base :class:VTKPath instances pointing to a saved .h5 file,
loads via the internal HDF5 reader. Typed subclasses override this
method with format-specific loading logic.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If this path does not point to a |
Source code in src/vneurotk/io/path.py
Bases: VTKPath
Path class for BIDS data.
Inherits all attributes from VTKPath. Sets modality to 'bids' by default. Wraps mne_bids.BIDSPath internally.
Source code in src/vneurotk/io/path.py
bids_path
property
¶
Get underlying mne_bids.BIDSPath object.
Returns:
| Type | Description |
|---|---|
BIDSPath
|
The wrapped BIDS path object. |
fpath
property
¶
Get BIDS file path.
Returns:
| Type | Description |
|---|---|
Path
|
Full BIDS file path. |
__post_init__()
¶
Initialize BIDS path wrapper.
Source code in src/vneurotk/io/path.py
load(pre_load=False)
¶
Load this BIDS recording into a :class:~vneurotk.neuro.base.BaseData.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pre_load
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
BaseData
|
|
Source code in src/vneurotk/io/path.py
Reading Data¶
Read data from various sources into BaseData.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
VTKPath, EphysPath, MNEPath, BIDSPath, Path, or str
|
Data source. Plain |
required |
pre_load
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
BaseData
|
Data as BaseData object. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If loading AvgPsth (not yet implemented). |
ValueError
|
If path type is unknown or file format unsupported. |
FileNotFoundError
|
If the specified file does not exist. |
Source code in src/vneurotk/io/loader.py
Deferred loader for a neuro array — invokes loader_fn on first call.
Wraps any Callable[[], np.ndarray] and guarantees the underlying
function is executed at most once. The result is cached so subsequent
calls return the same array without re-reading from disk.
Satisfies the NeuroLoader = Callable[[], np.ndarray] contract, so it
can be passed directly to :meth:~vneurotk.neuro.base.BaseData.set_neuro_loader.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
loader_fn
|
Callable[[], ndarray]
|
Zero-argument function that reads and returns the neuro array. |
required |
Examples:
>>> loader = LazyNeuroLoader(lambda: np.load("data.npy"))
>>> bd.set_neuro_loader(loader) # called at most once on first bd.neuro access
Source code in src/vneurotk/io/loader.py
is_loaded
property
¶
True after the first call has materialised the array.
Bases: Mapping
HDF5-backed read-only image dict that loads arrays on demand.
The key index is built on first access (one lightweight pass over
attribute metadata only). Each __getitem__ call opens the file,
reads a single dataset, and closes it immediately.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path or str
|
Path to the HDF5 file. |
required |
group
|
str
|
HDF5 group name that contains the image datasets.
Default |
'stimuli_db'
|