ex
tit.opt.ex ¶
TI Exhaustive Search Module.
ExConfig
dataclass
¶
ExConfig(subject_id: str, leadfield_hdf: str, roi_name: str, electrodes: BucketElectrodes | PoolElectrodes, total_current: float = 2.0, current_step: float = 0.5, channel_limit: float | None = None, roi_radius: float = 3.0, roi_names: list[str] | None = None, roi_atlas: list[AtlasROI] | None = None, roi_coordinate_space: Literal['subject', 'mni'] = 'subject', run_name: str | None = None)
Full configuration for exhaustive search optimization.
Exhaustive search evaluates every valid electrode combination from a user-defined pool or bucket set, sweeping current amplitudes at discrete steps.
Attributes¶
subject_id : str
Subject identifier matching the m2m directory name.
leadfield_hdf : str
Path to the precomputed leadfield HDF5 file.
roi_name : str
ROI CSV filename (e.g. "target.csv"). The ".csv" suffix
is appended automatically if missing. Used as the metric-key
prefix and (with the net name) the output-directory label.
roi_names : list of str or None
Optional list of ROI CSV filenames to union into a single
target. When provided (combined mode), the spherical masks of
every listed ROI are OR-folded into one region. None
(default) keeps single-ROI behavior driven by roi_name. An
explicit empty list means "no spherical centers at all" -- useful
for a purely atlas-driven ROI (roi_atlas only). Each entry gets
the ".csv" suffix appended if missing.
roi_atlas : list of AtlasROI or None
Volumetric atlas or mask ROI(s) to union with the spherical
centers from roi_name/roi_names. None (default) keeps
the existing spherical-only behavior.
roi_coordinate_space : str
Space of the roi_name/roi_names CSV centers -- "subject"
(default) or "mni". MNI centers are transformed to subject
space with simnibs.mni2subject_coords before the search runs.
Does not affect roi_atlas, which is always subject space.
electrodes : BucketElectrodes or PoolElectrodes
Electrode specification, either a single shared pool
(:class:PoolElectrodes) or separate per-channel buckets
(:class:BucketElectrodes). A plain dict is auto-converted
in __post_init__.
total_current : float
Total injected current in mA, split across channels.
current_step : float
Current amplitude step size in mA for the sweep.
channel_limit : float or None
Maximum current per channel in mA. None for no per-channel
limit.
roi_radius : float
Spherical ROI radius in mm for the target region.
run_name : str or None
Optional name for this run. Defaults to a datetime stamp.
Raises¶
ValueError
If current_step, total_current, or channel_limit are
non-positive, or if roi_coordinate_space is not "subject"
or "mni".
See Also¶
ExResult : Result container returned by :func:~tit.opt.ex.ex.run_ex_search.
tit.opt.ex.ex.run_ex_search : Consumes this config.
AtlasROI
dataclass
¶
Volumetric atlas or mask ROI, unioned with the spherical center(s).
Attributes¶
atlas_path : str
Path to a volumetric atlas or mask file -- NIfTI (.nii,
.nii.gz) or FreeSurfer (.mgz), e.g. one discovered by
:class:tit.atlas.voxel.VoxelAtlasManager.
label : int or None
Integer label to select within the atlas (elements are
included where the voxel value equals label). None
treats the whole file as a binary mask (voxel value > 0).
BucketElectrodes
dataclass
¶
Separate electrode lists for each bipolar channel position.
Attributes¶
e1_plus : list of str Candidate electrodes for channel 1 anode. e1_minus : list of str Candidate electrodes for channel 1 cathode. e2_plus : list of str Candidate electrodes for channel 2 anode. e2_minus : list of str Candidate electrodes for channel 2 cathode.
ExResult
dataclass
¶
ExResult(success: bool, output_dir: str, n_combinations: int, results_csv: str | None = None, config_json: str | None = None)
Result from an exhaustive search run.
Attributes¶
success : bool
True if the search completed without error.
output_dir : str
Absolute path to the output directory.
n_combinations : int
Total number of electrode/current combinations evaluated.
results_csv : str or None
Path to the CSV file containing ranked results. None if the
run failed before writing results.
config_json : str or None
Path to the saved configuration JSON. None if the run failed
before writing config.
See Also¶
ExConfig : Configuration consumed by :func:~tit.opt.ex.ex.run_ex_search.
tit.opt.ex.ex.run_ex_search : Returns this result.
ExSearchEngine ¶
ExSearchEngine(leadfield_hdf: str, roi_file: str | tuple[str, int] | list[str | tuple[str, int]], roi_name: str, logger: Logger)
Exhaustive TI electrode search engine.
Owns the full pipeline: leadfield loading, ROI resolution, simulation loop, and ROI CRUD.
Source code in tit/opt/ex/engine.py
initialize ¶
initialize(roi_radius: float = 3.0) -> None
Load leadfield, resolve the ROI (CSV/mask/atlas), find ROI + GM elements.
Source code in tit/opt/ex/engine.py
compute_ti_field ¶
compute_ti_field(e1_plus: str, e1_minus: str, current_ch1_mA: float, e2_plus: str, e2_minus: str, current_ch2_mA: float) -> dict[str, float]
Compute TI field for one montage and return ROI metrics.
Source code in tit/opt/ex/engine.py
run ¶
run(e1_plus: list[str], e1_minus: list[str], e2_plus: list[str], e2_minus: list[str], current_ratios: list[tuple[float, float]], all_combinations: bool, output_dir: str) -> dict[str, dict[str, float]]
Run the full simulation loop. Returns {mesh_key: metrics}.
Source code in tit/opt/ex/engine.py
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 | |
get_available_rois
staticmethod
¶
List ROI CSV files for a subject.
Source code in tit/opt/ex/engine.py
create_roi
staticmethod
¶
Create an ROI CSV from coordinates.
Source code in tit/opt/ex/engine.py
delete_roi
staticmethod
¶
Delete an ROI file and remove from roi_list.txt.
Source code in tit/opt/ex/engine.py
get_roi_coordinates
staticmethod
¶
Read ROI center coordinates from CSV.
Source code in tit/opt/ex/engine.py
run_ex_search ¶
Run exhaustive search from a typed config object.