Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
* np.uint64(32)
* np.uint64(num_dimensions)
* np.uint64(2)
)
num_slices = np.floor(estimated_ram_needed / options.ram_available).astype(int) + 1
if not options.quiet:
sys.stdout.write(
" | Points tested per reference point: {} | RAM split count: {}".format(
num_points_in_shell, num_slices
)
)
sys.stdout.flush()
all_checks = np.where(np.ravel(to_be_checked))[0]
index = np.arange(len(all_checks))
sliced = np.array_split(index, num_slices)
sorted_sliced = [np.sort(current_slice) for current_slice in sliced]
for current_slice in sorted_sliced:
to_be_checked_sliced = np.full_like(to_be_checked, False, dtype=bool)
to_be_checked_sliced[ # pylint: disable=unsupported-assignment-operation
all_checks[current_slice]
] = True
assert np.all(to_be_checked[to_be_checked_sliced])
axes_reference_to_be_checked = options.flat_mesh_axes_reference[
:, to_be_checked_sliced
]
def _get_indices(z_list, z_val):
indices = np.array([item[0] for item in z_list])
# This will error if more than one contour exists on a given slice
desired_indices = np.where(indices == z_val)[0]
# Multiple contour sets per slice not yet implemented
return desired_indices
Point
The weighted-pixel value location of the BB.
"""
# get initial starting conditions
hmin, hmax = np.percentile(self.array, [5, 99.9])
spread = hmax - hmin
max_thresh = hmax
lower_thresh = hmax - spread / 1.5
# search for the BB by iteratively lowering the low-pass threshold value until the BB is found.
found = False
while not found:
try:
binary_arr = np.logical_and((max_thresh > self), (self >= lower_thresh))
labeled_arr, num_roi = ndimage.measurements.label(binary_arr)
roi_sizes, _ = np.histogram(labeled_arr, bins=num_roi + 1)
bw_bb_img = np.where(
labeled_arr == np.argsort(roi_sizes)[-3], 1, 0
) # we pick the 3rd largest one because the largest is the background, 2nd is rad field, 3rd is the BB
bb_regionprops = measure.regionprops(bw_bb_img)[0]
if not is_round(bb_regionprops):
raise ValueError
if not is_modest_size(bw_bb_img, self.rad_field_bounding_box):
raise ValueError
if not is_symmetric(bw_bb_img):
raise ValueError
except (IndexError, ValueError):
max_thresh -= 0.05 * spread
if max_thresh < hmin:
raise ValueError(
"Pylinac v2.2.7: Unable to locate the BB. Make sure the field "
"edges do not obscure the BB and that there is no artifacts in "
def convert_numbers_to_string(name, lookup, column):
dtype = np.array([item for _, item in lookup.items()]).dtype
result = np.empty_like(column).astype(dtype)
result[:] = ""
for i, item in lookup.items():
result[column.values == int(i)] = item
if np.any(result == ""):
print(lookup)
print(np.where(result == ""))
print(column[result == ""].values)
unconverted_entries = np.unique(column[result == ""])
raise Exception(
"The conversion lookup list for converting {} is incomplete. "
"The following data numbers were not converted:\n"
"{}\n"
"Please update the trf2csv conversion script to include these "
"in its definitions.".format(name, unconverted_entries)
)
return result
# Convert python lists into numpy arrays for easier use
distance = np.array(distance)
relative_dose = np.array(relative_dose)
scan_curvetype = np.array(scan_curvetype)
scan_depth = np.array(scan_depth)
# If the user requests to sort the data (which is default) the loaded
# mephysto files are organised so that PDDs are first, then inplane
# profiles, then crossplane profiles.
if sort:
# Find the references for where the scan type is the relevant type
# and then use the "hstack" function to join the references together.
sort_ref = np.hstack(
[
np.where(scan_curvetype == "PDD")[0], # reference of PDDs
np.where(scan_curvetype == "INPLANE_PROFILE")[0], # inplane ref
np.where(scan_curvetype == "CROSSPLANE_PROFILE")[0], # crossplane
]
)
# Confirm that the length of sort_ref is the same as scan_curvetype.
# This will be false if there exists an unexpected scan_curvetype.
assert len(sort_ref) == len(scan_curvetype)
# Apply the sorting reference to each of the relevant variables.
distance = distance[sort_ref]
relative_dose = relative_dose[sort_ref]
scan_curvetype = scan_curvetype[sort_ref]
scan_depth = scan_depth[sort_ref]
# Output csv's if "output_to_file" is True
if output_to_file: