wolfhece 2.1.38__py3-none-any.whl → 2.1.39__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 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
- class wolfpalette(wx.Frame,LinearSegmentedColormap):
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[:,:3].astype(np.float32)
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[:,:3].astype(np.uint8) * 255
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 = self.colorsuint8[i]
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', 'YlOrRd', 'OrRd', 'PuRd', 'RdPu', 'BuPu','GnBu', 'PuBu', 'YlGnBu','PuBuGn', 'BuGn', 'YlGn']
116
- cmaps['Sequential (2)'] = ['binary', 'gist_yarg', 'gist_gray', 'gray', 'bone', 'pink','spring', 'summer', 'autumn', 'winter', 'cool', 'Wistia','hot', 'afmhot', 'gist_heat', 'copper']
117
- cmaps['Diverging'] = ['PiYG', 'PRGn', 'BrBG', 'PuOr', 'RdGy', 'RdBu','RdYlBu', 'RdYlGn', 'Spectral', 'coolwarm', 'bwr', 'seismic']
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','Dark2', 'Set1', 'Set2', 'Set3','tab10', 'tab20', 'tab20b', 'tab20c']
120
- cmaps['Miscellaneous'] = ['flag', 'prism', 'ocean', 'gist_earth', 'terrain', 'gist_stern','gnuplot', 'gnuplot2', 'CMRmap', 'cubehelix', 'brg','gist_rainbow', 'rainbow', 'jet', 'nipy_spectral', 'gist_ncar']
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) , dtype=float)
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
137
143
 
138
- return self.nb,self.values,self._segmentdata,self.colorsflt
144
+ return self.nb, self.values, self._segmentdata, self.colorsflt
145
+
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==-99999:
153
- dlg = wx.TextEntryDialog(None, _('Minimum value'), value = str(self.values[0]))
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==-99999 and step==0:
166
+ if maxval == -99999 and step == 0:
161
167
 
162
- dlg = wx.MessageDialog(None, _('Would you like to set the incremental step value ?'),style= wx.YES_NO|wx.YES_DEFAULT)
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 = '1')
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 = str(self.values[-1]))
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!=-99999:
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, endpoint=True)[0: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 = None):
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 , dtype=float)
351
- self.colors = np.zeros((self.nb,4) , dtype=int)
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),:] = 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,137 @@ 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]: return wx.Colour(self.colormin)
387
- if x > self.values[-1]: return wx.Colour(self.colormax)
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]: return wx.Colour(self.colormin)
403
- if x > self.values[-1]: return wx.Colour(self.colormax)
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]: return wx.Colour(self.colormin)
418
- if x > self.values[-1]: return wx.Colour(self.colormax)
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) , dtype=int)
436
- self.colorsflt = np.zeros((self.nb,4) , dtype=float)
437
-
438
- self.colors[0,:] = [128,255,255,255]
439
- self.colors[1,:] = [89,172,255,255]
440
- self.colors[2,:] = [72,72,255,255]
441
- self.colors[3,:] = [0,0,255,255]
442
- self.colors[4,:] = [0,128,0,255]
443
- self.colors[5,:] = [0,221,55,255]
444
- self.colors[6,:] = [128,255,128,255]
445
- self.colors[7,:] = [255,255,0,255]
446
- self.colors[8,:] = [255,128,0,255]
447
- self.colors[9,:] = [235,174,63,255]
448
- self.colors[10,:] = [255,0,0,255]
449
- self.colors[11,:] = [209,71,12,255]
450
- self.colors[12,:] = [128,0,0,255]
451
- self.colors[13,:] = [185,0,0,255]
452
- self.colors[14,:] = [111,111,111,255]
453
- self.colors[15,:] = [192,192,192,255]
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) , dtype=int)
470
- self.colorsflt = np.zeros((self.nb,4) , dtype=float)
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
- self.nb=2
504
- self.values = np.asarray([0.,1.])
505
- self.colors = np.asarray([[0,0,0,255],[255,255,255,255]],dtype=np.int32)
517
+ self.nb = 2
518
+ self.values = np.asarray([0., 1.], dtype=np.float64)
519
+ self.colors = np.asarray([[0, 0, 0, 255], [255, 255, 255, 255]], dtype=np.int32)
506
520
 
507
521
  self.fill_segmentdata()
