validate.run#
Run an analysis on every patient in the cohort.
Segment tab: applyAutoSegToCohort runs the AI models in the settings and records their outputs. Model tab: applyModelToCohort derives the structures the dosimetric model needs (from the AI outputs or classic recipes), then computes NTCP. deriveStructuresForCohort only derives them.
Functions
|
Run the AI models in the settings (segment.ai_models) on every patient in the cohort. |
|
Apply a dosimetric model to every patient dataset in the cohort. |
|
Load one patient's data and derive the model's "derive" structures. |
|
Derive the structures set to "derive" in the settings for every patient, without computing NTCP (see deriveModelStructures). |
- validate.run.applyAutoSegToCohort(analysisDir, errorLog, progressCallback=None, stageCallback=None, overwrite=False, shouldStop=None, isAborted=None)[source]#
Run the AI models in the settings (segment.ai_models) on every patient in the cohort.
Each model’s outputs are written to <analysisDir>/<patientId>/ and recorded in task_log.yaml under the patient’s “segment” section: status, output files and labels. A model that already ran for a patient, with its output files still in place, is skipped unless overwrite=True. Structures are derived from the outputs later, by applyModelToCohort.
- Parameters:
analysisDir (str) – the analysis folder. Holds the settings file (analysis.FILE_NAME) used to build the DataCapsule, and receives logs, sessions and the AI outputs (<analysisDir>/<patientId>/).
errorLog (validate.logs.ErrorLog) – error log to write to.
progressCallback (callable) – optional f(done, total, patientId) hook, invoked once at the start (0, total, None), then after each patient is processed.
stageCallback (callable) – optional f(message) hook for the AI model’s stages.
overwrite (bool) – if True, re-run models that already ran.
shouldStop (callable) – optional f() -> bool, checked before each patient; True stops the run there.
isAborted (callable) – optional f() -> bool; True once the run was aborted (its AI model processes killed). The patient being run is recorded as aborted, and no further AI model is run.
- Returns:
dict – {patientId: {aiModel: “ok”|”ok (cached)”|”error: <message>”}}
- validate.run.applyModelToCohort(analysisDir, errorLog, progressCallback=None, shouldStop=None, isAborted=None)[source]#
Apply a dosimetric model to every patient dataset in the cohort.
For raw data, each patient’s structures are taken from the settings file: “existing” ones by their name in the data, “derive” ones made with their registered recipe (classic recipes first) from the outputs of the AI models Segment ran for that patient. Derived structures are exported to <analysisDir>/<patientId>/ for review, then NTCP is computed.
- Parameters:
analysisDir (str) – the analysis folder. Holds the settings file (analysis.FILE_NAME), which supplies the cohort directory, the dosimetric model, the structures and the CSV inputs.
errorLog (validate.logs.ErrorLog) – error log to write to.
progressCallback (callable) – optional f(done, total, patientId) hook, invoked once at the start (0, total, None), then after each patient is processed.
shouldStop (callable) – optional f() -> bool, checked before each patient; True stops the run there.
isAborted (callable) – optional f() -> bool; True once the run was aborted. A patient that fails after that is recorded as aborted.
- Returns:
pandas.DataFrame with columns – patient_id, ntcp, status, message. status is “ok” or “error”; message holds the exception text on error.
- validate.run.deriveStructuresForCohort(analysisDir, errorLog, progressCallback=None, shouldStop=None, isAborted=None)[source]#
Derive the structures set to “derive” in the settings for every patient, without computing NTCP (see deriveModelStructures).
Each patient’s exports and status are recorded in task_log.yaml under the patient’s “segment” section (logs.DERIVED_KEY).
- Parameters:
analysisDir (str) – the analysis folder holding the settings file (analysis.FILE_NAME).
errorLog (validate.logs.ErrorLog) – error log to write to.
progressCallback (callable) – optional f(done, total, patientId) hook, invoked once at the start (0, total, None), then after each patient is processed.
shouldStop (callable) – optional f() -> bool, checked before each patient; True stops the run there.
isAborted (callable) – optional f() -> bool; True once the run was aborted. A patient that fails after that is recorded as aborted.
- Returns:
pandas.DataFrame – One row per patient: patient_id, status (“ok” or “error”), message.
- Raises:
ValueError – the settings start from pre-computed predictors, or no structure is set to “derive”.
- validate.run.deriveModelStructures(record, patientInfo, recipes, deriveNames, analysisDir, taskLog, derivedFiles=None)[source]#
Load one patient’s data and derive the model’s “derive” structures.
Validate’s own outputs are dropped from the loaded data first. Structures are derived on the scan the dose is linked to (the first scan if there’s no dose), and each is exported to <analysisDir>/<patientId>/ (see _deriveStructures).
- Parameters:
record – the patient’s record (data_io.build_capsule.buildPatientRecord).
patientInfo (pandas.Series or None) – the patient’s plan CSV row.
recipes (dict) – {structName: settings entry} for the model’s structures.
deriveNames (list[str]) – structures to derive, in order (see _deriveOrder).
analysisDir (str) – the analysis folder.
taskLog (dict) – the task log (for the AI outputs Segment recorded).
derivedFiles (dict, optional) – filled with {structName: exported file, relative to analysisDir}.
- Returns:
tuple – (planC, doseNum), doseNum None if the patient has no dose.