Skip to content

Commit

Permalink
Fix bug in angle interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
lauraporta committed Dec 12, 2023
1 parent 1004279 commit 9ba7c3e
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions derotation/analysis/full_rotation_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ def process_analog_signals(self):
) = self.adjust_rotation_increment()

self.interpolated_angles = self.get_interpolated_angles()

self.remove_artifacts_from_interpolated_angles()

(
self.line_start,
self.line_end,
Expand Down Expand Up @@ -516,6 +519,7 @@ def get_interpolated_angles(self) -> np.ndarray:
self.rotation_ticks_peaks[1:],
)

# interpolate between the ticks
for i, (start, stop) in enumerate(zip(starts, stops)):
if cumulative_sum_to360[i + 1] < cumulative_sum_to360[i]:
cumulative_sum_to360[i] = 0
Expand All @@ -531,6 +535,32 @@ def get_interpolated_angles(self) -> np.ndarray:

return interpolated_angles

def remove_artifacts_from_interpolated_angles(self):
"""Removes artifacts from the interpolated angles, coming from
an inconsistency between the number of ticks and cumulative sum.
These artifacts appear as very brief rotation periods that are not
plausible given the experimental setup.
"""
logging.info("Cleaning interpolated angles...")

# find very short rotation periods in self.interpolated_angles

thresholded = np.zeros_like(self.interpolated_angles)
thresholded[np.abs(self.interpolated_angles) > 0.15] = 1
rotation_start = np.where(np.diff(thresholded) > 0)[0]
rotation_end = np.where(np.diff(thresholded) < 0)[0]

assert len(rotation_start) == len(rotation_end)
assert len(rotation_start) == self.number_of_rotations

for i, (start, end) in enumerate(
zip(rotation_start[1:], rotation_end[:-1])
):
self.interpolated_angles[end:start] = 0

self.interpolated_angles[: rotation_start[0]] = 0
self.interpolated_angles[rotation_end[-1] :] = 0

def calculate_angles_by_line_and_frame(
self,
) -> Tuple[np.ndarray, np.ndarray]:
Expand Down

0 comments on commit 9ba7c3e

Please sign in to comment.