Skip to content

Commit

Permalink
warn if weight is large
Browse files Browse the repository at this point in the history
  • Loading branch information
tjlane committed Nov 15, 2024
1 parent f9c1762 commit 834cce6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions meteor/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
# tv denoising
TV_WEIGHT_DEFAULT: float = 0.01
BRACKET_FOR_GOLDEN_OPTIMIZATION: tuple[float, float] = (0.0, 0.05)
TV_MAX_WEIGHT_EXPECTED = 1.0
TV_STOP_TOLERANCE: float = 0.00000005 # inner loop; not for iterative-tv phase retrieval
TV_MAX_NUM_ITER: int = 50 # inner loop; not for iterative-tv phase retrieval

Expand Down
11 changes: 11 additions & 0 deletions meteor/tv.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@
from typing import Literal, overload

import numpy as np
import structlog
from skimage.restoration import denoise_tv_chambolle

from .rsmap import Map
from .settings import (
BRACKET_FOR_GOLDEN_OPTIMIZATION,
MAP_SAMPLING,
TV_MAX_NUM_ITER,
TV_MAX_WEIGHT_EXPECTED,
TV_STOP_TOLERANCE,
)
from .validate import ScalarMaximizer, negentropy

log = structlog.get_logger()


@dataclass
class TvDenoiseResult:
Expand Down Expand Up @@ -177,6 +181,13 @@ def negentropy_objective(tv_weight: float) -> float:
else:
maximizer.optimize_with_golden_algorithm(bracket=BRACKET_FOR_GOLDEN_OPTIMIZATION)

if maximizer.argument_optimum > TV_MAX_WEIGHT_EXPECTED:
log.warning(
"TV regularization weight much larger than expected, something probably went wrong",
weight=maximizer.argument_optimum,
limit=TV_MAX_WEIGHT_EXPECTED,
)

# denoise using the optimized parameters and convert to an rs.DataSet
final_realspace_map_as_array = _tv_denoise_array(
map_as_array=realspace_map_array,
Expand Down

0 comments on commit 834cce6

Please sign in to comment.