Skip to content

Commit 993b733

Browse files
committed
Add small fixes to improve handling of batch processing
1 parent 9b3b246 commit 993b733

File tree

3 files changed

+10
-40
lines changed

3 files changed

+10
-40
lines changed

derotation/analysis/incremental_derotation_pipeline.py

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import matplotlib.pyplot as plt
1616
import numpy as np
17-
import pandas as pd
1817

1918
from derotation.analysis.blob_detection import BlobDetection
2019
from derotation.analysis.fit_ellipse import (
@@ -40,8 +39,10 @@ def __init__(self, *args, **kwargs):
4039
"""Initialize the IncrementalPipeline object."""
4140
super().__init__(*args, **kwargs)
4241

43-
self.small_rotations = 10
44-
self.number_of_rotations = self.rot_deg // self.small_rotations
42+
self.degrees_per_small_rotation = 10
43+
self.number_of_rotations = (
44+
self.rot_deg // self.degrees_per_small_rotation
45+
)
4546

4647
def __call__(self):
4748
"""Overwrite the ``__call__`` method from the parent class to derotate
@@ -60,8 +61,6 @@ def __call__(self):
6061
self.save(self.masked_image_volume)
6162
self.save_csv_with_derotation_data()
6263

63-
self.center_of_rotation = self.find_center_of_rotation()
64-
6564
def create_signed_rotation_array(self) -> np.ndarray:
6665
logging.info("Creating signed rotation array...")
6766
rotation_on = np.zeros(self.total_clock_time)
@@ -116,7 +115,9 @@ def adjust_rotation_increment(self) -> Tuple[np.ndarray, np.ndarray]:
116115
self.rot_blocks_idx["end"],
117116
)
118117
]
119-
new_increments = [self.small_rotations / t for t in ticks_per_rotation]
118+
new_increments = [
119+
self.degrees_per_small_rotation / t for t in ticks_per_rotation
120+
]
120121

121122
logging.info(f"New increment example: {new_increments[0]:.3f}")
122123

@@ -257,34 +258,6 @@ def plot_rotation_speeds(self):
257258
# rotation pipeline
258259
pass
259260

260-
def save_csv_with_derotation_data(self):
261-
"""Saves a csv file with the rotation angles by line and frame,
262-
and the rotation on signal.
263-
It is saved in the saving folder specified in the config file.
264-
"""
265-
df = pd.DataFrame(
266-
columns=[
267-
"frame",
268-
"rotation_angle",
269-
"clock",
270-
]
271-
)
272-
273-
df["frame"] = np.arange(self.num_frames)
274-
df["rotation_angle"] = self.rot_deg_frame[: self.num_frames]
275-
df["clock"] = self.frame_start[: self.num_frames]
276-
277-
Path(self.config["paths_write"]["derotated_tiff_folder"]).mkdir(
278-
parents=True, exist_ok=True
279-
)
280-
281-
df.to_csv(
282-
self.config["paths_write"]["derotated_tiff_folder"]
283-
+ self.config["paths_write"]["saving_name"]
284-
+ ".csv",
285-
index=False,
286-
)
287-
288261
### ------- Methods unique to IncrementalPipeline ----------------- ###
289262

290263
def find_center_of_rotation(self) -> Tuple[int, int]:

derotation/config/load_config.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ def update_config_paths(
6666
config["paths_write"]["logs_folder"] = str(
6767
Path(output_folder) / "derotation" / "logs"
6868
)
69-
config["paths_write"]["derotated_tiff_folder"] = str(
70-
Path(output_folder) / "derotation/"
71-
)
69+
config["paths_write"]["derotated_tiff_folder"] = str(Path(output_folder))
7270
config["paths_write"]["saving_name"] = (
7371
f"derotated{f'_{folder_suffix}' if folder_suffix else ''}"
7472
)

derotation/derotate_batch.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ def derotate(
5151
Exception
5252
If the pipeline fails.
5353
"""
54-
# FULL DEROTATION PIPELINE
5554
# find tif and bin files
5655
bin_path = list(dataset_folder.rglob(glob_naming_pattern_bin))[0]
5756
tif_path = list(dataset_folder.rglob(glob_naming_pattern_tif))[0]
@@ -67,7 +66,7 @@ def derotate(
6766
folder_suffix=folder_suffix,
6867
)
6968

70-
logging.info("Running full derotation pipeline")
69+
logging.info(f"Running {folder_suffix} derotation pipeline")
7170

7271
# Run the pipeline
7372
try:
@@ -77,7 +76,7 @@ def derotate(
7776
derotator = IncrementalPipeline(config)
7877
derotator()
7978
except Exception as e:
80-
logging.error("Full derotation pipeline failed")
79+
logging.error("Derotation pipeline failed")
8180
logging.error(e.args)
8281
logging.error(traceback.format_exc())
8382
raise e

0 commit comments

Comments
 (0)