Skip to content

Commit f75539d

Browse files
committed
Merge branch 'develop'
# Conflicts: # plotpy/locale/fr/LC_MESSAGES/plotpy.mo # plotpy/locale/fr/LC_MESSAGES/plotpy.po # plotpy/locale/plotpy.pot # plotpy/panels/csection/csitem.py
2 parents 45e4deb + 1ea6ed9 commit f75539d

File tree

94 files changed

+16547
-1843
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+16547
-1843
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@
3838
"plotpy"
3939
],
4040
"python.analysis.autoFormatStrings": true,
41+
"python.analysis.typeCheckingMode": "off",
4142
}

.vscode/tasks.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
"run_pylint.bat",
128128
// "--disable=R0801,C0103,C0114,C0115,C0116,W0612,W0613",
129129
"--disable=fixme,C,R,W",
130+
"--ignore=external",
130131
],
131132
"options": {
132133
"cwd": "scripts",

colormaps/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This directory contains functions and data useful to generate default colormaps used
2+
in Plotpy. Launch `colormap.py` to create/overwrite the colormaps_default.json file.

colormaps/colormap.py

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Licensed under the terms of the BSD 3-Clause
4+
# (see plotpy/LICENSE for details)
5+
6+
# pylint: disable=C0103
7+
8+
"""
9+
Colormap utilities
10+
------------------
11+
12+
"""
13+
14+
from __future__ import annotations
15+
16+
import _cm
17+
import numpy as np
18+
from qtpy import QtGui as QG
19+
from qwt import QwtInterval
20+
21+
from plotpy.mathutils.colormaps import (
22+
DEFAULT_COLORMAPS,
23+
DEFAULT_COLORMAPS_PATH,
24+
save_colormaps,
25+
)
26+
from plotpy.widgets.colormap.widget import EditableColormap # Reuse matplotlib data
27+
28+
# usefull to obtain a full color map
29+
FULLRANGE = QwtInterval(0.0, 1.0)
30+
31+
COLORMAPS = {}
32+
EXTRA_COLORMAPS = [] # custom build colormaps
33+
ICON_CACHE = {}
34+
35+
36+
def _interpolate(val, vmin, vmax):
37+
"""Interpolate a color component between to values as provided
38+
by matplotlib colormaps
39+
"""
40+
interp = (val - vmin[0]) / (vmax[0] - vmin[0])
41+
return (1 - interp) * vmin[1] + interp * vmax[2]
42+
43+
44+
def _setup_colormap(cmap: EditableColormap, cmdata):
45+
"""Setup a CustomQwtLinearColorMap according to
46+
matplotlib's data
47+
"""
48+
red = np.array(cmdata["red"])
49+
green = np.array(cmdata["green"])
50+
blue = np.array(cmdata["blue"])
51+
qmin = QG.QColor()
52+
qmin.setRgbF(red[0, 2], green[0, 2], blue[0, 2])
53+
qmax = QG.QColor()
54+
qmax.setRgbF(red[-1, 2], green[-1, 2], blue[-1, 2])
55+
cmap.setColorInterval(qmin, qmax)
56+
indices = sorted(set(red[:, 0]) | set(green[:, 0]) | set(blue[:, 0]))
57+
for i in indices[1:-1]:
58+
idxr = red[:, 0].searchsorted(i)
59+
idxg = green[:, 0].searchsorted(i)
60+
idxb = blue[:, 0].searchsorted(i)
61+
compr = _interpolate(i, red[idxr - 1], red[idxr])
62+
compg = _interpolate(i, green[idxg - 1], green[idxg])
63+
compb = _interpolate(i, blue[idxb - 1], blue[idxb])
64+
col = QG.QColor()
65+
col.setRgbF(compr, compg, compb)
66+
cmap.addColorStop(i, col)
67+
68+
69+
def get_cmap(name: str) -> EditableColormap:
70+
"""Get a colormap from its name
71+
72+
Args:
73+
name: colormap name
74+
75+
Returns:
76+
Return a QwtColormap based on matplotlib's colormap of the same name
77+
We avoid rebuilding the cmap by keeping it in cache
78+
"""
79+
if name in COLORMAPS:
80+
return COLORMAPS[name]
81+
82+
colormap = EditableColormap()
83+
COLORMAPS[name] = colormap
84+
COLORMAPS[colormap] = name
85+
data = getattr(_cm, "_" + name + "_data")
86+
_setup_colormap(colormap, data)
87+
return colormap
88+
89+
90+
def get_colormap_list() -> list[str]:
91+
"""Builds a list of available colormaps by introspection of the _cm module
92+
93+
Returns:
94+
list of colormap names
95+
"""
96+
cmlist = []
97+
cmlist += EXTRA_COLORMAPS
98+
for name in dir(_cm):
99+
if name.endswith("_data"):
100+
obj = getattr(_cm, name)
101+
if isinstance(obj, dict):
102+
cmlist.append(name[1:-5])
103+
return cmlist
104+
105+
106+
if __name__ == "__main__":
107+
for cmap in get_colormap_list():
108+
DEFAULT_COLORMAPS[cmap] = get_cmap(cmap)
109+
save_colormaps(DEFAULT_COLORMAPS_PATH, DEFAULT_COLORMAPS)

doc/conf.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
# -- Project information -----------------------------------------------------
1111
project = "PlotPy"
12-
copyright = "2018, CEA"
13-
author = "CEA"
12+
copyright = "2023, CEA-Codra"
13+
author = "CEA-Codra"
1414
version = ""
1515
version = ".".join(plotpy.__version__.split(".")[:2])
1616
release = plotpy.__version__
@@ -24,21 +24,15 @@
2424
"sphinx.ext.intersphinx",
2525
"sphinx.ext.napoleon",
2626
"sphinx_qt_documentation",
27+
"sphinx.ext.mathjax",
2728
]
28-
if "htmlhelp" in sys.argv:
29-
extensions += ["sphinx.ext.imgmath"]
30-
else:
31-
extensions += ["sphinx.ext.mathjax"]
3229
templates_path = ["_templates"]
3330
source_suffix = ".rst"
3431
master_doc = "index"
3532
exclude_patterns = []
3633
pygments_style = "sphinx"
3734

