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

Common default colormap #2277

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
27 changes: 10 additions & 17 deletions src/pyFAI/app/drawmask.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__ = "21/05/2024"
__date__ = "17/09/2024"
__satus__ = "Production"

import os
Expand All @@ -42,6 +42,8 @@
logging.basicConfig(level=logging.INFO)
logging.captureWarnings(True)
logger = logging.getLogger(__name__)
from argparse import ArgumentParser

try:
import hdf5plugin # noqa
except ImportError:
Expand All @@ -51,8 +53,9 @@

import silx.gui.plot
from silx.gui import qt
import pyFAI.utils
from argparse import ArgumentParser
from ..version import version as pyFAI_version, date as pyFAI_date
from .. import utils
from ..gui.utils.colorutils import DEFAULT_COLORMAP


class AbstractMaskImageWidget(qt.QMainWindow):
Expand Down Expand Up @@ -104,17 +107,7 @@ def __init__(self):
maskAction = self.__plot2D.getMaskAction()
maskAction.setVisible(False)
self.__maskPanel = silx.gui.plot.MaskToolsWidget.MaskToolsWidget(plot=self.__plot2D)
try:
colormap = {
'name': "inferno",
'normalization': 'log',
'autoscale': True,
'vmax': None,
'vmin': None,
}
self.__plot2D.setDefaultColormap(colormap)
except Exception:
logger.error("Impossible to change the default colormap. Source code not compatible.", exc_info=True)
self.__plot2D.setDefaultColormap(DEFAULT_COLORMAP)
self.__maskPanel.setDirection(qt.QBoxLayout.TopToBottom)
self.__maskPanel.setMultipleMasks("single")

Expand Down Expand Up @@ -157,7 +150,7 @@ def postProcessId21(processFile, mask):

def main():
usage = "pyFAI-drawmask file1.edf file2.edf ..."
version = "pyFAI-average version %s from %s" % (pyFAI.version, pyFAI.date)
version = f"pyFAI-average version {pyFAI_version} from {pyFAI_date}"
description = """
Draw a mask, i.e. an image containing the list of pixels which are considered invalid
(no scintillator, module gap, beam stop shadow, ...).
Expand All @@ -169,15 +162,15 @@ def main():
Optionally the script will print the number of pixel masked
and the intensity masked (as well on other files provided in input)"""
parser = ArgumentParser(usage=usage, description=description, epilog=epilog)
parser.add_argument("-v", "--version", action='version', version=version)
parser.add_argument("-v", "--version", action='version', version=pyFAI_version)
parser.add_argument("args", metavar='FILE', type=str, nargs='+',
help="Files to be processed")

options = parser.parse_args()
if len(options.args) < 1:
parser.error("Incorrect number of arguments: please provide an image to draw a mask")

processFile = pyFAI.utils.expand_args(options.args)
processFile = utils.expand_args(options.args)

app = qt.QApplication([])

Expand Down
4 changes: 2 additions & 2 deletions src/pyFAI/gui/CalibrationContext.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

__authors__ = ["V. Valls"]
__license__ = "MIT"
__date__ = "16/05/2019"
__date__ = "17/09/2024"

import logging
import numpy
Expand Down Expand Up @@ -71,7 +71,7 @@ def __init__(self, settings=None):
self.__defaultColormapDialog = None
CalibrationContext.__instance = self
self.__calibrationModel = None
self.__rawColormap = Colormap("inferno", normalization=Colormap.LOGARITHM)
self.__rawColormap = colorutils.DEFAULT_COLORMAP
self.__settings = settings
self.__angleUnit = DataModel()
self.__angleUnit.setValue(units.Unit.RADIAN)
Expand Down
8 changes: 4 additions & 4 deletions src/pyFAI/gui/IntegrationDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
__contact__ = "[email protected]"
__license__ = "MIT"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
__date__ = "05/09/2023"
__date__ = "17/09/2024"
__status__ = "development"

import logging
Expand All @@ -57,7 +57,8 @@
from ..utils import get_ui_file
from ..app import integrate
from .. import containers
from pyFAI.gui.utils.eventutils import QtProxifier
from .utils.eventutils import QtProxifier
from .utils.colorutils import DEFAULT_COLORMAP


class _ThreadSafeIntegrationProcess(QtProxifier):
Expand Down Expand Up @@ -148,13 +149,12 @@ def computeLocation(result):
self._plot.setGraphXLabel("Radial")
self._plot.setGraphYLabel("Azimuthal")
origin, scale = computeLocation(result)
colormap = colors.Colormap("inferno", normalization=colors.Colormap.LOGARITHM)
self._plot.addImage(
legend="result2d",
data=result.intensity,
origin=origin,
scale=scale,
colormap=colormap,
colormap=DEFAULT_COLORMAP,
resetzoom=False)
else:
logger.error("Unsupported result type %s", type(result))
Expand Down
6 changes: 3 additions & 3 deletions src/pyFAI/gui/dialog/Detector3dDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

__authors__ = ["V. Valls"]
__license__ = "MIT"
__date__ = "17/12/2021"
__date__ = "17/09/2024"

import numpy
import time
Expand All @@ -38,7 +38,7 @@
from silx.gui import qt
from silx.gui.plot3d.items import mesh
from silx.gui.plot3d.SceneWindow import SceneWindow
from silx.gui import colors
from ..utils.colorutils import DEFAULT_COLORMAP


class CreateSceneThread(qt.QThread):
Expand Down Expand Up @@ -144,7 +144,7 @@ def __createDetectorColormapMesh(self):

colormap = self.__colormap
if colormap is None:
colormap = colors.Colormap(name="inferno", normalization=colors.Colormap.LOGARITHM)
colormap = DEFAULT_COLORMAP

item = mesh.ColormapMesh()
item.moveToThread(qt.QApplication.instance().thread())
Expand Down
5 changes: 4 additions & 1 deletion src/pyFAI/gui/matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

__authors__ = ["T. Vincent"]
__license__ = "MIT"
__date__ = "15/10/2021"
__date__ = "17/09/2024"

import sys
import logging
Expand Down Expand Up @@ -76,3 +76,6 @@ def _configure(backend, backend_qt4=None, check=False):
from matplotlib import pyplot # noqa
from matplotlib import pylab # noqa
from matplotlib import colors

#differs from the silx one (no normalization)
DEFAULT_MPL_COLORMAP = colors.Colormap(name="inferno")
4 changes: 1 addition & 3 deletions src/pyFAI/gui/pilx/widgets/DiffractionImagePlotWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,13 @@

import numpy
from silx.gui.plot.items import ImageData
from silx.gui.colors import Colormap

from .ImagePlotWidget import ImagePlotWidget
from ..models import ROI_COLOR, ImageIndices
from ...utils.colorutils import DEFAULT_COLORMAP

_LEGEND = "IMAGE"

DEFAULT_COLORMAP = Colormap(name="viridis") # TODO: grab the colormap from the application default


class DiffractionImagePlotWidget(ImagePlotWidget):

Expand Down
5 changes: 4 additions & 1 deletion src/pyFAI/gui/utils/colorutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@

__authors__ = ["V. Valls"]
__license__ = "MIT"
__date__ = "16/10/2020"
__date__ = "17/09/2024"

from silx.gui import qt
from silx.gui.colors import Colormap


DEFAULT_COLORMAP = Colormap(name="inferno", normalization=Colormap.ARCSINH)


def getFreeColorRange(colormap):
"""
Returns a list of 10 colors in range not covered by colormap.
Expand Down