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

silx.gui.colors: Add "percentile" mode for autoscaling #4154

Merged
merged 6 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 4 additions & 1 deletion src/silx/gui/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,10 @@ class Colormap(qt.QObject):
"""constant for autoscale using mean +/- 3*std(data)
with a clamp on min/max of the data"""

AUTOSCALE_MODES = (MINMAX, STDDEV3)
PERCENTILE_1_99 = "percentile_1_99"
"""constant for autoscale using 1st and 99th percentile of data"""

AUTOSCALE_MODES = (MINMAX, STDDEV3, PERCENTILE_1_99)
"""Tuple of managed auto scale algorithms"""

sigChanged = qt.Signal()
Expand Down
1 change: 1 addition & 0 deletions src/silx/gui/dialog/ColormapDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ class _AutoscaleModeComboBox(qt.QComboBox):
DATA = {
Colormap.MINMAX: ("Min/max", "Use the data min/max"),
Colormap.STDDEV3: ("Mean±3std", "Use the data mean ± 3 × standard deviation"),
Colormap.PERCENTILE_1_99: ("Percentile 1-99", "Use 1st to 99th percentile of data"),
}

def __init__(self, parent: qt.QWidget):
Expand Down
3 changes: 3 additions & 0 deletions src/silx/math/colormap.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ def autoscale(self, data, mode):
vmax = dmax
else:
vmax = min(dmax, stdmax)
elif mode == "percentile_1_99":
vmin = numpy.nanpercentile(data, 1)
vmax = numpy.nanpercentile(data, 99)

else:
raise ValueError("Unsupported mode: %s" % mode)
Expand Down