Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ movie_config:

# --- Beam mask estimation parameters ---
beam_mask_config:
threshold_method: "otsu" # (optional, default "otsu") Thresholding algorithm for binarising the low-pass-filtered frame sum. Only "otsu" is currently supported.
threshold_method: "sobel" # (optional, default "sobel") Ellipse fit method; only "sobel" (outermost Sobel edge along rays from the beam center; robust to dark sample at the rim) is currently supported.
diameter_reduction: 0.0 # (optional, default 0.0) Fractional shrink applied to both ellipse radii; 0.1 shrinks each axis by 10% to exclude fringe artifacts at the beam edge.
low_pass_resolution: 100.0 # (optional, default 100.0) Low-pass filter cutoff (Angstroms) applied to the frame sum before thresholding.
working_pixel_size: 8.0 # (optional, default 8.0) Approximate pixel size (Angstroms) the frame sum is binned to before edge detection.
edge_smoothing_sigma: 120.0 # (optional, default 120.0) Gaussian smoothing sigma (Angstroms) applied before edge detection.

# --- Output file configuration ---
output_config:
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ dependencies = [
"h5py",
"dm4",
"opencv-python-headless",
"scikit-image",
]

# https://peps.python.org/pep-0621/#dependencies-optional-dependencies
Expand Down
33 changes: 24 additions & 9 deletions src/ripple/config/beam_mask_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Literal

import torch
from pydantic import PositiveFloat
from teamtomo_basemodel import BaseModelTeamTomo

from ripple.config.crop_bounds_config import CropBoundsConfig
Expand All @@ -15,24 +16,30 @@ class BeamMaskConfig(BaseModelTeamTomo):

Parameters
----------
threshold_method: Literal["otsu"]
Thresholding algorithm used to binarise the low-pass-filtered frame sum.
Currently only ``"otsu"`` is supported. Default is ``"otsu"``.
threshold_method: Literal["sobel"]
Method used to fit the beam ellipse to the frame sum. ``"sobel"`` fits the
ellipse to the outermost Sobel edge along rays cast from the beam center, and is
robust to dark sample lying across the beam rim. Currently only ``"sobel"`` is
supported. Default is ``"sobel"``.
diameter_reduction: float
Fractional amount by which both ellipse radii are shrunk before creating the
final mask. ``0.0`` applies no reduction; ``0.1`` shrinks each axis by 10% to
exclude fringe artifacts at the beam edge. Default is 0.0.
low_pass_resolution: float
Low-pass filter cutoff, in Angstroms, applied to the frame sum before
thresholding. Default is 100.0.
working_pixel_size: float
Approximate pixel size, in Angstroms, the frame sum is binned to before edge
detection. Default is 8.0.
edge_smoothing_sigma: float
Standard deviation, in Angstroms, of the Gaussian smoothing applied to the
binned frame sum before edge detection. Default is 120.0.
crop_bounds_config: CropBoundsConfig
Size policy for cropping movie frames down to the region covered by the beam
mask. Default disables cropping (``mode="none"``).
"""

threshold_method: Literal["otsu"] = "otsu"
threshold_method: Literal["sobel"] = "sobel"
diameter_reduction: float = 0.0
low_pass_resolution: float = 100.0
working_pixel_size: PositiveFloat = 8.0
edge_smoothing_sigma: PositiveFloat = 120.0
crop_bounds_config: CropBoundsConfig = CropBoundsConfig()


Expand Down Expand Up @@ -80,9 +87,15 @@ class BeamMaskResult(BaseModelTeamTomo):
output_crop_max_x: int
Right column of the output crop region, inclusive.
threshold_method: str
Thresholding algorithm used to binarise the filtered frame sum.
Method used to fit the beam ellipse (``"sobel"``).
pixel_size: float
Pixel size in Angstroms per pixel.
n_edge_points: int
Number of beam-edge points found (at most one per ray cast).
n_inliers: int
Number of edge points kept as beam-rim inliers.
``n_inliers / ripple.core.beam_mask.DEFAULT_N_RAYS`` is the fraction of the
rim that was found.
"""

center_y: float
Expand All @@ -103,6 +116,8 @@ class BeamMaskResult(BaseModelTeamTomo):
output_crop_max_x: int
threshold_method: str
pixel_size: float
n_edge_points: int
n_inliers: int

@property
def crop_bounds(self) -> CropBounds:
Expand Down
8 changes: 7 additions & 1 deletion src/ripple/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
"""Core functions for RIPPLE."""

from .beam_mask import estimate_beam_mask, make_ellipse_mask, sum_movie_chunked
from .beam_mask import (
estimate_beam_mask,
fit_beam_edge,
make_ellipse_mask,
sum_movie_chunked,
)
from .core_optimize_sigmas import core_optimize_sigmas
from .core_polish_particles import core_polish_particles
from .crop_bounds import crop_movie, determine_crop_bounds, get_crop_bounds
Expand All @@ -13,6 +18,7 @@
"crop_movie",
"determine_crop_bounds",
"estimate_beam_mask",
"fit_beam_edge",
"fourier_crop_movie",
"generate_dose_weighted_image",
"get_crop_bounds",
Expand Down
Loading
Loading