508
522
 
@@ -512,89 +526,89 @@ class wolfpalette(wx.Frame,LinearSegmentedColormap):
512
526
  self.colorsflt = self.colors.astype(float)/255.
513
527
  self.colorsuint8 = self.colors.astype(np.uint8)
514
528
 
515
- dval=self.values[-1]-self.values[0]
529
+ dval = self.values[-1]-self.values[0]
516
530
 
517
531
  normval = np.ones([len(self.values)])
518
532
 
519
- if dval>0.:
533
+ if dval > 0.:
520
534
  normval = (self.values-self.values[0])/(self.values[-1]-self.values[0])
521
535
 
522
- normval[0]=0.
523
- normval[-1]=1.
524
- segmentdata = {"red": np.column_stack([normval, self.colorsflt[:,0], self.colorsflt[:,0]]),
525
- "green": np.column_stack([normval, self.colorsflt[:,1], self.colorsflt[:,1]]),
526
- "blue": np.column_stack([normval, self.colorsflt[:,2], self.colorsflt[:,2]]),
527
- "alpha": np.column_stack([normval, self.colorsflt[:,3], self.colorsflt[:,3]])}
536
+ normval[0] = 0.
537
+ normval[-1] = 1.
538
+ segmentdata = {"red": np.column_stack([normval, self.colorsflt[:, 0], self.colorsflt[:, 0]]),
539
+ "green": np.column_stack([normval, self.colorsflt[:, 1], self.colorsflt[:, 1]]),
540
+ "blue": np.column_stack([normval, self.colorsflt[:, 2], self.colorsflt[:, 2]]),
541
+ "alpha": np.column_stack([normval, self.colorsflt[:, 3], self.colorsflt[:, 3]])}
528
542
 
529
- LinearSegmentedColormap.__init__(self,'wolf',segmentdata,self.nseg)
543
+ LinearSegmentedColormap.__init__(self, 'wolf', segmentdata, self.nseg)
530
544
 
531
- def readfile(self,*args):
545
+ def readfile(self, *args):
532
546
  """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
547
+ if len(args) > 0:
548
+ # s'il y a un argument on le prend tel quel
535
549
  self.filename = str(args[0])
536
550
  else:
537
551
  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 (*.*)|*.*")
552
+ # ouverture d'une boîte de dialogue
553
+ file = wx.FileDialog(None, "Choose .pal file", wildcard="pal (*.pal)|*.pal|all (*.*)|*.*")
540
554
  if file.ShowModal() == wx.ID_CANCEL:
541
555
  file.Destroy()
542
556
  return
543
557
  else:
544
- #récuparétaion du nom de fichier avec chemin d'accès
545
- self.filename =file.GetPath()
558
+ # récuparétaion du nom de fichier avec chemin d'accès
559
+ self.filename = file.GetPath()
546
560
  file.Destroy()
547
561
  else:
548
562
  return
549
563
 
550
- #lecture du contenu
564
+ # lecture du contenu
551
565
  with open(self.filename, 'r') as myfile:
552
- #split des lignes --> récupération des infos sans '\n' en fin de ligne
566
+ # split des lignes --> récupération des infos sans '\n' en fin de ligne
553
567
  # différent de .readlines() qui lui ne supprime pas les '\n'
554
568
  mypallines = myfile.read().splitlines()
555
569
  myfile.close()
556
570
 
557
571
  self.nb = int(mypallines[0])
558
- self.values = np.zeros(self.nb , dtype=float)
559
- self.colors = np.zeros((self.nb,4) , dtype=int)
572
+ self.values = np.zeros(self.nb, dtype=np.float64)
573
+ self.colors = np.zeros((self.nb, 4), dtype=int)
560
574
 
561
575
  for i in range(self.nb):
562
576
  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
577
+ self.colors[i, 0] = mypallines[i*4+2]
578
+ self.colors[i, 1] = mypallines[i*4+3]
579
+ self.colors[i, 2] = mypallines[i*4+4]
580
+ self.colors[i, 3] = 255
567
581
 
568
582
  self.fill_segmentdata()
569
583
 
570
- def savefile(self,*args):
584
+ def savefile(self, *args):
571
585
  """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
586
+ if len(args) > 0:
587
+ # s'il y a un argument on le prend tel quel
574
588
  fn = str(args[0])
