> Design or audit the data-preparation stage of a medical-imaging model — DICOM/NIfTI intake, resampling and intensity normalisation, and the augmentation plan — so the pipeline is leakage-safe before model-scaffold builds the training repo. Emits a declarative preprocessing manifest and a dataset-level normaliser fit on non-train data, any data-fitted transform run before the split, and the same patient's slices crossing splits. Integrates MONAI / TorchIO transforms; it does not reimplement them, and it never runs preprocessing on real patient data.
npx skills add https://github.com/Aperivue/medsci-skills --skill preprocess-imaging
This skill designs and audits the data-preparation stage of a medical-imaging model — the stage
*before* a training repo is built — and proves it is leakage-safe by construction. Data leakage
enters one step earlier than the split table can see: a normaliser fit on the whole dataset, a
data-fitted transform run before the split exists, or a patient whose slices land in more than one
partition. Each silently inflates every downstream metric (Kapoor & Narayanan, *Patterns* 2023;
Varoquaux & Cheplygina, *npj Digit Med* 2022; CLAIM 2024 data items).
It is the missing first link in the lane: preprocess-imaging (prepare + audit) →
/model-scaffold (build) → /model-validation (validate the split) → /model-evaluation +
/analyze-stats (metrics) → /write-paper + /check-reporting (publish). It integrates
MONAI / TorchIO transforms (referenced in the emitted plan); it does not reimplement them, and it
never executes preprocessing on real patient data.
leakage-safe preprocessing plan + a machine-checkable manifest before scaffolding a model.
/model-validation (split-leakage gate)./model-scaffold (it consumes this manifest)./architecture-zoo./model-evaluation then /analyze-stats.Collect: modality (CT / MR / X-ray / US / path), the data manifest (one row per image/slice with a
patient_id), the intended resample spacing, the intensity transform (fixed HU window vs a fitted
z-score / min-max / histogram match), and the augmentation plan. See
references/preprocessing_guide.md for modality-aware guidance
(what normalisation is standard per modality, which augmentations preserve vs break physiology).
distinction, so the fit spans partitions.
image's own statistics and is leakage-free even before the split.
into the reported metric.
Write a declarative JSON manifest that model-scaffold consumes and the gate checks:
{
"split_seed": 42,
"transforms": [
{"name": "hu_window", "type": "clip", "fit_scope": "none", "stage": "before_split"},
{"name": "train_zscore", "type": "standardize", "fit_scope": "train", "stage": "after_split"},
{"name": "flip_rotate", "type": "augmentation", "stage": "after_split", "applies_to": ["train"]}
],
"split_assignment": [
{"patient_id": "P001", "unit_id": "P001_s1", "split": "train"}
]
}
fit_scope: train (OK) · all/full/dataset/test (leak) · sample/per_image/none/fixed
(not data-fitted, leakage-free). stage: before_split / after_split.
Declare the fit scope of resampling too. A target spacing you chose in advance is fixed and
never leaks (fit_scope: fixed). A target *derived* from the cohort does: nnU-Net sets its target
spacing from a percentile of the dataset fingerprint, so a resample fitted over every case carries
held-out geometry into the training grid exactly as an intensity statistic would. Which one you
have is decided by the fingerprint's scope, not by the word "resample".
python3 scripts/check_preprocessing_leakage.py --manifest preprocessing_manifest.json --strict
That gate asks whether a transform was fit on the right scope. Before an *inference* run on a
cohort the model was not trained on, ask the other question — is that cohort in the intensity
domain the trained normaliser assumes?
python3 scripts/check_normalizer_domain.py \
--profile eda/<cohort>_profile.json \
--contract work/nnUNet_results/.../plans.json \
--splits external_mri --out qc/normalizer_domain.json --strict
Verdicts: PREPROCESS_BEFORE_SPLIT, NORMALIZATION_LEAKAGE, PATIENT_CROSS_SPLIT (Major);
AUGMENTATION_ON_EVAL, UNSPECIFIED_FIT_SCOPE, MISSING_SEED (Minor). The verdict is reproduced
by set arithmetic + rule on the manifest, never asserted from prose. A green gate is a precondition
for handing the manifest to /model-scaffold.
/model-scaffold — the audited manifest is the scaffold's preprocessing input; itssplit_assignment is the same patient-level split /model-validation later re-verifies.
/self-review model_development probe audits data-stage leakage in a finished manuscript;this skill *produces* the leakage-safe pipeline it looks for.
/check-reporting — the manifest documents the CLAIM 2024 / TRIPOD+AI data-preprocessing items.manifest comes from the real data manifest and the researcher's declared pipeline — never invented.
This skill designs and audits the plan; it does not run preprocessing on real patient data or
synthesise the images it describes.
check_preprocessing_leakage.py. Theleakage verdict is reproduced deterministically (rule + set arithmetic on the manifest), never
asserted from prose.
type / fit_scope / stage must describe what the code actually does; a mislabelled transform
hides a real leak the gate would otherwise catch.
normalisation/resampling implementation or claim results for one.
scripts/check_normalizer_domain_challenge/ ships a synthetic profile/contract triple: a cohort in
the contract's own domain that must come back clean (the false-positive guard), an arbitrary-unit
cohort that must raise a Major, and an unreadable contract that must refuse rather than pass.
scripts/check_preprocessing_leakage_challenge/ ships a synthetic leak/clean manifest pair with a
network-free verify.sh wired into the skill's validation commands.
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.
Access NCBI GEO for gene expression/genomics data. Search/download microarray and RNA-seq datasets (GSE, GSM, GPL), retrieve SOFT/Matrix files, for transcriptomics and expression analysis.
Bayesian modeling with PyMC. Build hierarchical models, MCMC (NUTS), variational inference, LOO/WAIC comparison, posterior checks, for probabilistic programming and inference.
Multi-objective optimization framework. NSGA-II, NSGA-III, MOEA/D, Pareto fronts, constraint handling, benchmarks (ZDT, DTLZ), for engineering design and optimization problems.
Statistical modeling toolkit. OLS, GLM, logistic, ARIMA, time series, hypothesis tests, diagnostics, AIC/BIC, for rigorous statistical inference and econometric analysis.
Add unsigned integer (uint) type support to PyTorch operators by updating AT_DISPATCH macros. Use when adding support for uint16, uint32, uint64 types to operators, kernels, or when user mentions enabling unsigned types, barebones unsigned types, or uint support.
Convert PyTorch AT_DISPATCH macros to AT_DISPATCH_V2 format in ATen C++ code. Use when porting AT_DISPATCH_ALL_TYPES_AND*, AT_DISPATCH_FLOATING_TYPES*, or other dispatch macros to the new v2 API. For ATen kernel files, CUDA kernels, and native operator implementations.
Write docstrings for PyTorch functions and methods following PyTorch conventions. Use when writing or updating docstrings in PyTorch code.
Take aperivue/preprocess-imaging from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.