Skip to content

Commit

Permalink
Merge pull request #221 from StellarStorm/np125_deprecation
Browse files Browse the repository at this point in the history
Replace np.product with np.prod pending deprecation
  • Loading branch information
pchlap authored Jul 26, 2023
2 parents a6cfe23 + b911831 commit 847b3f3
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion platipy/imaging/dose/dvh.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def calculate_dvh_for_labels(dose_grid, labels, bin_width=0.1, max_dose=None):
mask_array = sitk.GetArrayFromImage(mask)

# Compute cubic centimetre volume of structure
cc = mask_array.sum() * np.product([a / 10 for a in mask.GetSpacing()])
cc = mask_array.sum() * np.prod([a / 10 for a in mask.GetSpacing()])

bins, values = calculate_dvh(
dose_grid, labels[k], bins=np.arange(-bin_width / 2, max_dose + bin_width, bin_width)
Expand Down
4 changes: 2 additions & 2 deletions platipy/imaging/dose/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def calculate_d_to_volume(dose_grid, label, volume, volume_in_cc=False):
mask_array = sitk.GetArrayFromImage(label)

if volume_in_cc:
volume = (volume * 1000 / ((mask_array > 0).sum() * np.product(label.GetSpacing()))) * 100
volume = (volume * 1000 / ((mask_array > 0).sum() * np.prod(label.GetSpacing()))) * 100

if volume > 100:
volume = 100
Expand Down Expand Up @@ -106,7 +106,7 @@ def calculate_v_receiving_dose(dose_grid, label, dose_threshold, relative=True):
if relative:
return relative_volume

total_volume = (mask_array > 0).sum() * np.product(label.GetSpacing()) / 1000
total_volume = (mask_array > 0).sum() * np.prod(label.GetSpacing()) / 1000

return relative_volume * total_volume

Expand Down
4 changes: 2 additions & 2 deletions platipy/imaging/label/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def compute_volume(label):
float: The volume (in cubic centimetres)
"""

return sitk.GetArrayFromImage(label).sum() * np.product(label.GetSpacing()) / 1000
return sitk.GetArrayFromImage(label).sum() * np.prod(label.GetSpacing()) / 1000


def compute_surface_dsc(label_a, label_b, tau=3.0):
Expand Down Expand Up @@ -159,7 +159,7 @@ def compute_volume_metrics(label_a, label_b):
arr_intersection = arr_a & arr_b
arr_union = arr_a | arr_b

voxel_volume = np.product(label_a.GetSpacing()) / 1000.0 # Conversion to cm^3
voxel_volume = np.prod(label_a.GetSpacing()) / 1000.0 # Conversion to cm^3

# 2|A & B|/(|A|+|B|)
dsc = (2.0 * arr_intersection.sum()) / (arr_a.sum() + arr_b.sum())
Expand Down
2 changes: 1 addition & 1 deletion platipy/imaging/label/fusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def compute_weight_map(
view_mask = view_as_windows(arr_mask, window_box_im)

# Flatten to have a list of patches (that are also flattened)
new_shape = (np.product(view_target.shape[:3]), np.product(view_target.shape[3:]))
new_shape = (np.prod(view_target.shape[:3]), np.prod(view_target.shape[3:]))
view_target_flat = np.reshape(view_target, new_shape)
view_moving_flat = np.reshape(view_moving, new_shape)
view_mask_flat = np.reshape(view_mask, new_shape)
Expand Down
6 changes: 3 additions & 3 deletions platipy/imaging/projects/cardiac/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,15 +567,15 @@ def run_cardiac_segmentation(img, guide_structure=None, settings=CARDIAC_SETTING
if crop_atlas_to_structures:
logger.info("Automatically cropping atlas: %s", atlas_id)

original_volume = np.product(image.GetSize())
original_volume = np.prod(image.GetSize())

crop_box_size, crop_box_index = label_to_roi(
structures.values(), expansion_mm=crop_atlas_expansion_mm
)

image = crop_to_roi(image, size=crop_box_size, index=crop_box_index)

final_volume = np.product(image.GetSize())
final_volume = np.prod(image.GetSize())

logger.info(" > Volume reduced by factor %.2f", original_volume / final_volume)

Expand Down Expand Up @@ -654,7 +654,7 @@ def run_cardiac_segmentation(img, guide_structure=None, settings=CARDIAC_SETTING
logger.info("Calculated crop box:")
logger.info(" > %s", crop_box_index)
logger.info(" > %s", crop_box_size)
logger.info(" > Vol reduction = %.2f", np.product(img.GetSize()) / np.product(crop_box_size))
logger.info(" > Vol reduction = %.2f", np.prod(img.GetSize()) / np.prod(crop_box_size))

"""
Step 2 - Rigid registration of target images
Expand Down
6 changes: 3 additions & 3 deletions platipy/imaging/projects/multiatlas/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,15 @@ def run_segmentation(img, settings=MUTLIATLAS_SETTINGS_DEFAULTS):
if crop_atlas_to_structures:
logger.info("Automatically cropping atlas: %s", atlas_id)

original_volume = np.product(image.GetSize())
original_volume = np.prod(image.GetSize())

crop_box_size, crop_box_index = label_to_roi(
structures.values(), expansion_mm=crop_atlas_expansion_mm
)

image = crop_to_roi(image, size=crop_box_size, index=crop_box_index)

final_volume = np.product(image.GetSize())
final_volume = np.prod(image.GetSize())

logger.info(" > Volume reduced by factor %.2f", original_volume/final_volume)

Expand Down Expand Up @@ -245,7 +245,7 @@ def run_segmentation(img, settings=MUTLIATLAS_SETTINGS_DEFAULTS):
logger.info("Calculated crop box:")
logger.info(" > %s", crop_box_index)
logger.info(" > %s", crop_box_size)
logger.info(" > Vol reduction = %.2f", np.product(img.GetSize())/np.product(crop_box_size))
logger.info(" > Vol reduction = %.2f", np.prod(img.GetSize())/np.prod(crop_box_size))

"""
Step 2 - Rigid registration of target images
Expand Down
2 changes: 1 addition & 1 deletion platipy/imaging/utils/valve.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def generate_valve_using_cylinder(
overlap = sitk.BinaryDilate(label_atrium, dilation_img) & sitk.BinaryDilate(
label_ventricle, dilation_img
)
overlap_vol = np.sum(sitk.GetArrayFromImage(overlap) * np.product(overlap.GetSpacing()))
overlap_vol = np.sum(sitk.GetArrayFromImage(overlap) * np.prod(overlap.GetSpacing()))
dilation += 1

# Now we can calculate the location of the valve
Expand Down
6 changes: 3 additions & 3 deletions platipy/imaging/utils/ventricle.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def extract(
segment_img.CopyInformation(template_img)

# Make sure area exceeds lower bound
area = segment_arr.sum() * np.product(segment_img.GetSpacing())
area = segment_arr.sum() * np.prod(segment_img.GetSpacing())
if area < min_area_mm2:
segment_img *= 0

Expand Down Expand Up @@ -167,8 +167,8 @@ def generate_left_ventricle_segments(

if verbose:
print("Module 1: Cropping and initial alignment.")
vol_before = np.product(contours[label_heart].GetSize())
vol_after = np.product(working_contours[label_heart].GetSize())
vol_before = np.prod(contours[label_heart].GetSize())
vol_after = np.prod(working_contours[label_heart].GetSize())
print(f" Images cropped. Volume reduction: {vol_before/vol_after:.3f}")

# Initially we should reorient based on the cardiac axis
Expand Down

0 comments on commit 847b3f3

Please sign in to comment.