Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce logging #381

Merged
merged 3 commits into from
Nov 22, 2024
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
9 changes: 9 additions & 0 deletions src/darsia/image/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -24,6 +26,8 @@

import darsia

logger = logging.getLogger(__name__)


class Image:
"""General image class."""
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions src/darsia/multi_image_analysis/concentrationanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -16,6 +18,8 @@

import darsia

logger = logging.getLogger(__name__)


class ConcentrationAnalysis:
"""Class providing the capabilities to determine concentration/saturation
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions src/darsia/presets/analysis/multichromatictracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 ----
Expand Down
Loading