-
Notifications
You must be signed in to change notification settings - Fork 2
/
get_plan.py
66 lines (58 loc) · 2.29 KB
/
get_plan.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""Get clinical and default plans."""
import pickle
import sys
import connect
repo_path = '\\\\client\\E$\\My Drive\\RayBay\\'
sys.path.append(repo_path + 'src\\')
import optimize
import raybay
# Patient
patient_path = repo_path + 'results\\SBRT_lung_minsun\\'
#patient_path = repo_path + 'results\\ZZ_MK_LLungSBRT3778\\'
#patient_path = repo_path + 'results\\ZZ_MK_RLungSBRT4076\\'
#patient_path = repo_path + 'results\\ZZ_MK_RULungSBRT3796\\'
#patient_path = repo_path + 'results\\ZZ_MK_RLSBRT1931\\'
#patient_path = repo_path + 'results\\ZZ_MK_LLLungSBRT2736\\'
#patient_path = repo_path + 'results\\ZZ_MK_LULSBRT4544\\'
#patient_path = repo_path + 'results\\ZZ_MK_SBRTLL0924allviolated\\'
#patient_path = repo_path + 'results\\ZZ_MK_SBRTLL7289\\'
#patient_path = repo_path + 'results\ZZ_MK_SBRTLLL8973\\'
#patient_path = repo_path + 'results\\ZZ_MK_SBRTRL7289\\'
#patient_path = repo_path + 'results\\ZZ_MK_SBRTRUL_2928allviolate\\'
# Case
case_path = 'approved\\'
#case_path = 'default\\'
# Get RayStation objects
patient = connect.get_current('Patient')
case = connect.get_current('Case')
plan = connect.get_current('Plan')
beam_set = connect.get_current('BeamSet')
# Initialize result object
result = raybay.RaybayResult(
patient.Name,
case.CaseName,
plan.Name,
patient_path + case_path + 'funcs.csv',
('PTV', 4800, 95), # check PTV name
goals=patient_path + case_path + 'goals.csv')
# Add results
if 'default' in case_path:
optimize.add_funcs(plan, result.func_df)
optimize.set_pars(plan, result.func_df, [])
flag = optimize.calc_plan(plan, beam_set, result.norm)
else:
result.func_df = optimize.get_funcs(plan)
result.func_df.to_csv(patient_path + case_path + 'funcs.csv')
flag = 0
result.flag_list.append(flag)
goal_results = optimize.get_results(plan, result.goal_df)
scale = optimize.get_scale(result.goal_df, result.norm, goal_results)
for index, row in result.goal_df.iterrows():
result.goal_dict[index].append(scale*goal_results[index])
result.dvh_dict = optimize.get_dvh(result.roi_list)
coeff = result.goal_dict[6][0]/result.dvh_dict['Dose'][-1]
result.dvh_dict['Dose'] *= coeff # normalize (check index in prev line)
# Save results
result_path = patient_path + case_path + 'res_' + case_path[:-1] + '.pkl'
with open(result_path, 'wb') as fp:
pickle.dump(result, fp)