575
589
  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)
590
+ # ouverture d'une boîte de dialogue
591
+ file = wx.FileDialog(None, "Choose .pal file", wildcard="pal (*.pal)|*.pal|all (*.*)|*.*", style=wx.FD_SAVE)
578
592
  if file.ShowModal() == wx.ID_CANCEL:
579
593
  return
580
594
  else:
581
- #récuparétaion du nom de fichier avec chemin d'accès
582
- fn =file.GetPath()
595
+ # récuparétaion du nom de fichier avec chemin d'accès
596
+ fn = file.GetPath()
583
597
 
584
- self.filename=fn
598
+ self.filename = fn
585
599
 
586
- #lecture du contenu
600
+ # lecture du contenu
587
601
  with open(self.filename, 'w') as myfile:
588
- #split des lignes --> récupération des infos sans '\n' en fin de ligne
602
+ # split des lignes --> récupération des infos sans '\n' en fin de ligne
589
603
  # différent de .readlines() qui lui ne supprime pas les '\n'
590
604
  myfile.write(str(self.nb)+'\n')
591
605
  for i in range(self.nb):
592
606
  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')
607
+ myfile.write(str(self.colors[i, 0])+'\n')
608
+ myfile.write(str(self.colors[i, 1])+'\n')
609
+ myfile.write(str(self.colors[i, 2])+'\n')
596
610
 
597
- def isopop(self, array: ma.masked_array, nbnotnull:int=99999):
611
+ def isopop(self, array: ma.masked_array, nbnotnull: int = 99999):
598
612
  """Remplissage des valeurs de palette sur base d'une équirépartition de valeurs"""
599
613
 
600
614
  sortarray = array.flatten(order='F')
@@ -607,7 +621,7 @@ class wolfpalette(wx.Frame,LinearSegmentedColormap):
607
621
 
608
622
  sortarray.sort(axis=-1)
609
623
 
610
- #valeurs min et max
624
+ # valeurs min et max
611
625
  if nbnotnull == 0:
612
626
  self.values[0] = 0
613
627
  self.values[1:] = 1
@@ -617,7 +631,7 @@ class wolfpalette(wx.Frame,LinearSegmentedColormap):
617
631
 
618
632
  self.values[0] = sortarray[0]
619
633
 
620
- if(nbnotnull==99999):
634
+ if (nbnotnull == 99999):
621
635
  self.values[-1] = sortarray[-1]
622
636
  nb = sortarray.count()
623
637
  else:
@@ -625,41 +639,41 @@ class wolfpalette(wx.Frame,LinearSegmentedColormap):
625
639
  nb = nbnotnull
626
640
 
627
641
  interv = int(nb / (self.nb-1))
628
- if interv==0:
642
+ if interv == 0:
629
643
  self.values[:] = self.values[-1]
630
644
  self.values[0] = self.values[-1]-1.
631
645
  else:
632
- for cur in range(1,self.nb-1):
646
+ for cur in range(1, self.nb-1):
633
647
  self.values[cur] = sortarray[cur * interv]
634
648
 
635
649
  self.fill_segmentdata()
636
650
 
637
- def defaultgray_minmax(self,array: ma.masked_array,nbnotnull=99999):
651
+ def defaultgray_minmax(self, array: ma.masked_array, nbnotnull=99999):
638
652
  """Remplissage des valeurs de palette sur base d'une équirépartition de valeurs"""
639
653
 
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)
654
+ self.nb = 2
655
+ self.values = np.asarray([np.min(array), np.max(array)], dtype=np.float64)
656
+ self.colors = np.asarray([[0, 0, 0, 255], [255, 255, 255, 255]], dtype=np.int32)
657
+ self.colorsflt = np.asarray([[0., 0., 0., 1.], [1., 1., 1., 1.]], dtype=np.float64)
644
658
 
645
659
  self.fill_segmentdata()
646
660
 
647
- def defaultblue_minmax(self,array: ma.masked_array,nbnotnull=99999):
661
+ def defaultblue_minmax(self, array: ma.masked_array, nbnotnull=99999):
648
662
  """Remplissage des valeurs de palette sur base d'une équirépartition de valeurs"""
