Skip to content

Commit

Permalink
warn if TV weight is large (#83)
Browse files Browse the repository at this point in the history
* warn if weight is large

* update settings @alisiafadini feedback
  • Loading branch information
tjlane authored Nov 20, 2024
1 parent 7a5ae55 commit 84da814
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion meteor/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@

# tv denoising
TV_WEIGHT_DEFAULT: float = 0.01
BRACKET_FOR_GOLDEN_OPTIMIZATION: tuple[float, float] = (0.0, 0.05)
BRACKET_FOR_GOLDEN_OPTIMIZATION: tuple[float, float] = (0.0, 0.01) # the braket can expand
TV_MAX_WEIGHT_EXPECTED = 0.1 # this value sets the threshold for a warning to the user
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 84da814

Please sign in to comment.