Skip to content

Commit

Permalink
Use new interpolation method
Browse files Browse the repository at this point in the history
  • Loading branch information
lauraporta committed Oct 24, 2023
1 parent b5edcce commit 23e9549
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 23 deletions.
63 changes: 40 additions & 23 deletions derotation/analysis/derotation_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ def load_data(self):

self.total_clock_time = len(self.frame_clock)

self.line_use_start = self.config["interpolation"]["line_use_start"]
self.frame_use_start = self.config["interpolation"]["frame_use_start"]

self.rotation_increment = self.config["rotation_increment"]
self.rot_deg = self.config["rot_deg"]
self.assume_full_rotation = self.config["assume_full_rotation"]
Expand Down Expand Up @@ -129,16 +132,21 @@ def process_analog_signals(self):
f"Corrected increments: {self.corrected_increments}"
)

self.interpolate_angles()

# ===================================
# Quantify the rotation for each line of each frame
self.interpolated_angles = self.get_interpolated_angles()
(
self.line_start,
self.line_end,
) = self.get_start_end_times_with_threshold(self.line_clock, self.k)
(
self.frame_start,
self.frame_end,
) = self.get_start_end_times_with_threshold(self.frame_clock, self.k)

if self.assume_full_rotation:
(
self.rot_deg_line,
self.signed_rotation_degrees_line,
) = self.find_rotation_for_each_line_from_motor()
self.rot_deg_frame,
) = self.calculate_angles_by_line_and_frame()
else:
self.rot_deg_line = (
self.find_rotation_angles_by_line_in_incremental_rotation()
Expand Down Expand Up @@ -444,42 +452,51 @@ def roatate_by_frame_incremental(self):

return new_rotated_image_stack

def interpolate_angles(self):
def get_interpolated_angles(self):
ticks_with_increment = [
item
for i in range(self.number_of_rotations)
for item in [self.corrected_increments[i]]
* self.ticks_per_rotation[i]
]

cumulative_sum_to360 = np.cumsum(ticks_with_increment) % self.rot_deg

interpolated_angles = np.zeros(self.total_clock_time * 256)
interpolated_angles = np.zeros(self.total_clock_time)

starts, stops = (
self.rotation_ticks_peaks[:-1],
self.rotation_ticks_peaks[1:],
)
angle_increments_between_ticks = [
np.linspace(

for i, (start, stop) in enumerate(zip(starts, stops)):
interpolated_angles[start:stop] = np.linspace(
cumulative_sum_to360[i],
cumulative_sum_to360[i + 1],
stops[i] - starts[i],
stop - start,
)
for i in range(len(starts))
]

np.put(
interpolated_angles,
[
idx
for start, stop in zip(starts, stops)
for idx in range(start, stop)
],
np.concatenate(angle_increments_between_ticks),
)

return interpolated_angles

def calculate_angles_by_line_and_frame(self):
logging.info("Calculating angles by line and frame...")
logging.info(self.interpolated_angles.shape)
inverted_angles = self.interpolated_angles * -1
line_angles = np.zeros(self.num_total_lines)
frame_angles = np.zeros(self.num_frames)

if self.line_use_start:
line_angles = inverted_angles[self.line_start]
else:
line_angles = inverted_angles[self.line_end]

if self.frame_use_start:
frame_angles = inverted_angles[self.frame_start]
else:
frame_angles = inverted_angles[self.frame_end]

return line_angles, frame_angles

def find_rotation_for_each_line_from_motor(self):
# calculate the rotation degrees for each line
rotation_degrees = np.empty_like(self.line_clock)
Expand Down
4 changes: 4 additions & 0 deletions derotation/config/full_rotation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ analog_signals_processing:
squared_pulse_k: 1
upper_lim_bisect: 5
inter_rotation_interval_min_len: 1000

interpolation:
line_use_start: True
frame_use_start: True

0 comments on commit 23e9549

Please sign in to comment.