649
663
 
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)
664
+ self.nb = 2
665
+ self.values = np.asarray([np.min(array), np.max(array)], dtype=np.float64)
666
+ self.colors = np.asarray([[255, 255, 255, 255], [0, 0, 255, 255]], dtype=np.int32)
667
+ self.colorsflt = np.asarray([[0., 0., 0., 1.], [1., 1., 1., 1.]], dtype=np.float64)
654
668
 
655
669
  self.fill_segmentdata()
656
670
 
657
671
  def defaultblue(self):
658
672
  """Remplissage des valeurs de palette sur base d'une équirépartition de valeurs"""
659
673
 
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)
674
+ self.nb = 2
675
+ self.values = np.asarray([0., 1.], dtype=np.float64)
676
+ self.colors = np.asarray([[255, 255, 255, 255], [0, 0, 255, 255]], dtype=np.int32)
677
+ self.colorsflt = np.asarray([[0., 0., 0., 1.], [1., 1., 1., 1.]], dtype=np.float64)
664
678
 
665
679
  self.fill_segmentdata()
@@ -19,7 +19,7 @@ from wx.adv import SplashScreen as SplashScreen,SPLASH_CENTRE_ON_SCREEN,SPLASH
19
19
 
20
20
  try:
21
21
  from ..libs import wolfogl
22
- except:
22
+ except ImportError:
23
23
  print("** WolfOGL not found **")
24
24
  print("Without WolfOGL, the application will not work !")
25
25
  print("Please reinstall 'wolfhece' package -- pip install wolfhece --force-reinstall")
@@ -38,7 +38,7 @@ class WolfLauncher(SplashScreen):
38
38
 
39
39
  # try:
40
40
  # wolfogl.init()
41
- # except Exception as e:
41
+ # except ImportError:
42
42
  # print("Error initializing WolfOGL -- We must stop here !")
43
43
  # print("Please reinstall 'wolfhece' package -- pip install wolfhece")
44
44
  # exit()
wolfhece/apps/version.py CHANGED
@@ -5,7 +5,7 @@ class WolfVersion():
5
5
 
6
6
  self.major = 2
7
7
  self.minor = 1
8
- self.patch = 38
8
+ self.patch = 39
9
9
 
10
10
  def __str__(self):
11
11
 
Binary file
wolfhece/pyviews.py CHANGED
@@ -181,17 +181,21 @@ class WolfViews(Element_To_Draw):
181
181
 
182
182
  if self.plotted:
183
183
 
184
- for cur,pal in zip(self.view,self.pals):
184
+ for cur, pal in zip(self.view, self.pals):
185
185
  oldplotted = cur.plotted
186
186
  cur.plotted=True
187
187
 
188
188
  if isinstance(cur,WolfArray):
189
- if cur.rgb is None:
190
- if pal is not None:
191
- if VERSION_RGB ==1: cur.rgb = pal.get_rgba(cur.array)
192
- else:
189
+ if VERSION_RGB ==1:
190
+ if cur.rgb is None:
191
+ if pal is not None:
192
+ cur.rgb = pal.get_rgba(cur.array)
193
+ else:
194
+ cur.mypal.defaultgray_minmax(cur.array)
195
+ cur.rgb = cur.mypal.get_rgba(cur.array)
196
+ elif VERSION_RGB == 2:
197
+ if pal is None:
193
198
  cur.mypal.defaultgray_minmax(cur.array)
194
- if VERSION_RGB ==1: cur.rgb = cur.mypal.get_rgba(cur.array)
195
199
 
196
200
  cur.plot(sx,sy,xmin,ymin,xmax,ymax)
197
201
  cur.plotted = oldplotted
wolfhece/wolf_array.py CHANGED
@@ -53,7 +53,7 @@ from .drawing_obj import Element_To_Draw
53
53
 
54
54
  try:
55
55
  from .libs import wolfogl
56
- except:
56
+ except ImportError:
57
57
  msg=_('Error importing wolfogl.pyd')
58
58
  msg+=_(' Python version : ' + sys.version)
59
59
  msg+=_(' If your Python version is not 3.10.x, you need to get an adapted library in wolfhece library path libs')
@@ -4163,7 +4163,7 @@ class WolfArray(Element_To_Draw, header_wolf):
4163
4163
  create:bool = False,
4164
4164
  mapviewer = None,
4165
4165
  nullvalue:float = 0.,
