No slash command · from TI-Toolbox
Python scripting API for TI-Toolbox (tit package) — SimulationConfig, FlexConfig, ExConfig, Analyzer, run_group_comparison, run_pipeline, tit.calc envelope functions, JSON config runners. Use when writing or debugging scripts/notebooks that drive TI-Toolbox, or converting a UI workflow to code.
Ships in TI-Toolbox. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Full page: MCP read_wiki_page("scripting") (or /wiki/notebooks/#example-workflow); the runnable tour
is tit/server/examples/example_workflow.ipynb (see read_wiki_page("notebooks")). This is the condensed version; verify
field names against read_source_file before emitting code — tit/sim/config.py,
tit/opt/config.py, tit/analyzer/analyzer.py, tit/stats/config.py, tit/pre/.
Everything runs inside the container (idossha/ti-toolbox: SimNIBS 4.6,
Python 3.11, NumPy 2.3.5 — Blender keeps its own NumPy 1.26.4; no FSL, no ANTs, no
X11, no FreeSurfer). Three ways in:
.ipynb
under <project>/code/ti-toolbox/notebooks/, executed by a Jupyter kernel the
server owns in the container. The kernelspec is the same environment every job
runs in, so from tit import get_path_manager works with nothing installed. A
seeded tour lives at code/ti-toolbox/notebooks/examples/example_workflow.ipynb.
At most 2 kernels, 30-minute idle timeout. There is no sandbox — a kernel
runs arbitrary code as the container's user.docker exec -it <container> bash, then
simnibs_python my_script.py. Use simnibs_python, never the host python.simnibs_python -m tit.<module> config.json.tit auto-initialises logging on import; the project root is discovered from the
mount (/mnt/<project>) or PROJECT_DIR.
./loader.sh --project ~/datasets/000 # Python-free: bash, curl and docker
python loader.py --project ~/datasets/000 # Python >= 3.11, runs tit/launch.py
tit launch --project ~/datasets/000 # the installed form (tit/cli.py)
tit launch --status | --logs [--follow] | --stop
Each opens the desktop app (downloaded and checksum-verified on first run), or the
browser UI with --browser; all read the one run spec (root docker-compose.yml).
Flags: --project --port --image --desktop --browser --no-open --existing --container --timeout --dev --print-config --interactive --stop --status --logs --follow. loader.sh needs no host Python; loader.py and tit launch need
CPython ≥ 3.11 and the docker CLI — not SimNIBS or Node. The server comes up at
http://127.0.0.1:8765; GET /api/health returns {"status": "ok"}.
from tit import get_path_manager
from tit.sim import SimulationConfig, Montage, MontageMode, run_simulation, load_montages
from tit.opt import (FlexConfig, run_flex_search,
ExConfig, run_ex_search,
MExConfig, run_m_ex_search)
from tit.analyzer import Analyzer, run_group_analysis, select_field_file
from tit.stats import run_group_comparison, GroupComparisonConfig, run_correlation
from tit.pre import run_pipeline
from tit.calc import envelope, envelope_max, envelope_mean, hf_peak, hf_power
tit.calc has five public functions. The three envelope functions take a
list of 2K arrays of shape (N, 3), paired positionally: each two
consecutive fields are the two channels of one beating pair (carriers f_k and
f_k + Δf, beating at the common Δf). The two carrier
functions take any number (>= 1) of fields, one per channel.
envelope(fields, direction) # (N,) envelope along direction ((3,) or (N, 3)) -> TI_normal
envelope_max(fields) # (N,) max over all directions -> TI_max / mTI_max
envelope_max(fields, perpendicular_to=normals) # (N,) max within the plane -> tangential TI
envelope_max(fields, return_direction=True) # (amp, unit direction): amp * dir is the TI vector
envelope_mean(fields) # (N,) mean over all directions -> TI_avg
hf_peak(fields) # (N,) peak carrier field max_s |sum s_c E_c|
hf_power(fields) # (N,) (1/2) sum |E_c|^2 = hf_rms^2, (V/m)^2
envelope_max([E1, E2]) # K = 1: exact closed form
envelope_max([E1, E2, E3, E4]) # K = 2 beating pairs, 4 channels (mTI)
coherent=True on hf_peak/hf_power is the carrier-only (ΔF = 0) control. A channel with no
beating partner gets a zero field as its partner in the envelope functions,
[E1, E2, Eu, np.zeros_like(Eu)] (it lowers the envelope), and one more field
in hf_peak/hf_power. hf_peak(coherent=True) is |sum E_c|, the phase-aligned
"peak HF"; the default is the worst case over channel signs. The on-disk field
hf_rms stores sqrt(hf_power) (V/m, RMS over time); hf_power_density stores
sigma * hf_power in W/m^3 with the solve's own conductivity (absorbed Joule power density,
not SAR).
Removed — do not emit these. Any tit.calc name other than the five above
(the older vector/average/direction functions, their psi argument, and the
separate carrier-fields module with its sum-of-squares function), get_nTI_vectors, get_mTI_vectors, get_mTI_dir,
get_magnitude_am, and the channels= carrier-regrouping parameter. There is no
montage.channels: wiring is positional — one field per channel, two channels per beating pair.
Channel count: an even number of channels (electrode pairs), at least two —
2 = TI, 4 or more (even) = mTI (tit.constants.is_valid_pair_count).
run_pipeline(subject_ids=["101"], convert_dicom=True, run_fastsurfer=True,
create_m2m=True)
montages = load_montages(montage_names=["L_Insula"], eeg_net="GSN-HydroCel-185.csv")
# or explicit:
Montage(name="Custom", mode=MontageMode.NET,
electrode_pairs=[("E010", "E011"), ("E012", "E013")],
eeg_net="GSN-HydroCel-185.csv")
cfg = SimulationConfig(
subject_id="101", montages=montages,
conductivity="scalar", # scalar | vn | dir | mc (vn/dir/mc need DTI)
intensities=[1.0, 1.0], # mA per channel
electrode_shape="ellipse", electrode_dimensions=[8.0, 8.0],
gel_thickness=1.0, rubber_thickness=2.0,
map_to_fsavg=True,
# output_fields=None (default) -> ["TI_max", "hf_peak", "hf_rms"]; add "TI_avg",
# "hf_power_density" by listing them. map_to_vol=True writes one NIfTI per field
# (map_to_mni=True, which needs it, adds MNI copies); both default False.
)
run_simulation(cfg)
# ΔF = 0 carrier-only control (two-channel TI; coherent sum, no envelope fields):
# SimulationConfig(..., carrier_only=True) # output_fields default -> ["hf_peak", "hf_rms"]
# (hf_power_density is a carrier field too and may be listed)
2 channels → TI, 4+ (even) → mTI, detected automatically. Outputs: the field mesh
Simulations/<name>/TI/mesh/<name>_TI.msh (every saved field) and its central surface
TI/mesh/surfaces/<name>_TI_central.msh (those fields + TI_normal, lh then rh);
TI/niftis/ only with map_to_vol (whole, grey_ and white_ NIfTIs per field). A field or NIfTI an analysis or group
tool needs and the run did not save is computed then from high_Frequency/mesh/ and saved
(tit.volume_fields; AnalysisResult.on_demand_note says what), except hf_power_density. TI_normal (via envelope along
the cortical normals) is on the central surface for TI and mTI runs and is mesh-only —
asking for it in voxel space is an error by design.
Free-hand montages come from m2m_<id>/stim_configs/*.json
({"name", "type": "U"|"M", "electrode_positions": {label: [x, y, z]}}, subject-RAS
millimetres); tit.sim.montage_sources.resolve_freehand_montage uses only the first
four coordinates, so an mTI free-hand config is not resolvable by it.
cfg = FlexConfig(
subject_id="101",
goal="mean", # mean | max | focality | focality_tf
postproc="max_TI", # max_TI | dir_TI_normal | dir_TI_tangential
current_mA=1.0, # per channel (+/-, 1:1 split)
electrode=FlexConfig.ElectrodeConfig(shape="ellipse", dimensions=[8, 8],
gel_thickness=1),
roi=FlexConfig.SphericalROI(x=-35, y=5, z=5, radius=10, use_mni=True),
n_multistart=3, min_electrode_distance=5.0)
res = run_flex_search(cfg)
res.success, res.best_value, res.output_folder, res.function_values
ROIs: SphericalROI(..., volumetric=, tissues=), AtlasROI(atlas_path, label, hemisphere), SubcorticalROI(atlas_path, label, tissues, atlas_space). Scalar
fields accept lists to union several regions. focality_tf = threshold-free
focality (mean_ROI^(1+w) / mean_nonROI). cpus does not parallelise the
search itself — only the multi-start restarts benefit.
cfg = ExConfig(
subject_id="101",
leadfield_hdf="101_leadfield_EEG10-20_Okamoto_2004.hdf5",
roi_name="L-Insula.csv",
electrodes=ExConfig.PoolElectrodes(
electrodes=["Fp1", "Fp2", "C3", "C4", "Cz", "Pz", "T7", "T8"]),
# or ExConfig.BucketElectrodes(e1_plus=[...], e1_minus=[...],
# e2_plus=[...], e2_minus=[...])
total_current=2.0, current_step=0.5, channel_limit=1.2)
run_ex_search(cfg)
roi_names=[...] unions spherical CSVs; roi_atlas=[ExConfig.AtlasROI(atlas_path, label, atlas_space="subject"|"mni")] adds volumetric regions (MNI masks are warped
to subject space);
roi_coordinate_space="subject"|"mni". MExConfig / run_m_ex_search is the
multipolar variant (no total_current / current_step / channel_limit).
The run name is the directory — a second run under the same run_name (or
output_folder for flex) overwrites the first in place. Put the ROI in the name
when more than one ROI is queued against one net.
a = Analyzer(subject_id="101", simulation="L_Insula", space="voxel") # voxel | mesh
r = a.analyze_sphere(center=(-35, 5, 5), radius=10,
coordinate_space="MNI", visualize=True)
r = a.analyze_cortex(atlas="DK40", region="superiorfrontal", visualize=True)
run_group_analysis(subject_ids=[...], simulation="L_Insula", space="voxel",
analysis_type="spherical", center=..., radius=...,
coordinate_space="MNI")
Units: focality_50/75/90/95_area is cm² in mesh space and cm³ in voxel
space — the _area names are kept for both deliberately, so scripts keep
working. Voxel values from v2.3.0–v2.5.0 are ten times too large; divide by 10 or
re-run. total_area_or_volume is mm² / mm³ and was always correct.
Carrier focality: a TI/mTI analysis also returns hf_peak_focality (hf_peak ROI /
GM mean), hf_rms_focality (the same on hf_rms), ti_selectivity
(roi_focality / hf_peak_focality) and hf_peak_focality_50..95_area, in V/m terms. They are
computed from the simulation's hf_peak / hf_rms, which are saved by default and
produced on demand otherwise; they are None only when a carrier has no usable values (or the
analysed field is a carrier field), and r.carrier_note says why.
subjects = GroupComparisonConfig.load_subjects("subjects.csv")
cfg = GroupComparisonConfig(
analysis_name="active_vs_sham", subjects=subjects,
test_type=GroupComparisonConfig.TestType.UNPAIRED,
alternative=GroupComparisonConfig.Alternative.TWO_SIDED,
cluster_stat=GroupComparisonConfig.ClusterStat.MASS,
n_permutations=1000,
tissue_type=GroupComparisonConfig.TissueType.GREY)
res = run_group_comparison(cfg)
Permutation p-values are p = (b + 1) / (m + 1), so the floor at 1000 permutations
is 1/1001 ≈ 1e-3, never 0. An old p = 0.0000 means p < 1/(m+1). All subjects'
NIfTIs must share a grid — a mismatched affine now raises ValueError naming the
subject rather than silently stacking different anatomy.
simnibs_python -m tit.source fsavg_config.json
tit.source.project_fields_to_fsaverage projects TI_max, TI_normal, hf_peak,
hf_rms onto fsaverage post hoc (spacings 5/6/7), writing
<sim>/fsaverage/sub-<id>_sim-<sim>_space-fsaverage<spacing>_fields.msh
(pm.sim_fsaverage_fields(sid, sim, spacing)): the fsaverage central surfaces, lh
nodes then rh, one node field per quantity, with a .msh.opt Gmsh view and a .json
provenance sidecar. It opens in the Viewer and Gmsh. Read values under simnibs_python
with tit.source.fsaverage.read_fsaverage_field(path, "TI_max") (or
mesh_io.read_msh(path).field["TI_max"].value). It is the only format surface stats
read; a simulation without it needs its projection re-run. It covers TI and mTI runs.
A surface stats run (space="fsaverage") writes surface_stats.msh in its output dir
(node fields t, p, sig_mask, cluster_id, r for correlation, and
mean_field or mean_responders/mean_non_responders; read them with
tit.source.fsaverage.read_fsaverage_fields(path)), surface_stats.json (settings,
subjects), and CSVs: significant_clusters.csv, null_distribution.csv,
cluster_subject_values.csv (subject × cluster mean field, long format).
simnibs_python -m tit.<sim|opt.flex|opt.ex|opt.mex|analyzer|stats|pre|source> config.json
Configs are serialised dataclasses (tit/config_io.py, _type discriminators).
The easiest way to get a valid JSON is to run the job once from the app and copy
code/ti-toolbox/jobs/<id>/spec.json — its config object is exactly this file.
That directory also holds status.json, events.jsonl and stdout.log for the run.
examples/scripts/preprocess.py, examples/scripts/simulator.py, examples/scripts/flex.py, examples/scripts/ex.py,
examples/scripts/analyzer.py, examples/scripts/leadfield.py, examples/scripts/pipeline.py,
examples/scripts/cluster_permutation.py, examples/scripts/blender.py — read them with
read_source_file("examples/scripts/<name>.py").
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub idossha/ti-toolbox --plugin ti-toolbox6 skills in this plugin
/ti-codebaseTI-Toolbox codebase patterns, module graph, conventions and architecture (v3 — Electron desktop app, FastAPI tit.server, shared tit science core). Use when reading or modifying source under tit/ or desktop/ (developers)./ti-domainTemporal interference neurostimulation domain knowledge. Use when working on simulation, optimization, analysis, or preprocessing code in TI-Toolbox./ti-run-pipelinesRun TI-Toolbox pipelines for the user through the app they have open — copy raw DICOM/NIfTI into the project's sourcedata, preprocess (charm head model), flex-search or ex-search optimisation, simulate a montage or an optimisation result, and follow the jobs. Use when the user asks you to DO something with their data in TI-Toolbox ("preprocess sub-101", "optimise for the thalamus", "simulate the best montage"), not to explain it. Needs the ti-toolbox-jobs MCP server./ti-toolboxOrientation for the Temporal Interference Toolbox (TI-Toolbox, Python package `tit`). Use whenever the user mentions TI-Toolbox, TI stimulation simulation/optimization, SimNIBS-based TI workflows, flex-search, ex-search, mTI, the v3 desktop app, or a BIDS project with derivatives/SimNIBS. Explains how the toolbox runs, where docs live, and which MCP tools to call./troubleshoot-projectDiagnose a TI-Toolbox project directory — which subjects, head models, simulations, optimizations, jobs and reports exist, and what is missing for the user's goal.Other plugins' skills for the same job