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 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
47 changes: 38 additions & 9 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 @@ -240,6 +243,39 @@ def displayPatternAtIndices(self,
self._integrated_plot_widget.setGraphXLabel(point._x_name)
self._integrated_plot_widget.setGraphYLabel(point._y_name)

def getMask(self, image, maskfile=None):
"""returns a 2D array of boolean with invalid pixels masked,
combination of Detector mask, static & dynamic mask.
Handles detector/mask image binning on the fly

:param image: 2D array image with data, used for dynamic masking
:param maskfile: filename or URL pointing to a static mask
:return: 2D array
"""
if maskfile:
mask_image = get_data(url=DataUrl(maskfile))
if mask_image.shape != image.shape:
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)
return mask_image

def displayImageAtIndices(self, indices: ImageIndices):
if self._file_name is None:
return
Expand Down Expand Up @@ -276,14 +312,7 @@ def displayImageAtIndices(self, indices: ImageIndices):
else:
maskfile = None

if maskfile:
mask_image = get_data(url=DataUrl(maskfile))
if mask_image.shape != image.shape:
mask_image = None
else:
mask_image = None

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

Expand Down