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

[pilx] use dynamic masking for diffraction images #2450

Merged
merged 4 commits into from
Feb 21, 2025
Merged
Changes from 3 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
24 changes: 21 additions & 3 deletions src/pyFAI/gui/pilx/MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
__contact__ = "[email protected]"
__license__ = "MIT"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
__date__ = "31/01/2025"
__date__ = "20/02/2025"
__status__ = "development"

from typing import Tuple
Expand All @@ -42,6 +42,7 @@
import logging
import os.path
import posixpath
import numpy
from silx.gui import qt
from silx.gui.colors import Colormap
from silx.image.marchingsquares import find_contours
Expand All @@ -62,6 +63,8 @@
from .widgets.MapPlotWidget import MapPlotWidget
from .widgets.TitleWidget import TitleWidget
from ...io.integration_config import WorkerConfig
from ...utils.mathutil import binning as rebin_fct
from ...detectors import Detector
logger = logging.getLogger(__name__)

class MainWindow(qt.QMainWindow):
Expand Down Expand Up @@ -279,10 +282,25 @@ def displayImageAtIndices(self, indices: ImageIndices):
if maskfile:
mask_image = get_data(url=DataUrl(maskfile))
if mask_image.shape != image.shape:
mask_image = None
binning = [m//i for i, m in zip(image.shape, mask_image.shape)]
if min(binning)<1:
mask_image = None
else:
mask_image = rebin_fct(mask_image, binning)
else:
mask_image = None

detector = self.worker_config.poni.detector
if detector:
detector_mask = detector.mask
if detector.shape != image.shape:
detector.guess_binning(image)
detector_mask = rebin_fct(detector_mask, detector.binning)
if mask_image is None:
mask_image = detector_mask
else:
numpy.logical_or(mask_image, detector_mask, out=mask_image)
detector.mask = mask_image
mask_image = detector.dynamic_mask(image)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these intertwined conditions make the code difficult to parse. I would suggest to move the highlighted part in a separate function (like get_mask_file) and use early returns. That will perhaps help a bit.

image_base = ImageBase(data=image, mask=mask_image)
self._image_plot_widget.setImageData(image_base.getValueData())
self._image_plot_widget.setGraphTitle(f"{posixpath.basename(dataset_path)} #{image_index}")
Expand Down