Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix profile penumbra part deux #327

Closed
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions pylinac/core/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,20 +285,17 @@ def _penumbra_point(self, side: str='left', x: int=50, interpolate: bool=False,
max_point = y_data.max()
threshold = max_point * (x / 100)

# find the index, moving 1 element at a time until the value is encountered
found = False
at_end = False
try:
while not found and not at_end:
if y_data[peak] < threshold:
found = True
peak -= 1 if side == RIGHT else -1
elif peak == 0:
at_end = True
peak += 1 if side == RIGHT else -1
except IndexError:
not_found = len(np.where(y_data <= threshold)[0]) == 0
if not_found:
raise IndexError("The point of interest was beyond the profile; i.e. the profile may be cut off on the side")

# look for negative slope for RIGHT direction, postive slope for LEFT direction
grad = np.gradient(y_data)
cond = grad < 0 if side == RIGHT else grad > 0
locs = np.where((y_data > threshold) & cond)[0]

peak = locs[-1] + 1 if side == RIGHT else locs[0] - 1

if kind == VALUE:
return self._values_interp[peak] if interpolate else self.values[peak]
elif kind == INDEX:
Expand Down
7 changes: 4 additions & 3 deletions pylinac/planar_imaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ def _phantom_angle_calc(self) -> float:

start_angle_deg = self._determine_start_angle_for_circle_profile()
circle = self._circle_profile_for_phantom_angle(start_angle_deg)
peak_idx = circle.find_fwxm_peaks(threshold=0.6, max_number=1)[0]
peak_idx = circle.find_fwxm_peaks(threshold=0.6, x=80, max_number=1)[0]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This x=80 is failing a number of tests. Why are you choosing 80?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No good reason...I think that I was somewhat confused and was experimenting with various parameters. (I'm not proud ☹️ )


shift_percent = peak_idx / len(circle.values)
shift_radians = shift_percent * 2 * np.pi
Expand Down Expand Up @@ -774,10 +774,11 @@ def _is_counter_clockwise(self) -> bool:
"""

circle = self._circle_profile_for_phantom_angle(0)
peak_idx = circle.find_fwxm_peaks(threshold=0.6, max_number=1)[0]
peak_idx = circle.find_fwxm_peaks(threshold=0.6, x=80, max_number=1)[0]
circle.values = np.roll(circle.values, -peak_idx)
first_set = circle.find_peaks(search_region=(0.05, 0.45), threshold=0, min_distance=0.025, kind='value', max_number=9)
second_set = circle.find_peaks(search_region=(0.55, 0.95), threshold=0, min_distance=0.025, kind='value', max_number=9)

return max(first_set) > max(second_set)

def _determine_start_angle_for_circle_profile(self) -> float:
Expand All @@ -801,7 +802,7 @@ def _determine_start_angle_for_circle_profile(self) -> float:
"""

circle = self._circle_profile_for_phantom_angle(0)
peak_idxs = circle.find_fwxm_peaks(threshold=0.6, max_number=4)
peak_idxs = circle.find_fwxm_peaks(threshold=0.6, x=80, max_number=4)
on_left_half = [x < len(circle.values) / 2 for x in peak_idxs]
aligned_to_zero_deg = not(all(on_left_half) or not any(on_left_half))
return 90 if aligned_to_zero_deg else 0
Expand Down