Skip to content

Commit

Permalink
we should **not** add dependencies for such trivial tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
sarthakpati committed Apr 5, 2024
1 parent 8d97b7f commit 29550a9
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions ereg/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
from ereg.utils.io import read_image_and_cast_to_32bit_float, initialize_configuration
from ereg.utils.metrics import get_ssim

from auxiliary.turbopath import name_extractor


class RegistrationClass:
def __init__(
Expand Down Expand Up @@ -138,10 +136,7 @@ def register(
output_image (str): The output image.
transform_file (str, optional): The transform file. Defaults to None.
"""

if log_file is None:
output_name = name_extractor(output_image)
log_file = output_name + ".log"
log_file = self._get_log_file(output_image, log_file)
self._setup_logger(log_file, "registration")

self.logger.info(f"Target image: {target_image}, Moving image: {moving_image}")
Expand Down Expand Up @@ -231,9 +226,7 @@ def resample_image(
output_image (str): The output image.
transform_file (str, optional): The transform file. Defaults to None.
"""
if log_file is None:
output_name = name_extractor(output_image)
log_file = output_name + ".log"
log_file = self._get_log_file(output_image, log_file)
self._setup_logger(log_file, "resample")

# check if output image exists
Expand Down Expand Up @@ -825,3 +818,11 @@ def _setup_logger(self, log_file: str, logger_type: str) -> None:
console.setLevel(logging.INFO)
# add the handler to the root logger
self.logger.addHandler(console)

def _get_log_file(self, output_image: str, log_file: str = None) -> str:
if log_file is None:
extensions = Path(output_image).suffixes
output_image_base = output_image
for ext in extensions:
output_image_base = output_image_base.replace(ext, "")
log_file = output_image_base + ".log"

0 comments on commit 29550a9

Please sign in to comment.