Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
41 changes: 7 additions & 34 deletions derotation/analysis/incremental_derotation_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

from derotation.analysis.blob_detection import BlobDetection
from derotation.analysis.fit_ellipse import (
Expand All @@ -40,8 +39,10 @@
"""Initialize the IncrementalPipeline object."""
super().__init__(*args, **kwargs)

self.small_rotations = 10
self.number_of_rotations = self.rot_deg // self.small_rotations
self.degrees_per_small_rotation = 10
self.number_of_rotations = (

Check warning on line 43 in derotation/analysis/incremental_derotation_pipeline.py

View check run for this annotation

Codecov / codecov/patch

derotation/analysis/incremental_derotation_pipeline.py#L42-L43

Added lines #L42 - L43 were not covered by tests
self.rot_deg // self.degrees_per_small_rotation
)

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

self.center_of_rotation = self.find_center_of_rotation()

def create_signed_rotation_array(self) -> np.ndarray:
logging.info("Creating signed rotation array...")
rotation_on = np.zeros(self.total_clock_time)
Expand Down Expand Up @@ -116,7 +115,9 @@
self.rot_blocks_idx["end"],
)
]
new_increments = [self.small_rotations / t for t in ticks_per_rotation]
new_increments = [

Check warning on line 118 in derotation/analysis/incremental_derotation_pipeline.py

View check run for this annotation

Codecov / codecov/patch

derotation/analysis/incremental_derotation_pipeline.py#L118

Added line #L118 was not covered by tests
self.degrees_per_small_rotation / t for t in ticks_per_rotation
]

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

Expand Down Expand Up @@ -257,34 +258,6 @@
# rotation pipeline
pass

def save_csv_with_derotation_data(self):
"""Saves a csv file with the rotation angles by line and frame,
and the rotation on signal.
It is saved in the saving folder specified in the config file.
"""
df = pd.DataFrame(
columns=[
"frame",
"rotation_angle",
"clock",
]
)

df["frame"] = np.arange(self.num_frames)
df["rotation_angle"] = self.rot_deg_frame[: self.num_frames]
df["clock"] = self.frame_start[: self.num_frames]

Path(self.config["paths_write"]["derotated_tiff_folder"]).mkdir(
parents=True, exist_ok=True
)

df.to_csv(
self.config["paths_write"]["derotated_tiff_folder"]
+ self.config["paths_write"]["saving_name"]
+ ".csv",
index=False,
)

### ------- Methods unique to IncrementalPipeline ----------------- ###

def find_center_of_rotation(self) -> Tuple[int, int]:
Expand Down
4 changes: 1 addition & 3 deletions derotation/config/load_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ def update_config_paths(
config["paths_write"]["logs_folder"] = str(
Path(output_folder) / "derotation" / "logs"
)
config["paths_write"]["derotated_tiff_folder"] = str(
Path(output_folder) / "derotation/"
)
config["paths_write"]["derotated_tiff_folder"] = str(Path(output_folder))
config["paths_write"]["saving_name"] = (
f"derotated{f'_{folder_suffix}' if folder_suffix else ''}"
)
Expand Down
5 changes: 2 additions & 3 deletions derotation/derotate_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
Exception
If the pipeline fails.
"""
# FULL DEROTATION PIPELINE
# find tif and bin files
bin_path = list(dataset_folder.rglob(glob_naming_pattern_bin))[0]
tif_path = list(dataset_folder.rglob(glob_naming_pattern_tif))[0]
Expand All @@ -67,7 +66,7 @@
folder_suffix=folder_suffix,
)

logging.info("Running full derotation pipeline")
logging.info(f"Running {folder_suffix} derotation pipeline")

Check warning on line 69 in derotation/derotate_batch.py

View check run for this annotation

Codecov / codecov/patch

derotation/derotate_batch.py#L69

Added line #L69 was not covered by tests

# Run the pipeline
try:
Expand All @@ -77,7 +76,7 @@
derotator = IncrementalPipeline(config)
derotator()
except Exception as e:
logging.error("Full derotation pipeline failed")
logging.error("Derotation pipeline failed")

Check warning on line 79 in derotation/derotate_batch.py

View check run for this annotation

Codecov / codecov/patch

derotation/derotate_batch.py#L79

Added line #L79 was not covered by tests
logging.error(e.args)
logging.error(traceback.format_exc())
raise e