portpy.photon.utils package
Submodules
portpy.photon.utils.load_data module
- portpy.photon.utils.load_data.load_data(meta_data: dict, pat_dir: str, load_inf_matrix_full: bool) dict[source]
Takes meta_data and the location of the data as inputs and returns the full data. The meta_data only includes light-weight data from the .json files (e.g., beam IDs, angles, structure names,..). Large numeric data (e.g., influence matrix, voxel coordinates) are stored in .h5 files.
- Parameters:
load_inf_matrix_full – whether to load full influence matrix from the data
meta_data – meta_data containing light weight data from json file
pat_dir – patient folder directory containing all the data
e.g. if options[‘loadInfluenceMatrixFull’]=True, it will load full influence matrix :return: a dict of data
- portpy.photon.utils.load_data.load_file(meta_data: dict, pat_dir: str)[source]
This recursive function loads the data from .h5 files and merge them with the meta_data and returns a dictionary including all the data (meta_data+actual numeric data) :param meta_data: meta_data containing leight weight data from json file :param pat_dir: patient folder directory :return:
portpy.photon.utils.load_metadata module
- portpy.photon.utils.load_metadata.list_to_dict(json_data)[source]
A recursive function which constructs dictionary from list :param json_data: data in json or list format :return: data in dictionary format
- portpy.photon.utils.load_metadata.load_config_clinical_criteria(protocol_type, protocol_name)[source]
- portpy.photon.utils.load_metadata.load_metadata(pat_dir: str) dict[source]
Loads metadata of a patient located in path and returns the metadata as a dictionary
The data are loaded from the following .Json files: 1- StructureSet_MetaData.json
including data about the structures (e.g., PTV, Kidney, Lung)
- 2- OptimizationVoxels_MetaData.json
including patient voxel data (3D cubic voxels of patient body)
- 3- CT_MetaData.json
including patient CT scan data (e.g., size, resolution, ct hounsfield units)
- 4- PlannerBeams.json
including the indices of the beams_dict selected by an expert planner based on the geometry/shape/location of tumor/healthy-tissues
- 5- ClinicalCriteria_MetaData.json
including clinically relevant metrics used to evaluate a plan (e.g., Kidney mean dose_1d <= 20Gy, Cord max dose_1d <= 10 Gy)
- 6- Beams.json
including beam information (e.g., gantry angle, collimator angle)
- Parameters:
pat_dir – full path of patient folder
- Returns:
a dictionary including all metadata
portpy.photon.utils.save_nrrd module
- portpy.photon.utils.save_nrrd.save_nrrd(my_plan: Plan, sol: dict, data_dir: str = None, ct_filename: str = 'ct', dose_filename: str = 'dose', rt_struct_filename: str = 'rtss') None[source]
save nrrd in the path directory else save in patient data directory
- Parameters:
my_plan – object of class Plan
sol – optimal solution dict
data_dir – save nrrd images of ct, dose_1d and structure set in path directory
ct_filename – ct file name
dose_filename – dose file name
rt_struct_filename – rt_struct file name
- Returns:
save nrrd images in path
portpy.photon.utils.save_or_load_pickle module
- portpy.photon.utils.save_or_load_pickle.load_inf_matrix(inf_name: Optional[str] = None, path: Optional[str] = None)[source]
Load pickle file of the plan object.
- Parameters:
inf_name – influence matrix name of the object of class InfleunceMatrix.
path – if path is set, plan object will be load from path directory else current project directory
- Returns:
load pickled object of class Plan
- Example:
>>> load_plan(plan_name='my_plan', path=r"path/for/loading_inf_matrix")
- portpy.photon.utils.save_or_load_pickle.load_optimal_sol(sol_name: str, path: Optional[str] = None) dict[source]
Load optimal solution dictionary got from optimization
- Parameters:
sol_name – name of the optimal solution to be loaded.
path – if path is set, plan object will be load from path directory else current directory
- Returns:
load solution
- Example:
>>> sol = load_optimal_sol(sol_name='sol', path=r'path/for/loading_sol')
- portpy.photon.utils.save_or_load_pickle.load_plan(plan_name: Optional[str] = None, path: Optional[str] = None)[source]
Load pickle file of the plan object.
- Parameters:
plan_name – plan_name of the object of class Plan. It None, it will try to look for plan name called ‘my_plan’
path – if path is set, plan object will be load from path directory else current project directory
- Returns:
load pickled object of class Plan
- Example:
>>> load_plan(plan_name='my_plan', path=r"path/for/loading_plan")
- portpy.photon.utils.save_or_load_pickle.save_inf_matrix(inf_matrix, inf_name: Optional[str] = None, path: Optional[str] = None) None[source]
Save pickled file for plan object
- Parameters:
inf_matrix – object fo class Infuence matrix
inf_name – create the name of the pickled file of InfluenceMatrix object. If none, it will save with the name as ‘inf_matrix’
path – if path is set, plan object will be pickled and saved in path directory else it will save in current project directory
- Returns:
save pickled object of class Plan
- Example:
>>> save_inf_matrix(inf_matrix=inf_matrix, inf_name='inf_matrix', path=r"path/to/save_inf_matrix")
- portpy.photon.utils.save_or_load_pickle.save_optimal_sol(sol: dict, sol_name: str, path: Optional[str] = None) None[source]
Save the optimal solution dictionary from optimization
- Parameters:
sol – optimal solution dictionary
sol_name – name of the optimal solution saved
path – if path is set, plan object will be load from path directory else current directory
- Returns:
save pickled file of optimal solution dictionary
- Example:
>>> save_optimal_sol(sol=sol, sol_name='sol', path=r'path/to/save_solution')
- portpy.photon.utils.save_or_load_pickle.save_plan(my_plan: Plan, plan_name: str = None, path: str = None) None[source]
Save pickled file for plan object
- Parameters:
my_plan – object fo class Plan
plan_name – create the name of the pickled file of plan object. If none, it will save with the name as ‘my_plan’
path – if path is set, plan object will be pickled and saved in path directory else it will save in current project directory
- Returns:
save pickled object of class Plan
- Example:
>>> my_plan.save_plan(plan_name='my_plan', path=r"path/to/save_plan")
portpy.photon.utils.slicer_script module
portpy.photon.utils.sol_change_inf_matrix module
- portpy.photon.utils.sol_change_inf_matrix.sol_change_inf_matrix(sol: dict, inf_matrix: InfluenceMatrix) dict[source]
Create a new solution by changing the basis of current solution. It will create a solution with same number of beamlets and voxels as inf_matrix
- Parameters:
sol – solution for which influence matrix is changed
inf_matrix – object of class Influence matrix
- Returns:
new solution dictionary having same number of beamlets and voxels as inf_matrix
portpy.photon.utils.view_in_slicer_jupyter module
- portpy.photon.utils.view_in_slicer_jupyter.view_in_slicer_jupyter(my_plan, dose_1d: Optional[ndarray] = None, sol: Optional[dict] = None, ct_name: str = 'ct', dose_name: str = 'dose', struct_set_name: str = 'rt_struct', show_ct: bool = True, show_dose: bool = True, show_structs: bool = True)[source]
This method helps to visualize CT, Dose and Rt struct in 3d slicer
- Parameters:
my_plan – object of class plan
dose_1d – dose in 1d
sol – solution dictionary
ct_name – Default to ‘ct’. name of the ct node in 3D slicer
dose_name – Default to ‘dose’. name of the dose node in 3D slicer
struct_set_name – name of the rtstruct
show_structs – default to True. If false, will not create structure node
show_dose – default to True. If false, will not create dose node
:param show_ct:default to True. If false, will not create ct node :return: visualize in slicer jupyter