6. Comparing Plans¶
Compare two longitudinal dose distributions with spatial views, tabulated dose changes, DVHs, contour overlap, and an image-space difference map.
In [1]:
Copied!
from dosemetrics.metrics import dose_comparison
from dosemetrics.utils import (
compare_dose_statistics,
compare_structure_geometry,
load_example_study,
plot_dose_difference,
plot_dose_slice,
plot_dvh_comparison,
)
reference, reference_structures = load_example_study("longitudinal/time_point_1")
evaluated, evaluated_structures = load_example_study("longitudinal/time_point_2")
selected = ["PTV", "Brainstem", "Chiasm", "OpticNerve_L"]
from dosemetrics.metrics import dose_comparison
from dosemetrics.utils import (
compare_dose_statistics,
compare_structure_geometry,
load_example_study,
plot_dose_difference,
plot_dose_slice,
plot_dvh_comparison,
)
reference, reference_structures = load_example_study("longitudinal/time_point_1")
evaluated, evaluated_structures = load_example_study("longitudinal/time_point_2")
selected = ["PTV", "Brainstem", "Chiasm", "OpticNerve_L"]
Inspect both plans¶
In [2]:
Copied!
for label, dose, structures in [
("Reference", reference, reference_structures),
("Evaluated", evaluated, evaluated_structures),
]:
fig, ax = plot_dose_slice(
dose,
structures=structures,
structure_names=["PTV", "Brainstem", "Chiasm"],
contour_colors={"PTV": "white", "Brainstem": "lime", "Chiasm": "cyan"},
cmap="turbo",
)
ax.set_title(label)
for label, dose, structures in [
("Reference", reference, reference_structures),
("Evaluated", evaluated, evaluated_structures),
]:
fig, ax = plot_dose_slice(
dose,
structures=structures,
structure_names=["PTV", "Brainstem", "Chiasm"],
contour_colors={"PTV": "white", "Brainstem": "lime", "Chiasm": "cyan"},
cmap="turbo",
)
ax.set_title(label)
Compare structure dose and DVHs¶
In [3]:
Copied!
compare_dose_statistics(
reference,
evaluated,
reference_structures,
evaluated_structures,
selected,
).round(2)
compare_dose_statistics(
reference,
evaluated,
reference_structures,
evaluated_structures,
selected,
).round(2)
Out[3]:
| Mean dose - Reference (Gy) | Mean dose - Evaluated (Gy) | Mean dose change (Gy) | D95 - Reference (Gy) | D95 - Evaluated (Gy) | D95 change (Gy) | D02 - Reference (Gy) | D02 - Evaluated (Gy) | D02 change (Gy) | |
|---|---|---|---|---|---|---|---|---|---|
| Structure | |||||||||
| PTV | 60.15 | 59.94 | -0.21 | 57.66 | 57.32 | -0.34 | 62.81 | 62.71 | -0.10 |
| Brainstem | 14.47 | 15.08 | 0.61 | 1.24 | 1.28 | 0.04 | 46.23 | 47.64 | 1.40 |
| Chiasm | 43.69 | 39.94 | -3.75 | 36.67 | 24.63 | -12.04 | 53.69 | 53.19 | -0.49 |
| OpticNerve_L | 40.71 | 41.90 | 1.20 | 25.09 | 23.43 | -1.67 | 58.29 | 51.66 | -6.63 |
In [4]:
Copied!
plot_dvh_comparison(
reference,
evaluated,
reference_structures["PTV"],
labels=("Reference", "Evaluated"),
evaluated_structure=evaluated_structures["PTV"],
);
plot_dvh_comparison(
reference,
evaluated,
reference_structures["PTV"],
labels=("Reference", "Evaluated"),
evaluated_structure=evaluated_structures["PTV"],
);
Compare contours and dose images¶
In [5]:
Copied!
compare_structure_geometry(
reference_structures, evaluated_structures, selected
).round(3)
compare_structure_geometry(
reference_structures, evaluated_structures, selected
).round(3)
Out[5]:
| Dice | Jaccard | Volume change (%) | |
|---|---|---|---|
| Structure | |||
| PTV | 0.823 | 0.699 | -13.941 |
| Brainstem | 0.801 | 0.669 | -1.967 |
| Chiasm | 0.012 | 0.006 | 5.063 |
| OpticNerve_L | 0.105 | 0.055 | 42.857 |
In [6]:
Copied!
mae = dose_comparison.compare_mae(reference, evaluated)
print(f"Whole-grid mean absolute error: {mae:.3f} Gy")
plot_dose_difference(
reference,
evaluated,
structures=reference_structures,
structure_names=["PTV"],
);
mae = dose_comparison.compare_mae(reference, evaluated)
print(f"Whole-grid mean absolute error: {mae:.3f} Gy")
plot_dose_difference(
reference,
evaluated,
structures=reference_structures,
structure_names=["PTV"],
);
Whole-grid mean absolute error: 1.220 Gy