Skip to content

Commit 88debe0

Browse files
committed
Updates for v1.1.3: Fix bugs in clinical_criteria.py. Update data explorer to work with hugging face hub new version. Add lower bound dvh in clinical_criteria.py
1 parent c7c0e96 commit 88debe0

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

portpy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
# a separate commercial license.
1616
# ----------------------------------------------------------------------
1717

18-
__version__ = "1.1.2"
18+
__version__ = "1.1.3"
1919
# Change version here manually to reflect it everywhere
2020
from portpy import photon

portpy/photon/clinical_criteria.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ def get_dvh_table(self, my_plan: Plan, constraint_list: list = None, opt_params:
279279
df.at[count, 'dose_gy'] = self.dose_to_gy(dose_key, dvh_updated_list[i]['parameters'][dose_key])
280280
df.at[count, 'volume_perc'] = dvh_updated_list[i]['constraints'][limit_key]
281281
df.at[count, 'dvh_type'] = 'constraint'
282+
df.at[count, 'bound_type'] = dvh_updated_list[i]['constraints'].get('bound_type', 'upper')
282283
count = count + 1
283284
goal_key = self.matching_keys(dvh_updated_list[i]['constraints'], 'goal')
284285
if goal_key in dvh_updated_list[i]['constraints']:
@@ -287,6 +288,7 @@ def get_dvh_table(self, my_plan: Plan, constraint_list: list = None, opt_params:
287288
df.at[count, 'volume_perc'] = dvh_updated_list[i]['constraints'][goal_key]
288289
df.at[count, 'dvh_type'] = 'goal'
289290
df.at[count, 'weight'] = dvh_updated_list[i]['parameters']['weight']
291+
df.at[count, 'bound_type'] = dvh_updated_list[i]['constraints'].get('bound_type', 'upper')
290292
count = count + 1
291293
if 'dose_volume_D' in dvh_updated_list[i]['type']:
292294
limit_key = self.matching_keys(dvh_updated_list[i]['constraints'], 'limit')
@@ -295,6 +297,7 @@ def get_dvh_table(self, my_plan: Plan, constraint_list: list = None, opt_params:
295297
df.at[count, 'volume_perc'] = dvh_updated_list[i]['parameters']['volume_perc']
296298
df.at[count, 'dose_gy'] = self.dose_to_gy(limit_key, dvh_updated_list[i]['constraints'][limit_key])
297299
df.at[count, 'dvh_type'] = 'constraint'
300+
df.at[count, 'bound_type'] = dvh_updated_list[i]['constraints'].get('bound_type', 'upper')
298301
count = count + 1
299302
goal_key = self.matching_keys(dvh_updated_list[i]['constraints'], 'goal')
300303
if goal_key in dvh_updated_list[i]['constraints']:
@@ -303,6 +306,7 @@ def get_dvh_table(self, my_plan: Plan, constraint_list: list = None, opt_params:
303306
df.at[count, 'dose_gy'] = self.dose_to_gy(goal_key, dvh_updated_list[i]['constraints'][goal_key])
304307
df.at[count, 'dvh_type'] = 'goal'
305308
df.at[count, 'weight'] = dvh_updated_list[i]['parameters']['weight']
309+
df.at[count, 'bound_type'] = dvh_updated_list[i]['constraints'].get('bound_type', 'upper')
306310
count = count + 1
307311
self.dvh_table = df
308312
self.get_max_tol(constraints_list=constraint_list)
@@ -339,15 +343,25 @@ def get_low_dose_vox_ind(self, my_plan: Plan, dose: np.ndarray, inf_matrix: Infl
339343
volume percentage.
340344
"""
341345
dvh_table = self.dvh_table
342-
inf_matrix = my_plan.inf_matrix
346+
if inf_matrix is None:
347+
inf_matrix = my_plan.inf_matrix
343348
for ind in dvh_table.index:
344349
structure_name, dose_gy, vol_perc = dvh_table['structure_name'][ind], dvh_table['dose_gy'][ind], \
345350
dvh_table['volume_perc'][ind]
346351
dvh_type = dvh_table['dvh_type'][ind]
352+
bound_type = dvh_table.at[ind, 'bound_type'] if 'bound_type' in dvh_table.columns else 'upper'
347353
vol_perc = vol_perc / inf_matrix.get_fraction_of_vol_in_calc_box(structure_name)
348354
struct_vox = inf_matrix.get_opt_voxels_idx(structure_name)
349355
n_struct_vox = len(struct_vox)
350-
sort_ind = np.argsort(dose[struct_vox])
356+
# sort_ind = np.argsort(dose[struct_vox])
357+
if bound_type == 'lower':
358+
# For lower bound (e.g., PTV coverage), pick HIGHEST-dose voxels up to p%
359+
sort_ind = np.argsort(-dose[struct_vox]) # descending
360+
target_perc = vol_perc # accumulate to p%
361+
else:
362+
# Original behavior (upper bound): pick LOWEST-dose voxels up to (100 - p)%
363+
sort_ind = np.argsort(dose[struct_vox]) # ascending
364+
target_perc = 100 - vol_perc # accumulate to (100 - p)%
351365
voxel_sort = struct_vox[sort_ind]
352366
weights = inf_matrix.get_opt_voxels_volume_cc(structure_name)
353367
weights_sort = weights[sort_ind]
@@ -357,7 +371,7 @@ def get_low_dose_vox_ind(self, my_plan: Plan, dose: np.ndarray, inf_matrix: Infl
357371
for w_ind in range(n_struct_vox):
358372
w_sum = w_sum + weights_sort[w_ind]
359373
w_ratio = w_sum / weight_all_sum
360-
if w_ratio * 100 >= (100 - vol_perc):
374+
if w_ratio * 100 >= target_perc:
361375
break
362376
low_dose_voxels = voxel_sort[:w_ind+1]
363377
if ind == 0:

portpy/photon/data_explorer.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,8 @@ def _load_structure_metadata(self, patient_id: str, temp_download_dir: Optional[
593593
repo_id=self.hf_repo_id,
594594
repo_type="dataset",
595595
filename=hf_path,
596-
local_dir=temp_download_dir,
597-
use_auth_token=self.hf_token
596+
local_dir=temp_download_dir
597+
# use_auth_token=self.hf_token
598598
)
599599
with open(local_file) as f:
600600
return json.load(f)
@@ -634,8 +634,8 @@ def _load_beam_metadata(self, patient_id: str, temp_download_dir: Optional[str]
634634
self.hf_repo_id,
635635
repo_type="dataset",
636636
filename=path,
637-
local_dir=temp_download_dir,
638-
use_auth_token=self.hf_token
637+
local_dir=temp_download_dir
638+
# use_auth_token=self.hf_token
639639
)
640640
with open(local_file) as f:
641641
beam_meta.append(json.load(f))
@@ -666,8 +666,8 @@ def _load_planner_beams(self, patient_id: str, temp_download_dir: Optional[str]
666666
self.hf_repo_id,
667667
repo_type="dataset",
668668
filename=hf_path,
669-
local_dir=temp_download_dir,
670-
use_auth_token=self.hf_token
669+
local_dir=temp_download_dir
670+
# use_auth_token=self.hf_token
671671
)
672672
with open(local_file) as f:
673673
return json.load(f).get("IDs", [])

0 commit comments

Comments
 (0)