Prescription

Define Prescription and methods for parsing prescription data from python objects as well as JSON- or YAML-formatted files.

Parsing methods expect the following formats.

YAML:

- name : PTV
  label : 1
  is_target: Yes
  dose : 35.
  constraints:
  - "D90 >= 32.3Gy"
  - "D1 <= 1.1rx"

- name : OAR1
  label : 2
  is_target: No
  dose :
  constraints:
  - "D95 <= 20Gy"
  - "V30 Gy <= 20%"

Python list of dict (JSON approximately the same):

[{
        "name" : "PTV",
        "label" : 1,
        "is_target" : True,
        "dose" : 35.,
        "constraints" : ["D1 <= 1.1rx", "D90 >= 32.3Gy"]
}, {
        "name" : "OAR1",
        "label" : 2,
        "is_target" : False,
        "dose" : None,
        "constraints" : ["D95 <= 20Gy"]
}]
JSON verus Python syntax differences:
  • true/false instead of True/False
  • null instead of None
class prescription.Prescription(prescription_data=None)[source]

Class for specifying structures with dose targets and constraints.

constraint_dict

dict – Dictionary of ConstraintList objects, keyed by structure labels.

structure_dict

dict – Diciontionary of Structure objects, keyed by structure labels.

rx_list

list – List of dictionaries representation of prescription.

add_structure_to_dictionaries(structure)[source]

Add a new structure to internal representation of prescription.

Parameters:structure (Structure) – Structure added to Prescription.structure_dict. An corresponding, empty constraint list is added to Prescription.constraint_dict.
Returns:None
Raises:TypeError – If structure not a Structure.
constraints_by_label

Dictionary of constraints in prescription, by structure label.

dict

Dictionary of structures in prescription, by label.

digest(prescription_data)[source]

Populate Prescription‘s structures and dose constraints.

Specifically, for each entry in prescription_data, construct a Structure to capture structure data (e.g., name, label), as well as a corresponding but separate ConstraintList object to capture any dose constraints specified for the structure.

Add each such structure to Prescription.structure_dict, and each such constraint list to Prescription.constraint_dict. Build or copy a “list of dictionaries” representation of the prescription data, assign to Prescription.rx_list.

Parameters:prescription_data – Input to be parsed for structure and dose constraint data. Accepted formats include str specifying a valid path to a suitably-formatted JSON or YAML file, or a suitably-formatted list of dict objects.
Returns:None
Raises:TypeError – If input not of type list or a str specfying a valid path to file that can be loaded with the json.load() or yaml.safe_load() methods.
list

List of structures in prescription

report(anatomy)[source]

Reports whether anatomy fulfills all prescribed constraints.

Parameters:anatomy (Antomy) – Container of structures to compare against prescribed constraints.
Returns:Dictionary keyed by structure label, with data on each dose constraint associated with that structure in this Prescription. Reported data includes the constraint, whether it was satisfied, and the actual dose achieved at the percentile/threshold specified by the constraint.
Return type:dict
Raises:TypeError – If anatomy not an Anatomy.
report_string(anatomy)[source]

Reports whether anatomy fulfills all prescribed constraints.

Parameters:anatomy (Anatomy) – Container of structures to compare against prescribed constraints.
Returns:Stringified version of output from Presription.report.
Return type:str