Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUpClass(cls):
cls.profile = SingleProfile(cls.ydata, normalize_sides=cls.normalize_sides)
def find_mlc_peak(self, mlc_center):
"""Determine the center of the picket."""
mlc_rows = np.arange(mlc_center - self.sample_width, mlc_center + self.sample_width + 1)
if self.settings.orientation == UP_DOWN:
pix_vals = np.median(self.picket_array[mlc_rows, :], axis=0)
else:
pix_vals = np.median(self.picket_array[:, mlc_rows], axis=1)
if max(pix_vals) > np.percentile(self.picket_array, 80):
prof = SingleProfile(pix_vals)
fw80mc = prof.fwxm_center(70, interpolate=True)
return fw80mc + self.approximate_idx - self.spacing
def _get_vert_profile(self, vert_position: float, vert_width: float):
left_edge = int(round(self.image.array.shape[1]*vert_position - self.image.array.shape[1]*vert_width/2))
left_edge = max(left_edge, 0) # clip to 0
right_edge = int(round(self.image.array.shape[1]*vert_position + self.image.array.shape[1]*vert_width/2) + 1)
right_edge = min(right_edge, self.image.array.shape[1]) # clip to image limit
self.positions['vertical left'] = left_edge
self.positions['vertical right'] = right_edge
return SingleProfile(np.sum(self.image.array[:, left_edge:right_edge], 1))
The determination of an automatic start point is accomplished by finding the Full-Width-80%-Max.
Finding the maximum pixel does not consistently work, esp. in the presence of a pin prick. The
FW80M is a more consistent metric for finding a good start point.
"""
# sum the image along each axis within the central 1/3 (avoids outlier influence from say, gantry shots)
top_third = int(self.image.array.shape[0]/3)
bottom_third = int(top_third * 2)
left_third = int(self.image.array.shape[1]/3)
right_third = int(left_third * 2)
central_array = self.image.array[top_third:bottom_third, left_third:right_third]
x_sum = np.sum(central_array, 0)
y_sum = np.sum(central_array, 1)
# Calculate Full-Width, 80% Maximum center
fwxm_x_point = SingleProfile(x_sum).fwxm_center(80) + left_third
fwxm_y_point = SingleProfile(y_sum).fwxm_center(80) + top_third
center_point = Point(fwxm_x_point, fwxm_y_point)
return center_point
def _median_profiles(images) -> Tuple[SingleProfile, SingleProfile]:
"""Return two median profiles from the open and dmlc image. For visual comparison."""
profile1 = SingleProfile(np.mean(images[0], axis=0))
profile1.stretch()
profile2 = SingleProfile(np.mean(images[1], axis=0))
profile2.stretch()
# normalize the profiles to approximately the same value
norm_val = np.percentile(profile1.values, 90)
profile1.normalize(norm_val)
norm_val = np.percentile(profile2.values, 90)
profile2.normalize(norm_val)
return profile1, profile2
def _get_horiz_profile(self, horiz_position: float, horiz_width: float):
bottom_edge = int(round(self.image.array.shape[0] * horiz_position - self.image.array.shape[0] * horiz_width / 2))
bottom_edge = max(bottom_edge, 0)
top_edge = int(round(self.image.array.shape[0] * horiz_position + self.image.array.shape[0] * horiz_width / 2) + 1)
top_edge = min(top_edge, self.image.array.shape[0])
self.positions['horizontal bottom'] = bottom_edge
self.positions['horizontal top'] = top_edge
return SingleProfile(np.sum(self.image.array[bottom_edge:top_edge, :], 0))
Finding the maximum pixel does not consistently work, esp. in the presence of a pin prick. The
FW80M is a more consistent metric for finding a good start point.
"""
# sum the image along each axis within the central 1/3 (avoids outlier influence from say, gantry shots)
top_third = int(self.image.array.shape[0]/3)
bottom_third = int(top_third * 2)
left_third = int(self.image.array.shape[1]/3)
right_third = int(left_third * 2)
central_array = self.image.array[top_third:bottom_third, left_third:right_third]
x_sum = np.sum(central_array, 0)
y_sum = np.sum(central_array, 1)
# Calculate Full-Width, 80% Maximum center
fwxm_x_point = SingleProfile(x_sum).fwxm_center(80) + left_third
fwxm_y_point = SingleProfile(y_sum).fwxm_center(80) + top_third
center_point = Point(fwxm_x_point, fwxm_y_point)
return center_point