#******************************************************************************* # Title: getBrainDvhStats.py # Author: John Eley # Date: 12 Jan 2015 # # Purpose: Extract brain DVH stats from current plan # print to text file # # Notes: This should be run immediately after making the sum plan, since this will # use the most recently added "Evaluation Dose" # Expects image/structure set to be named 'CT 1' #******************************************************************************* # # USER INPUT # pcTargetName = 'CTV' pcBrainName = 'autoBrainMinusGTV' pcExternalName = 'External' pcBrainstemName = 'Brainstem' #pcAvoidName = 'eleyOptic' dRxDose = 78 # Gy, this is needed to compute V95 correctly, maybe later I can read this from the plan #pcFileOut = 'J:/raystationScripts/brainDvhStatsOut/testingOutput.txt' # Give unique name for output # # END USER INPUT # # Load necessary objects into memory and import libraries from connect import * import math import string import json import time patient = get_current("Patient") # I think this loads the patient object and all associated functions, this autopopulates when I make the scripts using the record function plan = get_current("Plan") beam_set = get_current("BeamSet") # Ditto # Find the last-computed evaluation dose index (they are all slapped in the same pile, so find the highest index) pcTempDoseEvaluationIndices = patient.TreatmentDelivery.FractionEvaluations[0].DoseOnExaminations[0].DoseEvaluations._ # This grabs a string containing the dose exam indices, but requires some manipulation to actually count the exams pcDoseEvaluationIndices = pcTempDoseEvaluationIndices.translate(None, '_') # remove underscores from string piDoseEvaluationIndices = json.loads('[' + pcDoseEvaluationIndices + ']') # this line relies on the function json.loads that converts strings into lists/arrays of integers iLastDose = len(piDoseEvaluationIndices) - 1 # grab the highest index # # Get statistics # #dMinTargetDose = patient \ # .TreatmentDelivery.FractionEvaluations[0] \ # .DoseOnExaminations[0].DoseEvaluations[iLastDose] \ # .GetDoseStatistic(RoiName='CTV tumor new', DoseType='Min') / 100 # Gy dMinTargetDose = patient \ .TreatmentDelivery.FractionEvaluations[0] \ .DoseOnExaminations[0].DoseEvaluations[iLastDose] \ .GetDoseAtRelativeVolumes(RoiName=pcTargetName, RelativeVolumes=[0.99]) dMinTargetDose = dMinTargetDose[0] / 100 # Gy dMeanTargetDose = patient \ .TreatmentDelivery.FractionEvaluations[0] \ .DoseOnExaminations[0].DoseEvaluations[iLastDose] \ .GetDoseStatistic(RoiName=pcTargetName, DoseType='Average') / 100 # Gy dMaxTargetDose = patient \ .TreatmentDelivery.FractionEvaluations[0] \ .DoseOnExaminations[0].DoseEvaluations[iLastDose] \ .GetDoseAtRelativeVolumes(RoiName=pcTargetName, RelativeVolumes=[0.01]) # Gy dMaxTargetDose = dMaxTargetDose[0] / 100 # Gy dV95Target = patient \ .TreatmentDelivery.FractionEvaluations[0] \ .DoseOnExaminations[0].DoseEvaluations[iLastDose] \ .GetRelativeVolumeAtDoseValues(RoiName=pcTargetName, DoseValues=[0.95 * dRxDose * 100]) # GetRelativeVolumeAtDoseValues expects cGy input dV95Target = dV95Target[0] * 100 dMeanBrainDose = patient \ .TreatmentDelivery.FractionEvaluations[0] \ .DoseOnExaminations[0].DoseEvaluations[iLastDose] \ .GetDoseStatistic(RoiName=pcBrainName, DoseType='Average') / 100 # Gy dMaxBrainDose = patient \ .TreatmentDelivery.FractionEvaluations[0] \ .DoseOnExaminations[0].DoseEvaluations[iLastDose] \ .GetDoseAtRelativeVolumes(RoiName=pcBrainName, RelativeVolumes=[0.01]) dMaxBrainDose = dMaxBrainDose[0] / 100 # Gy dBrainVolume = patient.PatientModel.StructureSets['CT 1'].RoiGeometries[pcBrainName].GetRoiVolume() # cm3 #dV12GyBrain = patient \ # .TreatmentDelivery.FractionEvaluations[0] \ # .DoseOnExaminations[0].DoseEvaluations[iLastDose] \ # .GetRelativeVolumeAtDoseValues(RoiName=pcBrainName, DoseValues=[1200]) #dV12GyBrain = dV12GyBrain[0] * dBrainVolume # cm3 #dV40GyBrain = patient \ # .TreatmentDelivery.FractionEvaluations[0] \ # .DoseOnExaminations[0].DoseEvaluations[iLastDose] \ # .GetRelativeVolumeAtDoseValues(RoiName=pcBrainName, DoseValues=[4000]) #dV40GyBrain = dV40GyBrain[0] * dBrainVolume # cm3 dV60GyBrain = patient \ .TreatmentDelivery.FractionEvaluations[0] \ .DoseOnExaminations[0].DoseEvaluations[iLastDose] \ .GetRelativeVolumeAtDoseValues(RoiName=pcBrainName, DoseValues=[6000]) dV60GyBrain = dV60GyBrain[0] * dBrainVolume # cm3 #dV72GyBrain = patient \ # .TreatmentDelivery.FractionEvaluations[0] \ # .DoseOnExaminations[0].DoseEvaluations[iLastDose] \ # .GetRelativeVolumeAtDoseValues(RoiName=pcBrainName, DoseValues=[7200]) #dV72GyBrain = dV72GyBrain[0] * dBrainVolume # cm3 dV95External = patient \ .TreatmentDelivery.FractionEvaluations[0] \ .DoseOnExaminations[0].DoseEvaluations[iLastDose] \ .GetRelativeVolumeAtDoseValues(RoiName=pcExternalName, DoseValues=[0.95 * dRxDose * 100]) # GetRelativeVolumeAtDoseValues expects cGy input dV95External = dV95External[0] * 100 #dV90External = patient \ # .TreatmentDelivery.FractionEvaluations[0] \ # .DoseOnExaminations[0].DoseEvaluations[iLastDose] \ # .GetRelativeVolumeAtDoseValues(RoiName=pcExternalName, DoseValues=[0.90 * dRxDose * 100]) # GetRelativeVolumeAtDoseValues expects cGy input #dV90External = dV90External[0] * 100 dTargetVolume = patient.PatientModel.StructureSets['CT 1'].RoiGeometries[pcTargetName].GetRoiVolume() # cm3 dExternalVolume = patient.PatientModel.StructureSets['CT 1'].RoiGeometries[pcExternalName].GetRoiVolume() # cm3 dCI95 = (dV95External / 100) * dExternalVolume / dTargetVolume # Conformity index for 95% isodose #dCI90 = (dV90External / 100) * dExternalVolume / dTargetVolume # Conformity index for 90% isodose #dMeanAvoidDose = patient \ # .TreatmentDelivery.FractionEvaluations[0] \ # .DoseOnExaminations[0].DoseEvaluations[iLastDose] \ # .GetDoseStatistic(RoiName=pcAvoidName, DoseType='Average') / 100 # Gy #dMaxAvoidDose = patient \ # .TreatmentDelivery.FractionEvaluations[0] \ # .DoseOnExaminations[0].DoseEvaluations[iLastDose] \ # .GetDoseAtRelativeVolumes(RoiName=pcAvoidName, RelativeVolumes=[0.01]) #dMaxAvoidDose = dMaxAvoidDose[0] / 100 dMeanBrainstemDose = patient \ .TreatmentDelivery.FractionEvaluations[0] \ .DoseOnExaminations[0].DoseEvaluations[iLastDose] \ .GetDoseStatistic(RoiName=pcBrainstemName, DoseType='Average') / 100 # Gy dMaxBrainstemDose = patient \ .TreatmentDelivery.FractionEvaluations[0] \ .DoseOnExaminations[0].DoseEvaluations[iLastDose] \ .GetDoseAtRelativeVolumes(RoiName=pcBrainstemName, RelativeVolumes=[0.01]) dMaxBrainstemDose = dMaxBrainstemDose[0] / 100 dBrainstemVolume = patient.PatientModel.StructureSets['CT 1'].RoiGeometries[pcBrainstemName].GetRoiVolume() # cm3 dV60GyBrainstem = patient \ .TreatmentDelivery.FractionEvaluations[0] \ .DoseOnExaminations[0].DoseEvaluations[iLastDose] \ .GetRelativeVolumeAtDoseValues(RoiName=pcBrainstemName, DoseValues=[6000]) dV60GyBrainstem = dV60GyBrainstem[0] * dBrainstemVolume # cm3 # # Print output to screen t # print(" ") print(" ") print("--- getBrainDvhStats.py ---") print(" ") print("Mean Target Dose (Gy): %.2f" % dMeanTargetDose) print("Min Target Dose (Gy): %.2f" % dMinTargetDose) print(" ") print("Conformity Index 95: %.2f" % dCI95) #print("Max Target Dose (Gy): %.2f" % dMaxTargetDose) #print("V95 Target (percent): %.2f" % dV95Target) print(" ") print("Mean Brainstem Dose (Gy): %.2f" % dMeanBrainstemDose) print("Max Brainstem Dose (Gy): %.2f" % dMaxBrainstemDose) print("V60Gy Brainstem (cm3): %.2f" % dV60GyBrainstem) print(" ") print("Mean Brain Dose (Gy): %.2f" % dMeanBrainDose) print("Max Brain Dose (Gy): %.2f" % dMaxBrainDose) #print("V12Gy Brain (cm3): %.2f" % dV12GyBrain) #print("V40Gy Brain (cm3): %.2f" % dV40GyBrain) print("V60Gy Brain (cm3): %.2f" % dV60GyBrain) #print("V72Gy Brain (cm3): %.2f" % dV72GyBrain) #print("Conformity Index 90: %.2f" % dCI90) #print(" ") #print("Mean Avoidance Dose (Gy): %.2f" % dMeanAvoidDose) #print("Max Avoidance Dose (Gy): %.2f" % dMaxAvoidDose) print(" ") print("--- END --- ") print(" ")