4166
- srcheader:header_wolf = None,
4166
+ srcheader:header_wolf = None,
4167
4167
  idx:str = '',
4168
4168
  plotted:bool = False,
4169
4169
  need_for_wx:bool = False,
@@ -4173,7 +4173,7 @@ class WolfArray(Element_To_Draw, header_wolf):
4173
4173
  Constructor of the WolfArray class
4174
4174
 
4175
4175
  :param fname: filename/filepath - if provided, the file will be read on disk
4176
- :param mold: initialize from a copy a the mold object --> must be a WolArray
4176
+ :param mold: initialize from a copy a the mold object --> must be a WolArray if not None
4177
4177
  :param masknull: mask data based on the nullvalue
4178
4178
  :param crop: crop data based on the spatial extent [[xmin, xmax],[ymin,ymax]]
4179
4179
  :param whichtype: type of the numpy array (float32 as default)
@@ -4188,7 +4188,11 @@ class WolfArray(Element_To_Draw, header_wolf):
4188
4188
  :param mask_source: mask to link to the data
4189
4189
 
4190
4190
  """
4191
- # wolfogl.powermode('ON')
4191
+ try:
4192
+ pass
4193
+ # wolfogl.powermode('ON')
4194
+ except PermissionError:
4195
+ print(_('wolfogl not available -- Pleas check your wolfhece installation'))
4192
4196
 
4193
4197
  Element_To_Draw.__init__(self, idx, plotted, mapviewer, need_for_wx)
4194
4198
  header_wolf.__init__(self)
@@ -6182,6 +6186,9 @@ class WolfArray(Element_To_Draw, header_wolf):
6182
6186
  else:
6183
6187
  newArray.array = np.ma.masked_array(self.array + other.array, self.array.mask)
6184
6188
  newArray.count()
6189
+
6190
+ assert newArray.array.dtype == self.array.dtype, _('Bad dtype')
6191
+
6185
6192
  return newArray
6186
6193
 
6187
6194
  def __mul__(self, other):
@@ -6208,6 +6215,9 @@ class WolfArray(Element_To_Draw, header_wolf):
6208
6215
  else:
6209
6216
  newArray.array = np.ma.masked_array(self.array * other.array, self.array.mask)
6210
6217
  newArray.count()
6218
+
6219
+ assert newArray.array.dtype == self.array.dtype, _('Bad dtype')
6220
+
6211
6221
  return newArray
6212
6222
 
6213
6223
  def __sub__(self, other):
@@ -6234,6 +6244,9 @@ class WolfArray(Element_To_Draw, header_wolf):
6234
6244
  else:
6235
6245
  newArray.array = np.ma.masked_array(self.array - other.array, self.array.mask)
6236
6246
  newArray.count()
6247
+
6248
+ assert newArray.array.dtype == self.array.dtype, _('Bad dtype')
6249
+
6237
6250
  return newArray
6238
6251
 
6239
6252
  def __pow__(self, other):
@@ -6256,6 +6269,9 @@ class WolfArray(Element_To_Draw, header_wolf):
6256
6269
 
6257
6270
  newArray.array = np.ma.masked_array(self.array ** other, self.array.mask)
6258
6271
  newArray.count()
6272
+
6273
+ assert newArray.array.dtype == self.array.dtype, _('Bad dtype')
6274
+
6259
6275
  return newArray
6260
6276
 
6261
6277
  def __truediv__(self, other):
@@ -6282,6 +6298,9 @@ class WolfArray(Element_To_Draw, header_wolf):
6282
6298
  else:
6283
6299
  newArray.array = np.ma.masked_array(np.where(other == 0., 0., self.array / other.array), self.array.mask)
6284
6300
  newArray.count()
6301
+
6302
+ assert newArray.array.dtype == self.array.dtype, _('Bad dtype')
6303
+
6285
6304
  return newArray
6286
6305
 
6287
6306
  def concatenate(self, list_arr:list["WolfArray"], nullvalue:float = 0.):
@@ -1787,14 +1787,20 @@ class OneWolfResult:
1787
1787
  self._current.rgb = curpal.get_rgba(self._current.array)
1788
1788
  self._current.rgb[self._current.array.mask] = [1., 1., 1., 1.]
1789
1789
 
1790
- if which == 'wd_u':
1791
- self._view.pals = [bluepal,curpal]
1792
- elif which =='t_wl_q':
1793
- self._view.pals = [graypal,curpal,None]
1794
- elif which =='t_wd_q':
1795
- self._view.pals = [graypal,bluepal,None]
1796
- elif which =='t_wd_u':
1797
- self._view.pals = [graypal,bluepal,None]
1790
+ if which in [views_2D.WD_Q, views_2D.WD_U]:
1791
+ self._view.pals = [curpal, None]
1792
+ elif which in [views_2D.WL_U, views_2D.WL_Q]:
1793
+ self._view.pals = [curpal, None]
1794
+
1795
+ elif which == views_2D.T_WL_Q:
1796
+ self._view.pals = [graypal, curpal, None]
1797
+ elif which == views_2D.T_WL_Q:
1798
+ self._view.pals = [graypal, curpal, None]
1799
+
1800
+ elif which == views_2D.T_WD_Q:
1801
+ self._view.pals = [graypal, bluepal, None]
1802
+ elif which == views_2D.T_WD_U:
1803
+ self._view.pals = [graypal, bluepal, None]
1798
1804
 
1799
1805
  def get_critdiam(self, which:int) -> WolfArray:
1800
1806
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: wolfhece
3
- Version: 2.1.38
3
+ Version: 2.1.39
4
4
  Author-email: Pierre Archambeau <pierre.archambeau@uliege.be>
5
5
  License: Copyright (c) 2024 University of Liege. All rights reserved.
6
6
  Project-URL: Homepage, https://uee.uliege.be/hece
@@ -10,7 +10,7 @@ wolfhece/PyDraw.py,sha256=MQO149Cp8QtxWceXpKWLsDbE6JBrVbqEWoAOXWfHl2w,390751
10
10
  wolfhece/PyGui.py,sha256=_1LKelusQ-FS0AtgpwFiXKMZ2glky7K1WINTI93H0k0,103438
11
11
  wolfhece/PyGuiHydrology.py,sha256=f60E8K9eGTnRq5RDF6yvt-ahf2AYegwQ9t25zZ2Mk1A,14946
12
12
  wolfhece/PyHydrographs.py,sha256=jwtSNMMACwarxrtN1UeQYth99UNrhwPx1IGgUwcooHA,3774
13
- wolfhece/PyPalette.py,sha256=lqWd-jZkEyYeeAyaiIaGZq_bxXRiiMhDXN68QYoVCfU,26181
13
+ wolfhece/PyPalette.py,sha256=uxibQSz5u1q8bgZv-VId6o_SI5TTfLHPs9DpJomVwSA,27179
14
14
  wolfhece/PyParams.py,sha256=wwgmP-_7wiiPLTcyX8a5jR6FyC1D2c4oBPc1VWQqtSA,97383
15
15
  wolfhece/PyPictures.py,sha256=m1kY0saW6Y9Q0bDCo47lW6XxDkBrbQG-Fd8uVn8G5ic,2514
16
16
  wolfhece/PyTranslate.py,sha256=4appkmNeHHZLFmUtaA_k5_5QL-5ymxnbVN4R2OblmtE,622
@@ -42,18 +42,18 @@ wolfhece/pydike.py,sha256=hPBQsmSTW4QAp1wcOzb-TL3L7eet2WT1sJx2q-WNQ-Q,2241
42
42
  wolfhece/pylogging.py,sha256=4TI8hgBB65z-zpvU5Rfa2jkPXPhJaqXjHVPwbcdzTNc,4528
43
43
  wolfhece/pypolygons_scen.py,sha256=x-tnYLNq3MPV51NbaU14trgRj8qyUyOrMdF1zDsUX3I,37444
44
44
  wolfhece/pyshields.py,sha256=7k-qe2EJgr9fJE62jyPmlWQwRj8T0DK4iuMU844ZhYs,23281
45
- wolfhece/pyviews.py,sha256=G4PHtXJ8F9PQDt_hcKnxF5kmA1_Fy-8hGiJN2wa_9j4,10017
45
+ wolfhece/pyviews.py,sha256=jSTXCsmzw5OIZusj3Ynfd2o2XvRq7TaDnbt-dyNlbi0,10198
46
46
  wolfhece/pywalous.py,sha256=yRaWJjKckXef1d9D5devP0yFHC9uc6kRV4G5x9PNq9k,18972
47
47
  wolfhece/rain_SPWMI.py,sha256=qCfcmF7LajloOaCwnTrrSMzyME03YyilmRUOqrPrv3U,13846
48
48
  wolfhece/textpillow.py,sha256=map7HsGYML_o5NHRdFg2s_TVQed_lDnpYNDv27MM0Vw,14130
49
49
  wolfhece/tools_mpl.py,sha256=gQ3Jg1iuZiecmMqa5Eli2ZLSkttu68VXL8YmMDBaEYU,564
50
- wolfhece/wolf_array.py,sha256=m0Akg1jpe8L7139afVANhqUI09q7YlQvlGm2mcs7gJQ,356155
50
+ wolfhece/wolf_array.py,sha256=7-5l96kuQdTE3CStLyf8PkyRD3QX1Us7DOTbF7INepY,356721
51
51
  wolfhece/wolf_hist.py,sha256=7jeVrgSkM3ErJO6SRMH_PGzfLjIdw8vTy87kesldggk,3582
52
52
  wolfhece/wolf_texture.py,sha256=EqZI6qCR6ouT3wEtnG_NkVLdvUhfY65JVTj5b6o4lXI,16576
53
53
  wolfhece/wolf_tiles.py,sha256=2Ho2I20rHRY81KXxjgLOYISdF4OkJ2d6omeY4shDoGI,10386
54
54
  wolfhece/wolf_vrt.py,sha256=89XoDhCJMHiwPQUuOduxtTRKuIa8RDxgNqX65S4xp9M,10569
55
55
  wolfhece/wolf_zi_db.py,sha256=baE0niMCzybWGSvPJc5FNxo9ZxsGfU4p-FmfiavFHAs,12967
56
- wolfhece/wolfresults_2D.py,sha256=U6k8BeQj2g3EUpAQq7m0nSdLtNKrrn_knWKKs1KoAQ8,165462
56
+ wolfhece/wolfresults_2D.py,sha256=MlvE2OoSwk1P_CeTwotV1QDBJYeHhSCjUprG3c42tRc,165714
57
57
  wolfhece/xyz_file.py,sha256=Se4nCPwYAYLSA5i0zsbnZUKoAMAD0mK1FJea5WSZUkk,5755
58
58
  wolfhece/acceptability/Parallels.py,sha256=h4tu3SpC_hR5Hqa68aruxhtAyhs8u666YuZ40_fR5zg,3979
59
59
  wolfhece/acceptability/__init__.py,sha256=hfgoPKLDpX7drN1Vpvux-_5Lfyc_7feT2C2zQr5v-Os,258
@@ -70,8 +70,8 @@ wolfhece/apps/__init__.py,sha256=OzzKItATWV0mDkz_LC2L3w5sgT2rt8ExXXCbR_FwvlY,24
70
70
  wolfhece/apps/check_install.py,sha256=icFpkjfwNGDX-0NZVa-ijrCrqmGHEKDiFphjN8uTyh8,928
71
71
  wolfhece/apps/curvedigitizer.py,sha256=_hRR2PWow7PU7rTHIbc6ykZ08tCXcK9uy7RFrb4EKkE,5196
72
72
  wolfhece/apps/isocurrent.py,sha256=MuwTodHxdc6PrqNpphR2ntYf1NLL2n9klTPndGrOHDQ,4109
73
- wolfhece/apps/splashscreen.py,sha256=Z95ca-r_SZFpTJZIILuAcKyzl6ElZR08Y5mpQ5y4ZDc,2920
74
- wolfhece/apps/version.py,sha256=oID8AvPVNdgq4kmuDFo7jFiw8pv1XddrAgr_ttxcAgk,388
73
+ wolfhece/apps/splashscreen.py,sha256=SrustmIQeXnsiD-92OzjdGhBi-S7c_j-cSvuX4T6rtg,2929
74
+ wolfhece/apps/version.py,sha256=9TV-RYEEy9X0HeZ9xYxf6PRts-on5mB43zJZtbq4_bY,388
75
75
  wolfhece/apps/wolf.py,sha256=mM6Tyi4DlKQILmO49cDUCip9fYVy-hLXkY3YhZgIeUQ,591
76
76
  wolfhece/apps/wolf2D.py,sha256=yPQGee7fsegoQ8GfWKrWEjX1Az_ApL-UWlBiqPvaIyY,565
77
77
  wolfhece/apps/wolf_logo.bmp,sha256=ruJ4MA51CpGO_AYUp_dB4SWKHelvhOvd7Q8NrVOjDJk,3126
@@ -171,7 +171,7 @@ wolfhece/lazviewer/viewer/viewer.exe,sha256=pF5nwE8vMWlEzkk-SOekae9zpOsPhTWhZbqa
171
171
  wolfhece/lazviewer/viewer/viewer.py,sha256=8_MQCaQOS0Z_oRPiGoRy1lq-aCirReX3hWEBjQID0ig,24665
172
172
  wolfhece/libs/get_infos.cp310-win_amd64.pyd,sha256=45b6uo0r2zPD4KbpHR8QZC0TwQHDb9S0It7-kv0GWTA,77824
173
173
  wolfhece/libs/verify_wolf.cp310-win_amd64.pyd,sha256=ceWkovmTDfQcIzlxOBjUUDoHu6ZglOlUFADaRuAe3WM,127488
174
- wolfhece/libs/wolfogl.cp310-win_amd64.pyd,sha256=1nQE30ZDXTmnjnaJisDDlP5zvt5Chu2Lxz1a-bZTY1A,294912
174
+ wolfhece/libs/wolfogl.cp310-win_amd64.pyd,sha256=e27Epa44wBSrXiwzeUpl2ud8oCPJpFbfWd_5P5l6sAo,294912
175
175
  wolfhece/libs/wolfpy.cp310-win_amd64.pyd,sha256=6omqEaxmQll-Gg24e90wVomAB9rO_tyyOES2FewXn58,36457472
176
176
  wolfhece/libs/GL/gl.h,sha256=IhsS_fOLa8GW9MpiLZebe9QYRy6uIB_qK_uQMWMOoeg,46345
177
177
  wolfhece/libs/GL/glaux.h,sha256=I3vxXdrzVH05TmjEeAOgKn3egbPt34WMjbeKq5LaBvE,7130
@@ -249,8 +249,8 @@ wolfhece/ui/wolf_multiselection_collapsiblepane.py,sha256=8PlMYrb_8jI8h9F0_EagpM
249
249
  wolfhece/ui/wolf_times_selection_comparison_models.py,sha256=ORy7fz4dcp691qKzaOZHrRLZ0uXNhL-LIHxmpDGL6BI,5007
250
250
  wolfhece/wintab/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
251
251
  wolfhece/wintab/wintab.py,sha256=8A-JNONV6ujgsgG3lM5Uw-pVgglPATwKs86oBzzljoc,7179
252
- wolfhece-2.1.38.dist-info/METADATA,sha256=YabVhQz0G97k82q5CR8b4lqyCKpVhdhWpbIrjeJ9Yuw,2463
253
- wolfhece-2.1.38.dist-info/WHEEL,sha256=Wyh-_nZ0DJYolHNn1_hMa4lM7uDedD_RGVwbmTjyItk,91
254
- wolfhece-2.1.38.dist-info/entry_points.txt,sha256=yggeO1Fa80pi2BrOd9k5dTkiFlefGPwG6HztZhY0-qw,366
255
- wolfhece-2.1.38.dist-info/top_level.txt,sha256=EfqZXMVCn7eILUzx9xsEu2oBbSo9liWPFWjIHik0iCI,9
256
- wolfhece-2.1.38.dist-info/RECORD,,
252
+ wolfhece-2.1.39.dist-info/METADATA,sha256=83wPlCtt2A7BPb-3QuxZrLSWn3AGA5uppBHC79HuiBU,2463
253
+ wolfhece-2.1.39.dist-info/WHEEL,sha256=Wyh-_nZ0DJYolHNn1_hMa4lM7uDedD_RGVwbmTjyItk,91
254
+ wolfhece-2.1.39.dist-info/entry_points.txt,sha256=yggeO1Fa80pi2BrOd9k5dTkiFlefGPwG6HztZhY0-qw,366
255
+ wolfhece-2.1.39.dist-info/top_level.txt,sha256=EfqZXMVCn7eILUzx9xsEu2oBbSo9liWPFWjIHik0iCI,9
256
+ wolfhece-2.1.39.dist-info/RECORD,,