diff --git a/src/darsia/image/image.py b/src/darsia/image/image.py index bb0ead4b..28f16fea 100644 --- a/src/darsia/image/image.py +++ b/src/darsia/image/image.py @@ -7,9 +7,11 @@ from __future__ import annotations import copy +import logging import math from datetime import datetime, timedelta from pathlib import Path +from time import time as tm from typing import Any, Optional, Union from warnings import warn @@ -24,6 +26,8 @@ import darsia +logger = logging.getLogger(__name__) + class Image: """General image class.""" @@ -185,9 +189,14 @@ def __init__( # NOTE: Require mapping format: darsia.Image -> darsia.Image # May require redefinition of the coordinate system. if transformations is not None: + for transformation in transformations: if transformation is not None and hasattr(transformation, "__call__"): + tic = tm() transformation(self, overwrite=True) + logger.debug( + f"{type(transformation)} transformation applied in {tm() - tic:.3f} s." + ) # ! ---- Safety check on dimensionality and resolution of image. assert len(self.shape) == self.space_dim + self.time_dim + self.range_dim diff --git a/src/darsia/multi_image_analysis/concentrationanalysis.py b/src/darsia/multi_image_analysis/concentrationanalysis.py index a795cd4d..1d54bec0 100644 --- a/src/darsia/multi_image_analysis/concentrationanalysis.py +++ b/src/darsia/multi_image_analysis/concentrationanalysis.py @@ -5,7 +5,9 @@ from __future__ import annotations import copy +import logging from pathlib import Path +from time import time from typing import Optional, Union from warnings import warn @@ -16,6 +18,8 @@ import darsia +logger = logging.getLogger(__name__) + class ConcentrationAnalysis: """Class providing the capabilities to determine concentration/saturation @@ -248,7 +252,11 @@ def __call__(self, img: darsia.Image) -> darsia.Image: probe_img = copy.deepcopy(img) # Remove background image + tic = time() diff = self._subtract_background(probe_img) + logger.debug(f"subtraction: {time() - tic}") + + tic = time() # Provide possibility for tuning and inspection of intermediate results self._inspect_diff(diff) @@ -268,14 +276,20 @@ def __call__(self, img: darsia.Image) -> darsia.Image: # Balance signal (take into account possible heterogeneous effects) balanced_signal = self._balance_signal(clean_signal) + logger.debug(f"processing: {time() - tic}") + # Regularize/upscale signal to Darcy scale and convert from signal to concentration # or other way around. if self.first_restoration_then_model: smooth_signal = self._restore_signal(balanced_signal) concentration = self._convert_signal(smooth_signal, diff) else: + tic = time() nonsmooth_concentration = self._convert_signal(balanced_signal, diff) + logger.debug(f"conversion: {time() - tic}") + tic = time() concentration = self._restore_signal(nonsmooth_concentration) + logger.debug(f"restoration: {time() - tic}") # Invoke plot if self.verbosity >= 1: diff --git a/src/darsia/presets/analysis/multichromatictracer.py b/src/darsia/presets/analysis/multichromatictracer.py index c234d77d..8e3ba144 100644 --- a/src/darsia/presets/analysis/multichromatictracer.py +++ b/src/darsia/presets/analysis/multichromatictracer.py @@ -3,12 +3,15 @@ """ +import logging from typing import Optional import numpy as np import darsia +logger = logging.getLogger(__name__) + class MultichromaticTracerAnalysis(darsia.ConcentrationAnalysis): """Multichomratic concentration analysis tailored to labeled media. @@ -108,8 +111,14 @@ def __call__(self, image: darsia.Image) -> darsia.Image: Image: concentration map """ + from time import time + + tic = time() concentration = super().__call__(image) + logger.debug(f"concentration call: {time() - tic}") + tic = time() self.expert_knowledge(concentration) + logger.debug(f"expert knowledge - concentration: {time() - tic}") return concentration # ! ---- SAVE AND LOAD ----