leadfield
tit.opt.leadfield ¶
Leadfield matrix generator for TI optimization.
Integrates with SimNIBS to create leadfield matrices via TDCSLEADFIELD.
Public API¶
LeadfieldGenerator Object-oriented interface for generation and listing.
ensure_leadfield(subject_id, eeg_net, *, project_dir, tissues, force) -> Path Return an existing leadfield path or generate a new one.
LeadfieldGenerator ¶
LeadfieldGenerator(subject_id: str, electrode_cap: str = 'EEG10-10', progress_callback: Callable | None = None, termination_flag: Callable[[], bool] | None = None)
Generate and list leadfield matrices for TI optimization.
Initialize leadfield generator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subject_id
|
str
|
Subject identifier (e.g. "101"). |
required |
electrode_cap
|
str
|
EEG cap name without .csv (e.g. "GSN-HydroCel-185"). |
'EEG10-10'
|
progress_callback
|
Callable | None
|
Optional callback(message, level) for GUI updates. |
None
|
termination_flag
|
Callable[[], bool] | None
|
Optional callable returning True when cancelled. |
None
|
Source code in tit/opt/leadfield.py
generate ¶
generate(output_dir: str | Path | None = None, tissues: list[int] | None = None, cleanup: bool = True) -> Path
Generate a leadfield matrix via SimNIBS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_dir
|
str | Path | None
|
Output directory (default: pm.leadfields(subject_id)). |
None
|
tissues
|
list[int] | None
|
Tissue tags [1=WM, 2=GM]. Default: [1, 2]. |
None
|
cleanup
|
bool
|
Remove stale SimNIBS artefacts before running. |
True
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the generated HDF5 leadfield file. |
Raises:
| Type | Description |
|---|---|
InterruptedError
|
If cancelled via termination_flag. |
Source code in tit/opt/leadfield.py
list_leadfields ¶
List available leadfield HDF5 files for a subject.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subject_id
|
str | None
|
Subject ID (defaults to self.subject_id). |
None
|
Returns:
| Type | Description |
|---|---|
list[tuple[str, str, float]]
|
Sorted list of (net_name, hdf5_path, size_gb) tuples. |
Source code in tit/opt/leadfield.py
get_electrode_names ¶
Extract electrode labels from an EEG cap via SimNIBS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cap_name
|
str | None
|
EEG cap name (without .csv). Defaults to self.electrode_cap. |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
Sorted list of electrode label strings. |