wolfhece 2.1.38__py3-none-any.whl → 2.1.40__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- wolfhece/PyPalette.py +297 -268
- wolfhece/apps/splashscreen.py +2 -2
- wolfhece/apps/version.py +1 -1
- wolfhece/libs/wolfogl.cp310-win_amd64.pyd +0 -0
- wolfhece/pyviews.py +80 -18
- wolfhece/wolf_array.py +23 -4
- wolfhece/wolfresults_2D.py +19 -10
- {wolfhece-2.1.38.dist-info → wolfhece-2.1.40.dist-info}/METADATA +1 -1
- {wolfhece-2.1.38.dist-info → wolfhece-2.1.40.dist-info}/RECORD +12 -12
- {wolfhece-2.1.38.dist-info → wolfhece-2.1.40.dist-info}/WHEEL +0 -0
- {wolfhece-2.1.38.dist-info → wolfhece-2.1.40.dist-info}/entry_points.txt +0 -0
- {wolfhece-2.1.38.dist-info → wolfhece-2.1.40.dist-info}/top_level.txt +0 -0
wolfhece/PyPalette.py
CHANGED
@@ -16,7 +16,7 @@ import numpy as np
|
|
16
16
|
import numpy.ma as ma
|
17
17
|
from bisect import bisect_left
|
18
18
|
import matplotlib.pyplot as plt
|
19
|
-
from matplotlib.colors import LinearSegmentedColormap,Normalize
|
19
|
+
from matplotlib.colors import LinearSegmentedColormap, Normalize
|
20
20
|
from collections import OrderedDict
|
21
21
|
import typing
|
22
22
|
import io
|
@@ -26,53 +26,54 @@ from .PyTranslate import _
|
|
26
26
|
from .CpGrid import CpGrid
|
27
27
|
from .PyVertex import getRGBfromI, getIfromRGB
|
28
28
|
|
29
|
-
|
29
|
+
|
30
|
+
class wolfpalette(wx.Frame, LinearSegmentedColormap):
|
30
31
|
"""
|
31
32
|
Palette de couleurs basée sur l'objet "LinearSegmentedColormap" de Matplotlib (Colormap objects based on lookup tables using linear segments)
|
32
33
|
"""
|
33
|
-
filename:str
|
34
|
-
nb:int
|
35
|
-
colors:np.array
|
36
|
-
colorsflt:np.array
|
37
|
-
colorsuint8:np.array
|
34
|
+
filename: str
|
35
|
+
nb: int
|
36
|
+
colors: np.array
|
37
|
+
colorsflt: np.array
|
38
|
+
colorsuint8: np.array
|
38
39
|
|
39
|
-
def __init__(self, parent=None, title=_('Colormap'),w=100,h=500,nseg=1024):
|
40
|
+
def __init__(self, parent=None, title=_('Colormap'), w=100, h=500, nseg=1024):
|
40
41
|
|
41
|
-
self.filename=''
|
42
|
+
self.filename = ''
|
42
43
|
self.nb = 0
|
43
44
|
self.values = None
|
44
|
-
self.colormin = np.array([1.,1.,1.,1.])
|
45
|
-
self.colormax = np.array([0,0,0,1.])
|
46
|
-
self.nseg=nseg
|
45
|
+
self.colormin = np.array([1., 1., 1., 1.])
|
46
|
+
self.colormax = np.array([0, 0, 0, 1.])
|
47
|
+
self.nseg = nseg
|
47
48
|
self.automatic = True
|
48
49
|
self.interval_cst = False
|
49
50
|
|
50
51
|
self.wx_exists = wx.App.Get() is not None
|
51
52
|
|
52
|
-
#Appel à l'initialisation d'un frame général
|
53
|
-
if(self.wx_exists):
|
54
|
-
wx.Frame.__init__(self, parent, title=title, size=(w,h),style=wx.DEFAULT_FRAME_STYLE)
|
53
|
+
# Appel à l'initialisation d'un frame général
|
54
|
+
if (self.wx_exists):
|
55
|
+
wx.Frame.__init__(self, parent, title=title, size=(w, h), style=wx.DEFAULT_FRAME_STYLE)
|
55
56
|
|
56
|
-
LinearSegmentedColormap.__init__(self,'wolf',{},nseg)
|
57
|
+
LinearSegmentedColormap.__init__(self, 'wolf', {}, nseg)
|
57
58
|
self.set_bounds()
|
58
59
|
|
59
60
|
@property
|
60
61
|
def colormin_uint8(self):
|
61
62
|
return self.colormin.astype(np.uint8)*255
|
62
|
-
|
63
|
+
|
63
64
|
@property
|
64
65
|
def colormax_uint8(self):
|
65
66
|
return self.colormax.astype(np.uint8)*255
|
66
67
|
|
67
68
|
def get_colors_f32(self):
|
68
69
|
|
69
|
-
colors = self.colorsflt[
|
70
|
+
colors = self.colorsflt[:, :3].astype(np.float32)
|
70
71
|
|
71
72
|
return colors
|
72
|
-
|
73
|
+
|
73
74
|
def get_colors_uint8(self):
|
74
|
-
|
75
|
-
colors = self.colorsflt[
|
75
|
+
|
76
|
+
colors = self.colorsflt[:, :3].astype(np.uint8) * 255
|
76
77
|
|
77
78
|
return colors
|
78
79
|
|
@@ -80,66 +81,71 @@ class wolfpalette(wx.Frame,LinearSegmentedColormap):
|
|
80
81
|
self.set_under(tuple(self.colormin))
|
81
82
|
self.set_over(tuple(self.colormax))
|
82
83
|
|
83
|
-
def get_rgba(self, x:np.ndarray):
|
84
|
+
def get_rgba(self, x: np.ndarray):
|
84
85
|
"""Récupération de la couleur en fonction de la valeur x"""
|
85
86
|
|
86
|
-
dval=self.values[-1]-self.values[0]
|
87
|
-
if dval==0.:
|
88
|
-
dval=1.
|
87
|
+
dval = self.values[-1]-self.values[0]
|
88
|
+
if dval == 0.:
|
89
|
+
dval = 1.
|
89
90
|
xloc = (x-self.values[0])/dval
|
90
91
|
|
91
92
|
if self.interval_cst:
|
92
|
-
rgba = np.ones((xloc.shape[0],xloc.shape[1],4), dtype=np.uint8)
|
93
|
+
rgba = np.ones((xloc.shape[0], xloc.shape[1], 4), dtype=np.uint8)
|
93
94
|
|
94
|
-
ij = np.where(xloc<0.)
|
95
|
-
rgba[ij[0],ij[1]] = self.colormin_uint8
|
96
|
-
ij = np.where(xloc>=1.)
|
97
|
-
rgba[ij[0],ij[1]] = self.colormax_uint8
|
95
|
+
ij = np.where(xloc < 0.)
|
96
|
+
rgba[ij[0], ij[1]] = self.colormin_uint8
|
97
|
+
ij = np.where(xloc >= 1.)
|
98
|
+
rgba[ij[0], ij[1]] = self.colormax_uint8
|
98
99
|
|
99
100
|
for i in range(self.nb-1):
|
100
101
|
val1 = (self.values[i]-self.values[0])/dval
|
101
102
|
val2 = (self.values[i+1]-self.values[0])/dval
|
102
103
|
# c1 = self.colorsflt[i]
|
103
|
-
c1
|
104
|
-
ij = np.where((xloc>=val1) & (xloc<val2))
|
105
|
-
rgba[ij[0],ij[1]] = c1
|
104
|
+
c1 = self.colorsuint8[i]
|
105
|
+
ij = np.where((xloc >= val1) & (xloc < val2))
|
106
|
+
rgba[ij[0], ij[1]] = c1
|
106
107
|
|
107
108
|
return rgba
|
108
109
|
else:
|
109
110
|
return self(xloc, bytes=True)
|
110
111
|
|
111
|
-
def export_palette_matplotlib(self,name):
|
112
|
+
def export_palette_matplotlib(self, name):
|
112
113
|
cmaps = OrderedDict()
|
113
114
|
cmaps['Perceptually Uniform Sequential'] = ['viridis', 'plasma', 'inferno', 'magma', 'cividis']
|
114
115
|
|
115
|
-
cmaps['Sequential'] = ['Greys', 'Purples', 'Blues', 'Greens', 'Oranges', 'Reds','YlOrBr',
|
116
|
-
|
117
|
-
cmaps['
|
116
|
+
cmaps['Sequential'] = ['Greys', 'Purples', 'Blues', 'Greens', 'Oranges', 'Reds', 'YlOrBr',
|
117
|
+
'YlOrRd', 'OrRd', 'PuRd', 'RdPu', 'BuPu', 'GnBu', 'PuBu', 'YlGnBu', 'PuBuGn', 'BuGn', 'YlGn']
|
118
|
+
cmaps['Sequential (2)'] = ['binary', 'gist_yarg', 'gist_gray', 'gray', 'bone', 'pink', 'spring',
|
119
|
+
'summer', 'autumn', 'winter', 'cool', 'Wistia', 'hot', 'afmhot', 'gist_heat', 'copper']
|
120
|
+
cmaps['Diverging'] = ['PiYG', 'PRGn', 'BrBG', 'PuOr', 'RdGy', 'RdBu',
|
121
|
+
'RdYlBu', 'RdYlGn', 'Spectral', 'coolwarm', 'bwr', 'seismic']
|
118
122
|
cmaps['Cyclic'] = ['twilight', 'twilight_shifted', 'hsv']
|
119
|
-
cmaps['Qualitative'] = ['Pastel1', 'Pastel2', 'Paired', 'Accent',
|
120
|
-
|
123
|
+
cmaps['Qualitative'] = ['Pastel1', 'Pastel2', 'Paired', 'Accent',
|
124
|
+
'Dark2', 'Set1', 'Set2', 'Set3', 'tab10', 'tab20', 'tab20b', 'tab20c']
|
125
|
+
cmaps['Miscellaneous'] = ['flag', 'prism', 'ocean', 'gist_earth', 'terrain', 'gist_stern', 'gnuplot',
|
126
|
+
'gnuplot2', 'CMRmap', 'cubehelix', 'brg', 'gist_rainbow', 'rainbow', 'jet', 'nipy_spectral', 'gist_ncar']
|
121
127
|
|
122
128
|
for cmap_category, cmap_list in cmaps.items():
|
123
|
-
if(name in cmaps[cmap_category]):
|
124
|
-
self=plt.get_cmap(name)
|
125
|
-
self.nb=len(self._segmentdata['blue'])
|
126
|
-
self.values = np.linspace(0.,1.,self.nb)
|
127
|
-
self.colorsflt = np.zeros((self.nb,4)
|
129
|
+
if (name in cmaps[cmap_category]):
|
130
|
+
self = plt.get_cmap(name)
|
131
|
+
self.nb = len(self._segmentdata['blue'])
|
132
|
+
self.values = np.linspace(0., 1., self.nb, dtype=np.float64)
|
133
|
+
self.colorsflt = np.zeros((self.nb, 4), dtype=np.float64)
|
128
134
|
for i in range(self.nb):
|
129
|
-
self.colorsflt[i,0]=self._segmentdata['red'][i][2]
|
130
|
-
self.colorsflt[i,1]=self._segmentdata['green'][i][2]
|
131
|
-
self.colorsflt[i,2]=self._segmentdata['blue'][i][2]
|
132
|
-
self.colorsflt[i,3]=self._segmentdata['alpha'][i][2]
|
133
|
-
test=1
|
135
|
+
self.colorsflt[i, 0] = self._segmentdata['red'][i][2]
|
136
|
+
self.colorsflt[i, 1] = self._segmentdata['green'][i][2]
|
137
|
+
self.colorsflt[i, 2] = self._segmentdata['blue'][i][2]
|
138
|
+
self.colorsflt[i, 3] = self._segmentdata['alpha'][i][2]
|
139
|
+
test = 1
|
134
140
|
break
|
135
141
|
else:
|
136
|
-
test=1
|
142
|
+
test = 1
|
143
|
+
|
144
|
+
return self.nb, self.values, self._segmentdata, self.colorsflt
|
137
145
|
|
138
|
-
|
146
|
+
def distribute_values(self, minval: float = -99999, maxval: float = -99999, step=0, wx_permitted=True):
|
147
|
+
""" Distribution des valeurs de la palette
|
139
148
|
|
140
|
-
def distribute_values(self, minval:float=-99999, maxval:float=-99999, step=0, wx_permitted=True):
|
141
|
-
""" Distribution des valeurs de la palette
|
142
|
-
|
143
149
|
:param minval: valeur minimale
|
144
150
|
:param maxval: valeur maximale
|
145
151
|
:param step: pas de distribution
|
@@ -149,31 +155,32 @@ class wolfpalette(wx.Frame,LinearSegmentedColormap):
|
|
149
155
|
"""
|
150
156
|
|
151
157
|
if self.wx_exists and wx_permitted:
|
152
|
-
if minval
|
153
|
-
dlg = wx.TextEntryDialog(None, _('Minimum value'), value
|
158
|
+
if minval == -99999:
|
159
|
+
dlg = wx.TextEntryDialog(None, _('Minimum value'), value=str(self.values[0]))
|
154
160
|
ret = dlg.ShowModal()
|
155
161
|
self.values[0] = dlg.GetValue()
|
156
162
|
dlg.Destroy()
|
157
163
|
else:
|
158
164
|
self.values[0] = minval
|
159
165
|
|
160
|
-
if maxval
|
166
|
+
if maxval == -99999 and step == 0:
|
161
167
|
|
162
|
-
dlg = wx.MessageDialog(None, _('Would you like to set the incremental step value ?'),
|
168
|
+
dlg = wx.MessageDialog(None, _('Would you like to set the incremental step value ?'),
|
169
|
+
style=wx.YES_NO | wx.YES_DEFAULT)
|
163
170
|
ret = dlg.ShowModal()
|
164
171
|
dlg.Destroy
|
165
172
|
if ret == wx.ID_YES:
|
166
|
-
dlg = wx.TextEntryDialog(None, _('Step value'), value
|
173
|
+
dlg = wx.TextEntryDialog(None, _('Step value'), value='1')
|
167
174
|
ret = dlg.ShowModal()
|
168
175
|
step = float(dlg.GetValue())
|
169
176
|
dlg.Destroy()
|
170
177
|
else:
|
171
|
-
dlg = wx.TextEntryDialog(None, _('Maximum value'), value
|
178
|
+
dlg = wx.TextEntryDialog(None, _('Maximum value'), value=str(self.values[-1]))
|
172
179
|
ret = dlg.ShowModal()
|
173
180
|
self.values[-1] = float(dlg.GetValue())
|
174
181
|
dlg.Destroy()
|
175
|
-
|
176
|
-
elif maxval
|
182
|
+
|
183
|
+
elif maxval != -99999:
|
177
184
|
self.values[-1] = maxval
|
178
185
|
else:
|
179
186
|
if minval != -99999:
|
@@ -181,34 +188,35 @@ class wolfpalette(wx.Frame,LinearSegmentedColormap):
|
|
181
188
|
if maxval != -99999:
|
182
189
|
self.values[-1] = maxval
|
183
190
|
|
184
|
-
if step==0:
|
185
|
-
self.values = np.linspace(self.values[0], self.values[-1], num=self.nb,
|
191
|
+
if step == 0:
|
192
|
+
self.values = np.linspace(self.values[0], self.values[-1], num=self.nb,
|
193
|
+
endpoint=True, dtype=np.float64)[0:self.nb]
|
186
194
|
else:
|
187
|
-
self.values = np.arange(self.values[0], self.values[0]+(self.nb)*step, step)[0:self.nb]
|
195
|
+
self.values = np.arange(self.values[0], self.values[0]+(self.nb)*step, step, dtype=np.float64)[0:self.nb]
|
188
196
|
|
189
197
|
self.fill_segmentdata()
|
190
198
|
|
191
|
-
def export_image(self,fn='',h_or_v:typing.Literal['h','v',''] ='', figax
|
199
|
+
def export_image(self, fn='', h_or_v: typing.Literal['h', 'v', ''] = '', figax=None):
|
192
200
|
"""
|
193
201
|
Export image from colormap
|
194
202
|
|
195
203
|
:param : fn : filepath or io.BytesIO()
|
196
204
|
:param : h_or_v : configuration to save 'h' = horizontal, 'v' = vertical, '' = both
|
197
205
|
"""
|
198
|
-
if fn=='':
|
199
|
-
file=wx.FileDialog(None,"Choose .pal file", wildcard="png (*.png)|*.png|all (*.*)|*.*",style=wx.FD_SAVE)
|
206
|
+
if fn == '':
|
207
|
+
file = wx.FileDialog(None, "Choose .pal file", wildcard="png (*.png)|*.png|all (*.*)|*.*", style=wx.FD_SAVE)
|
200
208
|
if file.ShowModal() == wx.ID_CANCEL:
|
201
209
|
return
|
202
210
|
else:
|
203
|
-
#récupération du nom de fichier avec chemin d'accès
|
204
|
-
fn =file.GetPath()
|
211
|
+
# récupération du nom de fichier avec chemin d'accès
|
212
|
+
fn = file.GetPath()
|
205
213
|
|
206
|
-
if h_or_v=='v':
|
214
|
+
if h_or_v == 'v':
|
207
215
|
if figax is None:
|
208
|
-
fig,ax=plt.subplots(1,1)
|
216
|
+
fig, ax = plt.subplots(1, 1)
|
209
217
|
else:
|
210
|
-
fig,ax = figax
|
211
|
-
plt.colorbar(ScalarMappable(Normalize(self.values[0],self.values[-1]),cmap=self),
|
218
|
+
fig, ax = figax
|
219
|
+
plt.colorbar(ScalarMappable(Normalize(self.values[0], self.values[-1]), cmap=self),
|
212
220
|
cax=ax,
|
213
221
|
orientation='vertical',
|
214
222
|
extend='both',
|
@@ -218,29 +226,29 @@ class wolfpalette(wx.Frame,LinearSegmentedColormap):
|
|
218
226
|
format='%.3f')
|
219
227
|
plt.tick_params(labelsize=14)
|
220
228
|
if figax is None:
|
221
|
-
fig.set_size_inches((2,10))
|
229
|
+
fig.set_size_inches((2, 10))
|
222
230
|
fig.tight_layout()
|
223
231
|
|
224
|
-
if fn!='' and fn is not None:
|
232
|
+
if fn != '' and fn is not None:
|
225
233
|
plt.savefig(fn, format='png')
|
226
234
|
# plt.savefig(fn,bbox_inches='tight', format='png')
|
227
|
-
elif h_or_v=='h':
|
235
|
+
elif h_or_v == 'h':
|
228
236
|
if figax is None:
|
229
|
-
fig,ax=plt.subplots(1,1)
|
237
|
+
fig, ax = plt.subplots(1, 1)
|
230
238
|
else:
|
231
|
-
fig,ax = figax
|
232
|
-
plt.colorbar(ScalarMappable(Normalize(self.values[0],self.values[-1]),cmap=self),
|
239
|
+
fig, ax = figax
|
240
|
+
plt.colorbar(ScalarMappable(Normalize(self.values[0], self.values[-1]), cmap=self),
|
233
241
|
cax=ax,
|
234
242
|
orientation='horizontal',
|
235
243
|
extend='both',
|
236
244
|
spacing='proportional',
|
237
245
|
ticks=self.values,
|
238
246
|
format='%.3f')
|
239
|
-
plt.tick_params(labelsize=14,rotation=45)
|
247
|
+
plt.tick_params(labelsize=14, rotation=45)
|
240
248
|
if figax is None:
|
241
|
-
fig.set_size_inches((2,10))
|
249
|
+
fig.set_size_inches((2, 10))
|
242
250
|
fig.tight_layout()
|
243
|
-
if fn!='' and fn is not None:
|
251
|
+
if fn != '' and fn is not None:
|
244
252
|
plt.savefig(fn, format='png')
|
245
253
|
# plt.savefig(fn,bbox_inches='tight', format='png')
|
246
254
|
else:
|
@@ -249,10 +257,10 @@ class wolfpalette(wx.Frame,LinearSegmentedColormap):
|
|
249
257
|
return
|
250
258
|
|
251
259
|
if figax is None:
|
252
|
-
fig,ax=plt.subplots(1,1)
|
260
|
+
fig, ax = plt.subplots(1, 1)
|
253
261
|
else:
|
254
|
-
fig,ax = figax
|
255
|
-
plt.colorbar(ScalarMappable(Normalize(self.values[0],self.values[-1]),cmap=self),
|
262
|
+
fig, ax = figax
|
263
|
+
plt.colorbar(ScalarMappable(Normalize(self.values[0], self.values[-1]), cmap=self),
|
256
264
|
cax=ax,
|
257
265
|
orientation='vertical',
|
258
266
|
extend='both',
|
@@ -260,117 +268,117 @@ class wolfpalette(wx.Frame,LinearSegmentedColormap):
|
|
260
268
|
ticks=self.values,
|
261
269
|
format='%.3f')
|
262
270
|
plt.tick_params(labelsize=14)
|
263
|
-
fig.set_size_inches((2,10))
|
271
|
+
fig.set_size_inches((2, 10))
|
264
272
|
fig.tight_layout()
|
265
|
-
if fn!='' and fn is not None:
|
273
|
+
if fn != '' and fn is not None:
|
266
274
|
plt.savefig(fn[:-4]+'_v.png', format='png')
|
267
275
|
|
268
276
|
if figax is None:
|
269
|
-
fig,ax=plt.subplots(1,1)
|
277
|
+
fig, ax = plt.subplots(1, 1)
|
270
278
|
else:
|
271
|
-
fig,ax = figax
|
279
|
+
fig, ax = figax
|
272
280
|
|
273
|
-
plt.colorbar(ScalarMappable(Normalize(self.values[0],self.values[-1]),cmap=self),
|
281
|
+
plt.colorbar(ScalarMappable(Normalize(self.values[0], self.values[-1]), cmap=self),
|
274
282
|
cax=ax,
|
275
283
|
orientation='horizontal',
|
276
284
|
extend='both',
|
277
285
|
spacing='proportional',
|
278
286
|
ticks=self.values,
|
279
287
|
format='%.3f')
|
280
|
-
plt.tick_params(labelsize=14,rotation=45)
|
281
|
-
fig.set_size_inches((10,2))
|
288
|
+
plt.tick_params(labelsize=14, rotation=45)
|
289
|
+
fig.set_size_inches((10, 2))
|
282
290
|
fig.tight_layout()
|
283
|
-
if fn!='' and fn is not None:
|
291
|
+
if fn != '' and fn is not None:
|
284
292
|
plt.savefig(fn[:-4]+'_h.png', format='png')
|
285
293
|
|
286
|
-
return fig,ax
|
294
|
+
return fig, ax
|
287
295
|
|
288
|
-
def plot(self,fig:Figure,ax:plt.Axes):
|
296
|
+
def plot(self, fig: Figure, ax: plt.Axes):
|
289
297
|
gradient = np.linspace(0, 1, 256)
|
290
298
|
gradient = np.vstack((gradient, gradient))
|
291
299
|
ax.imshow(gradient, aspect='auto', cmap=self)
|
292
300
|
ax.set_yticklabels([])
|
293
301
|
|
294
|
-
pos=[]
|
295
|
-
txt=[]
|
302
|
+
pos = []
|
303
|
+
txt = []
|
296
304
|
|
297
|
-
dval=(self.values[-1]-self.values[0])
|
298
|
-
if dval==0.:
|
299
|
-
dval=1.
|
305
|
+
dval = (self.values[-1]-self.values[0])
|
306
|
+
if dval == 0.:
|
307
|
+
dval = 1.
|
300
308
|
|
301
309
|
for curval in self.values:
|
302
310
|
pos.append((curval-self.values[0])/dval*256.)
|
303
311
|
txt.append("{0:.3f}".format(curval))
|
304
312
|
|
305
313
|
ax.set_xticks(pos)
|
306
|
-
ax.set_xticklabels(txt,rotation=30,fontsize=6)
|
314
|
+
ax.set_xticklabels(txt, rotation=30, fontsize=6)
|
307
315
|
|
308
|
-
def fillgrid(self,gridto:CpGrid):
|
309
|
-
gridto.SetColLabelValue(0,'Value')
|
310
|
-
gridto.SetColLabelValue(1,'R')
|
311
|
-
gridto.SetColLabelValue(2,'G')
|
312
|
-
gridto.SetColLabelValue(3,'B')
|
316
|
+
def fillgrid(self, gridto: CpGrid):
|
317
|
+
gridto.SetColLabelValue(0, 'Value')
|
318
|
+
gridto.SetColLabelValue(1, 'R')
|
319
|
+
gridto.SetColLabelValue(2, 'G')
|
320
|
+
gridto.SetColLabelValue(3, 'B')
|
313
321
|
|
314
|
-
nb=gridto.GetNumberRows()
|
315
|
-
if len(self.values)-nb>0:
|
322
|
+
nb = gridto.GetNumberRows()
|
323
|
+
if len(self.values)-nb > 0:
|
316
324
|
gridto.AppendRows(len(self.values)-nb)
|
317
325
|
|
318
|
-
k=0
|
319
|
-
for curv,rgba in zip(self.values,self.colors):
|
320
|
-
gridto.SetCellValue(k,0,str(curv))
|
321
|
-
gridto.SetCellValue(k,1,str(rgba[0]))
|
322
|
-
gridto.SetCellValue(k,2,str(rgba[1]))
|
323
|
-
gridto.SetCellValue(k,3,str(rgba[2]))
|
324
|
-
k+=1
|
326
|
+
k = 0
|
327
|
+
for curv, rgba in zip(self.values, self.colors):
|
328
|
+
gridto.SetCellValue(k, 0, str(curv))
|
329
|
+
gridto.SetCellValue(k, 1, str(rgba[0]))
|
330
|
+
gridto.SetCellValue(k, 2, str(rgba[1]))
|
331
|
+
gridto.SetCellValue(k, 3, str(rgba[2]))
|
332
|
+
k += 1
|
325
333
|
|
326
334
|
nb = gridto.GetNumberRows()
|
327
|
-
while k<nb:
|
328
|
-
gridto.SetCellValue(k,0,'')
|
329
|
-
gridto.SetCellValue(k,1,'')
|
330
|
-
gridto.SetCellValue(k,2,'')
|
331
|
-
gridto.SetCellValue(k,3,'')
|
332
|
-
k+=1
|
335
|
+
while k < nb:
|
336
|
+
gridto.SetCellValue(k, 0, '')
|
337
|
+
gridto.SetCellValue(k, 1, '')
|
338
|
+
gridto.SetCellValue(k, 2, '')
|
339
|
+
gridto.SetCellValue(k, 3, '')
|
340
|
+
k += 1
|
333
341
|
|
334
|
-
def updatefromgrid(self,gridfrom:CpGrid):
|
335
|
-
nbl=gridfrom.GetNumberRows()
|
342
|
+
def updatefromgrid(self, gridfrom: CpGrid):
|
343
|
+
nbl = gridfrom.GetNumberRows()
|
336
344
|
|
337
345
|
for i in range(nbl):
|
338
|
-
if gridfrom.GetCellValue(i,0) =='':
|
339
|
-
nbl=i-1
|
346
|
+
if gridfrom.GetCellValue(i, 0) == '':
|
347
|
+
nbl = i-1
|
340
348
|
break
|
341
349
|
|
342
350
|
if i < self.nb:
|
343
351
|
self.nb = i
|
344
|
-
self.values=self.values[0:i]
|
345
|
-
self.colors=self.colors[0:i
|
352
|
+
self.values = self.values[0:i]
|
353
|
+
self.colors = self.colors[0:i, :]
|
346
354
|
else:
|
347
355
|
self.nb = i
|
348
356
|
oldvalues = self.values
|
349
357
|
oldcolors = self.colors
|
350
|
-
self.values = np.zeros(self.nb
|
351
|
-
self.colors = np.zeros((self.nb,4)
|
358
|
+
self.values = np.zeros(self.nb, dtype=np.float64)
|
359
|
+
self.colors = np.zeros((self.nb, 4), dtype=int)
|
352
360
|
self.values[0:len(oldvalues)] = oldvalues
|
353
|
-
self.colors[0:len(oldcolors)
|
361
|
+
self.colors[0:len(oldcolors), :] = oldcolors
|
354
362
|
|
355
363
|
update = False
|
356
364
|
|
357
365
|
for k in range(self.nb):
|
358
366
|
|
359
|
-
update = update or self.values[k]!=float(gridfrom.GetCellValue(k,0))
|
360
|
-
update = update or self.colors[k,0]!=float(gridfrom.GetCellValue(k,1))
|
361
|
-
update = update or self.colors[k,1]!=float(gridfrom.GetCellValue(k,2))
|
362
|
-
update = update or self.colors[k,2]!=float(gridfrom.GetCellValue(k,3))
|
367
|
+
update = update or self.values[k] != float(gridfrom.GetCellValue(k, 0))
|
368
|
+
update = update or self.colors[k, 0] != float(gridfrom.GetCellValue(k, 1))
|
369
|
+
update = update or self.colors[k, 1] != float(gridfrom.GetCellValue(k, 2))
|
370
|
+
update = update or self.colors[k, 2] != float(gridfrom.GetCellValue(k, 3))
|
363
371
|
|
364
|
-
self.values[k]=float(gridfrom.GetCellValue(k,0))
|
365
|
-
self.colors[k,0]=int(gridfrom.GetCellValue(k,1))
|
366
|
-
self.colors[k,1]=int(gridfrom.GetCellValue(k,2))
|
367
|
-
self.colors[k,2]=int(gridfrom.GetCellValue(k,3))
|
372
|
+
self.values[k] = float(gridfrom.GetCellValue(k, 0))
|
373
|
+
self.colors[k, 0] = int(gridfrom.GetCellValue(k, 1))
|
374
|
+
self.colors[k, 1] = int(gridfrom.GetCellValue(k, 2))
|
375
|
+
self.colors[k, 2] = int(gridfrom.GetCellValue(k, 3))
|
368
376
|
|
369
377
|
self.fill_segmentdata()
|
370
378
|
|
371
379
|
return update
|
372
380
|
|
373
|
-
def updatefrompalette(self,srcpal):
|
381
|
+
def updatefrompalette(self, srcpal):
|
374
382
|
"""
|
375
383
|
Mise à jour de la palette sur base d'une autre
|
376
384
|
|
@@ -378,131 +386,152 @@ class wolfpalette(wx.Frame,LinearSegmentedColormap):
|
|
378
386
|
"""
|
379
387
|
|
380
388
|
for k in range(len(srcpal.values)):
|
381
|
-
self.values[k]=srcpal.values[k]
|
389
|
+
self.values[k] = srcpal.values[k]
|
382
390
|
|
383
391
|
self.fill_segmentdata()
|
384
392
|
|
385
|
-
def lookupcolor(self,x):
|
386
|
-
if x < self.values[0]:
|
387
|
-
|
393
|
+
def lookupcolor(self, x):
|
394
|
+
if x < self.values[0]:
|
395
|
+
return wx.Colour(self.colormin)
|
396
|
+
if x > self.values[-1]:
|
397
|
+
return wx.Colour(self.colormax)
|
388
398
|
|
389
399
|
i = bisect_left(self.values, x)
|
390
400
|
k = (x - self.values[i-1])/(self.values[i] - self.values[i-1])
|
391
401
|
|
392
|
-
r=int(k*(float(self.colors[i,0]-self.colors[i-1,0]))) + self.colors[i-1,0]
|
393
|
-
g=int(k*(float(self.colors[i,1]-self.colors[i-1,1]))) + self.colors[i-1,1]
|
394
|
-
b=int(k*(float(self.colors[i,2]-self.colors[i-1,2]))) + self.colors[i-1,2]
|
395
|
-
a=int(k*(float(self.colors[i,3]-self.colors[i-1,3]))) + self.colors[i-1,3]
|
402
|
+
r = int(k*(float(self.colors[i, 0]-self.colors[i-1, 0]))) + self.colors[i-1, 0]
|
403
|
+
g = int(k*(float(self.colors[i, 1]-self.colors[i-1, 1]))) + self.colors[i-1, 1]
|
404
|
+
b = int(k*(float(self.colors[i, 2]-self.colors[i-1, 2]))) + self.colors[i-1, 2]
|
405
|
+
a = int(k*(float(self.colors[i, 3]-self.colors[i-1, 3]))) + self.colors[i-1, 3]
|
396
406
|
|
397
|
-
y = wx.Colour(r,g,b,a)
|
407
|
+
y = wx.Colour(r, g, b, a)
|
398
408
|
|
399
409
|
return y
|
400
410
|
|
401
|
-
def lookupcolorflt(self,x):
|
402
|
-
if x < self.values[0]:
|
403
|
-
|
411
|
+
def lookupcolorflt(self, x):
|
412
|
+
if x < self.values[0]:
|
413
|
+
return wx.Colour(self.colormin)
|
414
|
+
if x > self.values[-1]:
|
415
|
+
return wx.Colour(self.colormax)
|
404
416
|
|
405
417
|
i = bisect_left(self.values, x)
|
406
418
|
k = (x - self.values[i-1])/(self.values[i] - self.values[i-1])
|
407
419
|
|
408
|
-
r=k*(self.colorsflt[i,0]-self.colorsflt[i-1,0]) + self.colorsflt[i-1,0]
|
409
|
-
g=k*(self.colorsflt[i,1]-self.colorsflt[i-1,1]) + self.colorsflt[i-1,1]
|
410
|
-
b=k*(self.colorsflt[i,2]-self.colorsflt[i-1,2]) + self.colorsflt[i-1,2]
|
411
|
-
a=k*(self.colorsflt[i,3]-self.colorsflt[i-1,3]) + self.colorsflt[i-1,3]
|
420
|
+
r = k*(self.colorsflt[i, 0]-self.colorsflt[i-1, 0]) + self.colorsflt[i-1, 0]
|
421
|
+
g = k*(self.colorsflt[i, 1]-self.colorsflt[i-1, 1]) + self.colorsflt[i-1, 1]
|
422
|
+
b = k*(self.colorsflt[i, 2]-self.colorsflt[i-1, 2]) + self.colorsflt[i-1, 2]
|
423
|
+
a = k*(self.colorsflt[i, 3]-self.colorsflt[i-1, 3]) + self.colorsflt[i-1, 3]
|
412
424
|
|
413
|
-
y=[r,g,b,a]
|
425
|
+
y = [r, g, b, a]
|
414
426
|
return y
|
415
427
|
|
416
|
-
def lookupcolorrgb(self,x):
|
417
|
-
if x < self.values[0]:
|
418
|
-
|
428
|
+
def lookupcolorrgb(self, x):
|
429
|
+
if x < self.values[0]:
|
430
|
+
return wx.Colour(self.colormin)
|
431
|
+
if x > self.values[-1]:
|
432
|
+
return wx.Colour(self.colormax)
|
419
433
|
|
420
434
|
i = bisect_left(self.values, x)
|
421
435
|
k = (x - self.values[i-1])/(self.values[i] - self.values[i-1])
|
422
436
|
|
423
|
-
r=int(k*(float(self.colors[i,0]-self.colors[i-1,0]))) + self.colors[i-1,0]
|
424
|
-
g=int(k*(float(self.colors[i,1]-self.colors[i-1,1]))) + self.colors[i-1,1]
|
425
|
-
b=int(k*(float(self.colors[i,2]-self.colors[i-1,2]))) + self.colors[i-1,2]
|
426
|
-
a=int(k*(float(self.colors[i,3]-self.colors[i-1,3]))) + self.colors[i-1,3]
|
437
|
+
r = int(k*(float(self.colors[i, 0]-self.colors[i-1, 0]))) + self.colors[i-1, 0]
|
438
|
+
g = int(k*(float(self.colors[i, 1]-self.colors[i-1, 1]))) + self.colors[i-1, 1]
|
439
|
+
b = int(k*(float(self.colors[i, 2]-self.colors[i-1, 2]))) + self.colors[i-1, 2]
|
440
|
+
a = int(k*(float(self.colors[i, 3]-self.colors[i-1, 3]))) + self.colors[i-1, 3]
|
427
441
|
|
428
|
-
return r,g,b,a
|
442
|
+
return r, g, b, a
|
429
443
|
|
430
444
|
def default16(self):
|
431
445
|
"""Palette 16 coulrurs par défaut dans WOLF"""
|
432
446
|
|
433
|
-
self.nb=16
|
434
|
-
self.values = np.linspace(0.,1.,16)
|
435
|
-
self.colors = np.zeros((self.nb,4)
|
436
|
-
self.colorsflt = np.zeros((self.nb,4)
|
437
|
-
|
438
|
-
self.colors[0
|
439
|
-
self.colors[1
|
440
|
-
self.colors[2
|
441
|
-
self.colors[3
|
442
|
-
self.colors[4
|
443
|
-
self.colors[5
|
444
|
-
self.colors[6
|
445
|
-
self.colors[7
|
446
|
-
self.colors[8
|
447
|
-
self.colors[9
|
448
|
-
self.colors[10
|
449
|
-
self.colors[11
|
450
|
-
self.colors[12
|
451
|
-
self.colors[13
|
452
|
-
self.colors[14
|
453
|
-
self.colors[15
|
447
|
+
self.nb = 16
|
448
|
+
self.values = np.linspace(0., 1., 16, dtype=np.float64)
|
449
|
+
self.colors = np.zeros((self.nb, 4), dtype=int)
|
450
|
+
self.colorsflt = np.zeros((self.nb, 4), dtype=np.float64)
|
451
|
+
|
452
|
+
self.colors[0, :] = [128, 255, 255, 255]
|
453
|
+
self.colors[1, :] = [89, 172, 255, 255]
|
454
|
+
self.colors[2, :] = [72, 72, 255, 255]
|
455
|
+
self.colors[3, :] = [0, 0, 255, 255]
|
456
|
+
self.colors[4, :] = [0, 128, 0, 255]
|
457
|
+
self.colors[5, :] = [0, 221, 55, 255]
|
458
|
+
self.colors[6, :] = [128, 255, 128, 255]
|
459
|
+
self.colors[7, :] = [255, 255, 0, 255]
|
460
|
+
self.colors[8, :] = [255, 128, 0, 255]
|
461
|
+
self.colors[9, :] = [235, 174, 63, 255]
|
462
|
+
self.colors[10, :] = [255, 0, 0, 255]
|
463
|
+
self.colors[11, :] = [209, 71, 12, 255]
|
464
|
+
self.colors[12, :] = [128, 0, 0, 255]
|
465
|
+
self.colors[13, :] = [185, 0, 0, 255]
|
466
|
+
self.colors[14, :] = [111, 111, 111, 255]
|
467
|
+
self.colors[15, :] = [192, 192, 192, 255]
|
454
468
|
|
455
469
|
self.fill_segmentdata()
|
456
470
|
|
457
471
|
def set_values_colors(self,
|
458
|
-
values:typing.Union[list[float], np.ndarray],
|
459
|
-
colors:typing.Union[list[tuple[int]], np.ndarray]):
|
472
|
+
values: typing.Union[list[float], np.ndarray],
|
473
|
+
colors: typing.Union[list[tuple[int]], np.ndarray]):
|
460
474
|
""" Mise à jour des valeurs et couleurs de la palette """
|
461
475
|
|
462
476
|
assert len(values) == len(colors), "Length of values and colors must be the same"
|
463
477
|
assert len(values) > 1, "At least 2 values are required"
|
464
|
-
assert len(colors[0]) in [3,4], "Colors must be in RGB or RGBA format"
|
478
|
+
assert len(colors[0]) in [3, 4], "Colors must be in RGB or RGBA format"
|
465
479
|
|
466
480
|
self.nb = len(values)
|
467
|
-
self.values = np.asarray(values)
|
481
|
+
self.values = np.asarray(values, dtype=np.float64)
|
468
482
|
|
469
|
-
self.colors = np.zeros((self.nb,4)
|
470
|
-
self.colorsflt = np.zeros((self.nb,4)
|
483
|
+
self.colors = np.zeros((self.nb, 4), dtype=int)
|
484
|
+
self.colorsflt = np.zeros((self.nb, 4), dtype=np.float64)
|
471
485
|
|
472
486
|
if isinstance(colors, list):
|
473
487
|
if len(colors[0]) == 3:
|
474
488
|
for curcol in range(self.nb):
|
475
|
-
self.colors[curcol,0] = colors[curcol][0]
|
476
|
-
self.colors[curcol,1] = colors[curcol][1]
|
477
|
-
self.colors[curcol,2] = colors[curcol][2]
|
478
|
-
self.colors[curcol,3] = 255
|
489
|
+
self.colors[curcol, 0] = colors[curcol][0]
|
490
|
+
self.colors[curcol, 1] = colors[curcol][1]
|
491
|
+
self.colors[curcol, 2] = colors[curcol][2]
|
492
|
+
self.colors[curcol, 3] = 255
|
479
493
|
elif len(colors[0]) == 4:
|
480
494
|
for curcol in range(self.nb):
|
481
|
-
self.colors[curcol,0] = colors[curcol][0]
|
482
|
-
self.colors[curcol,1] = colors[curcol][1]
|
483
|
-
self.colors[curcol,2] = colors[curcol][2]
|
484
|
-
self.colors[curcol,3] = colors[curcol][3]
|
495
|
+
self.colors[curcol, 0] = colors[curcol][0]
|
496
|
+
self.colors[curcol, 1] = colors[curcol][1]
|
497
|
+
self.colors[curcol, 2] = colors[curcol][2]
|
498
|
+
self.colors[curcol, 3] = colors[curcol][3]
|
485
499
|
elif isinstance(colors, np.ndarray):
|
486
500
|
if colors.shape[1] == 3:
|
487
501
|
for curcol in range(self.nb):
|
488
|
-
self.colors[curcol,0] = colors[curcol,0]
|
489
|
-
self.colors[curcol,1] = colors[curcol,1]
|
490
|
-
self.colors[curcol,2] = colors[curcol,2]
|
491
|
-
self.colors[curcol,3] = 255
|
502
|
+
self.colors[curcol, 0] = colors[curcol, 0]
|
503
|
+
self.colors[curcol, 1] = colors[curcol, 1]
|
504
|
+
self.colors[curcol, 2] = colors[curcol, 2]
|
505
|
+
self.colors[curcol, 3] = 255
|
492
506
|
elif colors.shape[1] == 4:
|
493
507
|
for curcol in range(self.nb):
|
494
|
-
self.colors[curcol,0] = colors[curcol,0]
|
495
|
-
self.colors[curcol,1] = colors[curcol,1]
|
496
|
-
self.colors[curcol,2] = colors[curcol,2]
|
497
|
-
self.colors[curcol,3] = colors[curcol,3]
|
498
|
-
|
508
|
+
self.colors[curcol, 0] = colors[curcol, 0]
|
509
|
+
self.colors[curcol, 1] = colors[curcol, 1]
|
510
|
+
self.colors[curcol, 2] = colors[curcol, 2]
|
511
|
+
self.colors[curcol, 3] = colors[curcol, 3]
|
512
|
+
|
499
513
|
self.fill_segmentdata()
|
500
514
|
|
501
515
|
def defaultgray(self):
|
502
516
|
"""Palette grise par défaut dans WOLF"""
|
503
|
-
|
504
|
-
self.
|
505
|
-
self.
|
517
|
+
|
518
|
+
self.nb = 2
|
519
|
+
self.values = np.asarray([0., 1.], dtype=np.float64)
|
520
|
+
self.colors = np.asarray([[0, 0, 0, 255], [255, 255, 255, 255]], dtype=np.int32)
|
521
|
+
|
522
|
+
# self.nb = 11
|
523
|
+
# self.values = np.asarray([0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.], dtype=np.float64)
|
524
|
+
# self.colors = np.asarray([[0, 0, 0, 255],
|
525
|
+
# [22, 22, 22, 255],
|
526
|
+
# [44, 44, 44, 255],
|
527
|
+
# [66, 66, 66, 255],
|
528
|
+
# [88, 88, 88, 255],
|
529
|
+
# [110, 110, 110, 255],
|
530
|
+
# [132, 132, 132, 255],
|
531
|
+
# [154, 154, 154, 255],
|
532
|
+
# [176, 176, 176, 255],
|
533
|
+
# [198, 198, 198, 255],
|
534
|
+
# [255, 255, 255, 255]], dtype=np.int32)
|
506
535
|
|
507
536
|
self.fill_segmentdata()
|
508
537
|
|
@@ -512,89 +541,89 @@ class wolfpalette(wx.Frame,LinearSegmentedColormap):
|
|
512
541
|
self.colorsflt = self.colors.astype(float)/255.
|
513
542
|
self.colorsuint8 = self.colors.astype(np.uint8)
|
514
543
|
|
515
|
-
dval=self.values[-1]-self.values[0]
|
544
|
+
dval = self.values[-1]-self.values[0]
|
516
545
|
|
517
546
|
normval = np.ones([len(self.values)])
|
518
547
|
|
519
|
-
if dval>0.:
|
548
|
+
if dval > 0.:
|
520
549
|
normval = (self.values-self.values[0])/(self.values[-1]-self.values[0])
|
521
550
|
|
522
|
-
normval[0]=0.
|
523
|
-
normval[-1]=1.
|
524
|
-
segmentdata = {"red": np.column_stack([normval, self.colorsflt[:,0], self.colorsflt[:,0]]),
|
525
|
-
|
526
|
-
|
527
|
-
|
551
|
+
normval[0] = 0.
|
552
|
+
normval[-1] = 1.
|
553
|
+
segmentdata = {"red": np.column_stack([normval, self.colorsflt[:, 0], self.colorsflt[:, 0]]),
|
554
|
+
"green": np.column_stack([normval, self.colorsflt[:, 1], self.colorsflt[:, 1]]),
|
555
|
+
"blue": np.column_stack([normval, self.colorsflt[:, 2], self.colorsflt[:, 2]]),
|
556
|
+
"alpha": np.column_stack([normval, self.colorsflt[:, 3], self.colorsflt[:, 3]])}
|
528
557
|
|
529
|
-
LinearSegmentedColormap.__init__(self,'wolf',segmentdata,self.nseg)
|
558
|
+
LinearSegmentedColormap.__init__(self, 'wolf', segmentdata, self.nseg)
|
530
559
|
|
531
|
-
def readfile(self
|
560
|
+
def readfile(self, *args):
|
532
561
|
"""Lecture de la palette sur base d'un fichier WOLF .pal"""
|
533
|
-
if len(args)>0:
|
534
|
-
#s'il y a un argument on le prend tel quel
|
562
|
+
if len(args) > 0:
|
563
|
+
# s'il y a un argument on le prend tel quel
|
535
564
|
self.filename = str(args[0])
|
536
565
|
else:
|
537
566
|
if self.wx_exists:
|
538
|
-
#ouverture d'une boîte de dialogue
|
539
|
-
file=wx.FileDialog(None,"Choose .pal file", wildcard="pal (*.pal)|*.pal|all (*.*)|*.*")
|
567
|
+
# ouverture d'une boîte de dialogue
|
568
|
+
file = wx.FileDialog(None, "Choose .pal file", wildcard="pal (*.pal)|*.pal|all (*.*)|*.*")
|
540
569
|
if file.ShowModal() == wx.ID_CANCEL:
|
541
570
|
file.Destroy()
|
542
571
|
return
|
543
572
|
else:
|
544
|
-
#récuparétaion du nom de fichier avec chemin d'accès
|
545
|
-
self.filename =file.GetPath()
|
573
|
+
# récuparétaion du nom de fichier avec chemin d'accès
|
574
|
+
self.filename = file.GetPath()
|
546
575
|
file.Destroy()
|
547
576
|
else:
|
548
577
|
return
|
549
578
|
|
550
|
-
#lecture du contenu
|
579
|
+
# lecture du contenu
|
551
580
|
with open(self.filename, 'r') as myfile:
|
552
|
-
#split des lignes --> récupération des infos sans '\n' en fin de ligne
|
581
|
+
# split des lignes --> récupération des infos sans '\n' en fin de ligne
|
553
582
|
# différent de .readlines() qui lui ne supprime pas les '\n'
|
554
583
|
mypallines = myfile.read().splitlines()
|
555
584
|
myfile.close()
|
556
585
|
|
557
586
|
self.nb = int(mypallines[0])
|
558
|
-
self.values = np.zeros(self.nb
|
559
|
-
self.colors = np.zeros((self.nb,4)
|
587
|
+
self.values = np.zeros(self.nb, dtype=np.float64)
|
588
|
+
self.colors = np.zeros((self.nb, 4), dtype=int)
|
560
589
|
|
561
590
|
for i in range(self.nb):
|
562
591
|
self.values[i] = mypallines[i*4+1]
|
563
|
-
self.colors[i,0] = mypallines[i*4+2]
|
564
|
-
self.colors[i,1] = mypallines[i*4+3]
|
565
|
-
self.colors[i,2] = mypallines[i*4+4]
|
566
|
-
self.colors[i,3] = 255
|
592
|
+
self.colors[i, 0] = mypallines[i*4+2]
|
593
|
+
self.colors[i, 1] = mypallines[i*4+3]
|
594
|
+
self.colors[i, 2] = mypallines[i*4+4]
|
595
|
+
self.colors[i, 3] = 255
|
567
596
|
|
568
597
|
self.fill_segmentdata()
|
569
598
|
|
570
|
-
def savefile(self
|
599
|
+
def savefile(self, *args):
|
571
600
|
"""Lecture de la palette sur base d'un fichier WOLF .pal"""
|
572
|
-
if len(args)>0:
|
573
|
-
#s'il y a un argument on le prend tel quel
|
601
|
+
if len(args) > 0:
|
602
|
+
# s'il y a un argument on le prend tel quel
|
574
603
|
fn = str(args[0])
|
575
604
|
else:
|
576
|
-
#ouverture d'une boîte de dialogue
|
577
|
-
file=wx.FileDialog(None,"Choose .pal file", wildcard="pal (*.pal)|*.pal|all (*.*)|*.*",style=wx.FD_SAVE)
|
605
|
+
# ouverture d'une boîte de dialogue
|
606
|
+
file = wx.FileDialog(None, "Choose .pal file", wildcard="pal (*.pal)|*.pal|all (*.*)|*.*", style=wx.FD_SAVE)
|
578
607
|
if file.ShowModal() == wx.ID_CANCEL:
|
579
608
|
return
|
580
609
|
else:
|
581
|
-
#récuparétaion du nom de fichier avec chemin d'accès
|
582
|
-
fn =file.GetPath()
|
610
|
+
# récuparétaion du nom de fichier avec chemin d'accès
|
611
|
+
fn = file.GetPath()
|
583
612
|
|
584
|
-
self.filename=fn
|
613
|
+
self.filename = fn
|
585
614
|
|
586
|
-
#lecture du contenu
|
615
|
+
# lecture du contenu
|
587
616
|
with open(self.filename, 'w') as myfile:
|
588
|
-
#split des lignes --> récupération des infos sans '\n' en fin de ligne
|
617
|
+
# split des lignes --> récupération des infos sans '\n' en fin de ligne
|
589
618
|
# différent de .readlines() qui lui ne supprime pas les '\n'
|
590
619
|
myfile.write(str(self.nb)+'\n')
|
591
620
|
for i in range(self.nb):
|
592
621
|
myfile.write(str(self.values[i])+'\n')
|
593
|
-
myfile.write(str(self.colors[i,0])+'\n')
|
594
|
-
myfile.write(str(self.colors[i,1])+'\n')
|
595
|
-
myfile.write(str(self.colors[i,2])+'\n')
|
622
|
+
myfile.write(str(self.colors[i, 0])+'\n')
|
623
|
+
myfile.write(str(self.colors[i, 1])+'\n')
|
624
|
+
myfile.write(str(self.colors[i, 2])+'\n')
|
596
625
|
|
597
|
-
def isopop(self, array: ma.masked_array, nbnotnull:int=99999):
|
626
|
+
def isopop(self, array: ma.masked_array, nbnotnull: int = 99999):
|
598
627
|
"""Remplissage des valeurs de palette sur base d'une équirépartition de valeurs"""
|
599
628
|
|
600
629
|
sortarray = array.flatten(order='F')
|
@@ -607,7 +636,7 @@ class wolfpalette(wx.Frame,LinearSegmentedColormap):
|
|
607
636
|
|
608
637
|
sortarray.sort(axis=-1)
|
609
638
|
|
610
|
-
#valeurs min et max
|
639
|
+
# valeurs min et max
|
611
640
|
if nbnotnull == 0:
|
612
641
|
self.values[0] = 0
|
613
642
|
self.values[1:] = 1
|
@@ -617,7 +646,7 @@ class wolfpalette(wx.Frame,LinearSegmentedColormap):
|
|
617
646
|
|
618
647
|
self.values[0] = sortarray[0]
|
619
648
|
|
620
|
-
if(nbnotnull==99999):
|
649
|
+
if (nbnotnull == 99999):
|
621
650
|
self.values[-1] = sortarray[-1]
|
622
651
|
nb = sortarray.count()
|
623
652
|
else:
|
@@ -625,41 +654,41 @@ class wolfpalette(wx.Frame,LinearSegmentedColormap):
|
|
625
654
|
nb = nbnotnull
|
626
655
|
|
627
656
|
interv = int(nb / (self.nb-1))
|
628
|
-
if interv==0:
|
657
|
+
if interv == 0:
|
629
658
|
self.values[:] = self.values[-1]
|
630
659
|
self.values[0] = self.values[-1]-1.
|
631
660
|
else:
|
632
|
-
for cur in range(1,self.nb-1):
|
661
|
+
for cur in range(1, self.nb-1):
|
633
662
|
self.values[cur] = sortarray[cur * interv]
|
634
663
|
|
635
664
|
self.fill_segmentdata()
|
636
665
|
|
637
|
-
def defaultgray_minmax(self,array: ma.masked_array,nbnotnull=99999):
|
666
|
+
def defaultgray_minmax(self, array: ma.masked_array, nbnotnull=99999):
|
638
667
|
"""Remplissage des valeurs de palette sur base d'une équirépartition de valeurs"""
|
639
668
|
|
640
|
-
self.nb=2
|
641
|
-
self.values = np.asarray([np.min(array),np.max(array)])
|
642
|
-
self.colors = np.asarray([[0,0,0,255],[255,255,255,255]],dtype=np.int32)
|
643
|
-
self.colorsflt = np.asarray([[0.,0.,0.,1.],[1.,1.,1.,1.]],dtype=np.float64)
|
669
|
+
self.nb = 2
|
670
|
+
self.values = np.asarray([np.min(array), np.max(array)], dtype=np.float64)
|
671
|
+
self.colors = np.asarray([[0, 0, 0, 255], [255, 255, 255, 255]], dtype=np.int32)
|
672
|
+
self.colorsflt = np.asarray([[0., 0., 0., 1.], [1., 1., 1., 1.]], dtype=np.float64)
|
644
673
|
|
645
674
|
self.fill_segmentdata()
|
646
675
|
|
647
|
-
def defaultblue_minmax(self,array: ma.masked_array,nbnotnull=99999):
|
676
|
+
def defaultblue_minmax(self, array: ma.masked_array, nbnotnull=99999):
|
648
677
|
"""Remplissage des valeurs de palette sur base d'une équirépartition de valeurs"""
|
649
678
|
|
650
|
-
self.nb=2
|
651
|
-
self.values = np.asarray([np.min(array),np.max(array)])
|
652
|
-
self.colors = np.asarray([[255,255,255,255],[0,0,255,255]],dtype=np.int32)
|
653
|
-
self.colorsflt = np.asarray([[0.,0.,0.,1.],[1.,1.,1.,1.]],dtype=np.float64)
|
679
|
+
self.nb = 2
|
680
|
+
self.values = np.asarray([np.min(array), np.max(array)], dtype=np.float64)
|
681
|
+
self.colors = np.asarray([[255, 255, 255, 255], [0, 0, 255, 255]], dtype=np.int32)
|
682
|
+
self.colorsflt = np.asarray([[0., 0., 0., 1.], [1., 1., 1., 1.]], dtype=np.float64)
|
654
683
|
|
655
684
|
self.fill_segmentdata()
|
656
685
|
|
657
686
|
def defaultblue(self):
|
658
687
|
"""Remplissage des valeurs de palette sur base d'une équirépartition de valeurs"""
|
659
688
|
|
660
|
-
self.nb=2
|
661
|
-
self.values = np.asarray([0.,1.])
|
662
|
-
self.colors = np.asarray([[255,255,255,255],[0,0,255,255]],dtype=np.int32)
|
663
|
-
self.colorsflt = np.asarray([[0.,0.,0.,1.],[1.,1.,1.,1.]],dtype=np.float64)
|
689
|
+
self.nb = 2
|
690
|
+
self.values = np.asarray([0., 1.], dtype=np.float64)
|
691
|
+
self.colors = np.asarray([[255, 255, 255, 255], [0, 0, 255, 255]], dtype=np.int32)
|
692
|
+
self.colorsflt = np.asarray([[0., 0., 0., 1.], [1., 1., 1., 1.]], dtype=np.float64)
|
664
693
|
|
665
694
|
self.fill_segmentdata()
|