Skip to content

Commit b2777dd

Browse files
committed
Store center of rotation previously found in a file
1 parent a34b2d7 commit b2777dd

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

derotation/analysis/full_derotation_pipeline.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def __call__(self):
6868
self.process_analog_signals()
6969

7070
self.offset = self.find_image_offset(self.image_stack[0])
71-
# self.find_optimal_parameters()
71+
self.set_optimal_center()
7272

7373
rotated_images = self.derotate_frames_line_by_line()
7474
self.masked_image_volume = self.add_circle_mask(
@@ -1019,6 +1019,29 @@ def find_optimal_parameters(self):
10191019
x_center, y_center = maximum["params"].values()
10201020
self.center_of_rotation = (x_center, y_center)
10211021

1022+
# write optimal center in a text file
1023+
with open(
1024+
self.debug_plots_folder / "optimal_center_of_rotation.txt", "w"
1025+
) as f:
1026+
f.write(f"Optimal center of rotation: {x_center}, {y_center}")
1027+
1028+
def set_optimal_center(self):
1029+
"""Checks if the optimal center of rotation is calculated.
1030+
If it is not calculated, it will calculate it.
1031+
"""
1032+
try:
1033+
with open(
1034+
self.debug_plots_folder / "optimal_center_of_rotation.txt", "r"
1035+
) as f:
1036+
optimal_center = f.read()
1037+
self.center_of_rotation = tuple(
1038+
map(int, optimal_center.split(":")[1].split(","))
1039+
)
1040+
logging.info("Optimal center of rotation found.")
1041+
except FileNotFoundError:
1042+
logging.info("Optimal center of rotation not found.")
1043+
self.find_optimal_parameters()
1044+
10221045
def plot_max_projection_with_center(
10231046
self, stack, name="max_projection_with_center"
10241047
):

0 commit comments

Comments
 (0)