Skip to content

kels271828/RayBay

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RayBay

DOI

Automatic parameter tuning for the RayStation treatment planning system

Code

  • raybay: Class and functions for specifying and saving problem instances.
  • optimize: Hyperparameter optimization functions for RayStation treatment planning system.
  • analyze: Plotting functions to visualize treatment plan results.

Workflow

Define clinical goals and objective functions

  • Clinical goals are specified in a CSV file with columns Roi, Type, GoalCriteria, AcceptanceLevel, ParameterValue, Weight, and Shape. Valid types include AverageDose, MinDose, MaxDose, MinDvh, and MaxDvh. Valid shapes include linear and linear_quadratic.
  • Constituent functions are specified in a CSV file with columns Roi, FunctionType, DoseLevel, PercentVolume, EudParameterA, and Weight. The row index within the table should correspond to the constituent function in the RayStation objective. Fixed parameters should be a single value, tunable parameters should be a list containing the minimum and maximum values, and irrelevant parameters can be left blank.

See results for examples.

Once the virtual environment is set up (see below), you can create clinical goal and objective function files with the following steps:

  1. Run get_volume script from Spyder to create initial goals.csv file. This will include the names and volumes for all ROIs in the current case. Delete rows that you don't want to include, and fill out the remaining columns based on your clinical goals. Use columns Volume (cm^3) and RoiVolume (cm^3) to compute the column Volume (%).
  2. Run setup_patient script from local computer to create goals.csv and funcs.csv files formatted for the approved, default, and bayes cases. For the approved plan, the file approved/funcs.csv will be filled in when you run the script get_plan. For the optimized plan, the file bayes/goals.csv will have default weights = 1 for all ROIs and shape = 'linear_quadratic' for all ROIs except for the chestwall and ribs. Update Weight and Shape columns if needed. The file bayes/funcs.csv will have DoseLevel = [gamma/4, gamma] for all goals except for the PTV. The PTV D95 will be 4800, and the PTV Max will be [(gamma - 3*4800)/4, gamma]. Update DoseLevel, PercentVolume, and Weight columns if needed (parameter will be tuned if a range of values is given, and parameter will be held constant if a single value is given).

Launch RayStation

  1. Log in to Citrix Receiver
  2. Open RayStation 8B SP1
  3. Open RayStation Planning
  4. Select patient and plan
  5. Make sure "Autoscale to Prescription" is turned off
  6. Make sure objective function terms are listed in same order as csv file
  7. In Scripting tab, run script run_console (may need to de-select "Show only validated scripts" in Settings)
  8. Create a new tab in the RayStation console

Set up virtual environment

  1. Create virtual environment: python -m venv fpath\virtual_environment
  2. Activate virtual environment: fpath\virtual_environment\Scripts\activate.bat
  3. Install packages: pip install -r requirements.txt

Note: Setting up the virtual environment only needs to be done once.

Run Spyder and connect to RayStation

  1. Activate virtual environment: fpath\virtual_environment\Scripts\activate.bat
  2. Run Spyder: spyder
  3. Start Spyder kernel: python -m spyder_kernels.console
  4. Connect Spyder to RayStation:
    • In Spyder, click options icon at the top left of the Spyder console
    • Click "Connect to existing kernel"
    • Enter kernel number listed in the RayStation console

Run Python Script

  1. Open script in Spyder
    • To use scripts on local computer, may need to change read/write settings first
  2. Click "Run file" button

See src for example scripts:

  • get_plan gets clinical goal values for the approved plan and the default plan. Make sure you have the correct plan open in RayStation. For the default plan, the constituent functions in RayStation will be cleared and re-populated based on default/funcs.csv.
  • opt_plan gets the optimized treatment plan using either random sampling (dummy_minimize) or Bayesian optimization (gp_minimize).

Paper

Data and notebooks used to create the figures appearing in our preprint "A hyperparameter-tuning approach to automated inverse planning" can be found in results.

Abstract

Background In current practice, radiotherapy inverse planning often requires treatment planners to modify multiple parameters in the treatment planning system's objective function to produce clinically acceptable plans. Due to the manual steps in this process, plan quality can vary depending on the planning time available and the planner's skills.

Purpose: This study investigates the feasibility of two hyperparameter-tuning methods for automated inverse planning. Because this framework does not train a model on previously-optimized plans, it can be readily adapted to practice pattern changes, and the resulting plan quality is not limited by that of a training cohort.

Method: We retrospectively selected 10 patients who received lung stereotactic body radiation therapy using manually-generated clinical plans. We implemented random sampling and Bayesian optimization to automatically tune objective function parameters using linear--quadratic utility functions based on 11 clinical goals. Normalizing all plans to deliver a minimum dose of 48 Gy to 95% of the planning target volume, we compared plan quality for the automatically-generated plans to the manually-generated plans. We also investigated the impact of iteration count on the automatically-generated plans, comparing planning time and plan utility for randomized and Bayesian plans with and without stopping criteria.

Results: Without stopping criteria, the median planning time was 1.9 and 2.3 hours for randomized and Bayesian plans, respectively. The organ-at-risk doses in the randomized and Bayesian plans had a median percent difference (MPD) of 48.7% and 60.4% below clinical dose limits and an MPD of 2.8% and 3.3% below clinical plan doses. With stopping criteria, the utility decreased by an MPD of 5.3% and 3.9% for randomized and Bayesian plans, but the median planning time was reduced to 0.5 and 0.7 hours, and the organ-at-risk doses still had an MPD of 42.9% and 49.7% below clinical dose limits and an MPD of 0.3% and 1.8% below clinical plan doses.

Conclusions: This study demonstrates that hyperparameter-tuning approaches to automated inverse planning can reduce the treatment planner's active planning time with plan quality that is similar to or better than manually-generated plans.