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, 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.
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.
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.
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 ¶
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, parse ROI CSV, find ROI + GM elements.
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
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 | |
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.