38-
if "htmlhelp" in sys.argv:
39-
html_theme = "classic"
40-
else:
41-
html_theme = "python_docs_theme"
35+
html_theme = "python_docs_theme"
4236
html_title = "%s %s Manual" % (project, version)
4337
html_short_title = "%s Manual" % project
4438
html_logo = "images/plotpy-vertical.png"

doc/dev/guiqwt_to_plotpy.csv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
guiqwt v4,plotpy v2,API changes
1+
guiqwt v4,PlotPy v2,API changes
22
``guiqwt.events``,``plotpy.events``
33
``guiqwt.interfaces``,``plotpy.interfaces``
44
``guiqwt.io``,``plotpy.io``
@@ -31,7 +31,7 @@ guiqwt v4,plotpy v2,API changes
3131
``guiqwt.pyplot``,``plotpy.pyplot``
3232
``guiqwt.styles``,``plotpy.styles``
3333
``guiqwt.tools``,``plotpy.tools``
34-
``guiqwt.colormap``,``plotpy.mathutils.colormap``
34+
``guiqwt.colormap``,``plotpy.mathutils.colormaps``
3535
``guiqwt.geometry``,``plotpy.mathutils.geometry``
3636
``guiqwt.qthelpers.exec_image_save_dialog``,``plotpy.widgets.imagefile.exec_image_save_dialog``
3737
``guiqwt.qthelpers.exec_image_open_dialog``,``plotpy.widgets.imagefile.exec_image_open_dialog``

doc/dev/v1_to_guidata_v3.csv

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
plotpy v1,guidata v3
2+
3+
``.gui.dataitems.*``,``.dataset.*``
4+
``.gui.datatypes.*``,``.dataset.*``
5+
``.gui.dataset.qtitemwidgets``,``.dataset.qtitemwidgets``
6+
``.gui.dataset.qtwidgets``,``.dataset.qtwidgets``
7+
``.core.io.hdf5io``,``.dataset.io.h5fmt``
8+
``.core.config.userconfigio``,``.dataset.io.inifmt``
9+
``.core.config.userconfig``,``.userconfig``
10+
``.core.utils.disthelpers``,*removed*

doc/dev/v1_to_v2.csv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
plotpy v1,plotpy v2 (and v1.99+)
1+
plotpy v1,plotpy v2
22

33
``.gui.widgets.interfaces``,``.interfaces``
44
``.gui.widgets.items``,``.items``
@@ -18,7 +18,7 @@ plotpy v1,plotpy v2 (and v1.99+)
1818
``.gui.widgets.histogram.ContrastAdjustment``,``.panels.contrastadjustment.ContrastAdjustment``
1919
``.gui.widgets.io``,``.io``
2020
``.gui.widgets.io.eliminate_outliers``,*removed*
21-
``.gui.widgets.colormap``,``.mathutils.colormap``
21+
``.gui.widgets.colormap``,``.mathutils.colormaps``
2222
``.gui.widgets.debug``,*removed*
2323
``.gui.widgets.debug.buttons_to_str``,``.events.buttons_to_str``
2424
``.gui.widgets.debug.evt_type_to_str``,``.events.evt_type_to_str``

doc/dev/v1_to_v2.rst

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ This section describes the steps to migrate python code using plotpy V1 to plotp
66
Updating the imports
77
^^^^^^^^^^^^^^^^^^^^
88

9-
The following table gives the equivalence between plotpy V1 and plotpy V2 classes.
9+
PlotPy V1 to PlotPy V2
10+
~~~~~~~~~~~~~~~~~~~~~~
11+
12+
The following table gives the equivalence between plotpy V1 and plotpy V2 imports
13+
or objects.
1014

1115
For most of them, the change in the module path is the only difference (only
1216
the import statement have to be updated in your client code). For others, the
@@ -16,6 +20,18 @@ required in your code.
1620
.. csv-table:: Compatibility table
1721
:file: v1_to_v2.csv
1822

23+
PlotPy V1 to guidata V3
24+
~~~~~~~~~~~~~~~~~~~~~~~
25+
26+
With the release of PlotPy V2, the ``DataSet`` related features have been moved
27+
to the `guidata` package (from where they were originally extracted).
28+
29+
The following table gives the equivalence between PlotPy V1 and guidata V3 imports
30+
or objects.
31+
32+
.. csv-table:: Compatibility table
33+
:file: v1_to_guidata_v3.csv
34+
1935
New method for thresholding image item LUTs
2036
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2137

0 commit comments

Comments
 (0)