I am considering a situation where the whole area is covered with ice:
md.mask.ice_levelset = np.full((md.mesh.numberofvertices,), -1.)
plotmodel(md, 'data', md.mask.ice_levelset)
However, plotmodel
produces error message as follows:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-22-2179064903b1> in <module>
----> 1 plotmodel(md, 'data', md.mask.ice_levelset)
~/issm/trunk/bin/plotmodel.py in plotmodel(md, *args)
98 for i, ax in enumerate(axgrid.axes_all):
99 try:
--> 100 plot_manager(options.list[i].getfieldvalue('model', md), options.list[i], fig, axgrid, i)
101 except KeyError:
102 print("Too many axes present, we delete the overflow")
~/issm/trunk/bin/plot_manager.py in plot_manager(md, options, fig, axgrid, gridindex)
88 data2, datatype = processdata(md, data, options)
89 #plot unit
---> 90 plot_unit(x, y, z, elements, data2, is2d, isplanet, datatype, options, fig, axgrid, gridindex)
91 #apply all options
92 applyoptions(md, data2, options, fig, axgrid, gridindex)
~/issm/trunk/bin/plot_unit.py in plot_unit(x, y, z, elements, data, is2d, isplanet, datatype, options, fig, axgrid, gridindex)
170 if alpha < 1: #help with antialiasing
171 tri = ax.tricontour(triangles, data, colorlevels, cmap=cmap, norm=norm, alpha=0.1, antialiased=antialiased)
--> 172 tri = ax.tricontourf(triangles, data, colorlevels, cmap=cmap, norm=norm, alpha=alpha, extend='both', antialiased=antialiased)
173 if edgecolor != 'None':
174 ax.triplot(x, y, elements, color=edgecolor)
~/spack/opt/spack/linux-ubuntu18.04-skylake_avx512/gcc-9.2.0/python-3.7.4-7sfqaxaatdpsy55drblc2ipnhbyg7gqz/lib/python3.7/site-packages/matplotlib/tri/tricontour.py in tricontourf(ax, *args, **kwargs)
273 def tricontourf(ax, *args, **kwargs):
274 kwargs['filled'] = True
--> 275 return TriContourSet(ax, *args, **kwargs)
276
277
~/spack/opt/spack/linux-ubuntu18.04-skylake_avx512/gcc-9.2.0/python-3.7.4-7sfqaxaatdpsy55drblc2ipnhbyg7gqz/lib/python3.7/site-packages/matplotlib/tri/tricontour.py in __init__(self, ax, *args, **kwargs)
33 are described in the docstring of `tricontour`.
34 """
---> 35 ContourSet.__init__(self, ax, *args, **kwargs)
36
37 def _process_args(self, *args, **kwargs):
~/spack/opt/spack/linux-ubuntu18.04-skylake_avx512/gcc-9.2.0/python-3.7.4-7sfqaxaatdpsy55drblc2ipnhbyg7gqz/lib/python3.7/site-packages/matplotlib/contour.py in __init__(self, ax, levels, filled, linewidths, linestyles, alpha, origin, extent, cmap, colors, norm, vmin, vmax, extend, antialiased, *args, **kwargs)
902 if vmax is not None:
903 self.norm.vmax = vmax
--> 904 self._process_colors()
905
906 self.allsegs, self.allkinds = self._get_allsegs_and_allkinds()
~/spack/opt/spack/linux-ubuntu18.04-skylake_avx512/gcc-9.2.0/python-3.7.4-7sfqaxaatdpsy55drblc2ipnhbyg7gqz/lib/python3.7/site-packages/matplotlib/contour.py in _process_colors(self)
1287 self.cvalues = self.layers
1288 self.set_array(self.levels)
-> 1289 self.autoscale_None()
1290 if self.extend in ('both', 'max', 'min'):
1291 self.norm.clip = False
~/spack/opt/spack/linux-ubuntu18.04-skylake_avx512/gcc-9.2.0/python-3.7.4-7sfqaxaatdpsy55drblc2ipnhbyg7gqz/lib/python3.7/site-packages/matplotlib/cm.py in autoscale_None(self)
392 raise TypeError('You must first set_array for mappable')
393 self.norm.autoscale_None(self._A)
--> 394 self.changed()
395
396 def add_checker(self, checker):
~/spack/opt/spack/linux-ubuntu18.04-skylake_avx512/gcc-9.2.0/python-3.7.4-7sfqaxaatdpsy55drblc2ipnhbyg7gqz/lib/python3.7/site-packages/matplotlib/contour.py in changed(self)
1121 def changed(self):
1122 tcolors = [(tuple(rgba),)
-> 1123 for rgba in self.to_rgba(self.cvalues, alpha=self.alpha)]
1124 self.tcolors = tcolors
1125 hatches = self.hatches * len(tcolors)
~/spack/opt/spack/linux-ubuntu18.04-skylake_avx512/gcc-9.2.0/python-3.7.4-7sfqaxaatdpsy55drblc2ipnhbyg7gqz/lib/python3.7/site-packages/matplotlib/cm.py in to_rgba(self, x, alpha, bytes, norm)
287 x = ma.asarray(x)
288 if norm:
--> 289 x = self.norm(x)
290 rgba = self.cmap(x, alpha=alpha, bytes=bytes)
291 return rgba
~/spack/opt/spack/linux-ubuntu18.04-skylake_avx512/gcc-9.2.0/python-3.7.4-7sfqaxaatdpsy55drblc2ipnhbyg7gqz/lib/python3.7/site-packages/matplotlib/colors.py in __call__(self, value, clip)
962 result.fill(0) # Or should it be all masked? Or 0.5?
963 elif vmin > vmax:
--> 964 raise ValueError("minvalue must be less than or equal to maxvalue")
965 else:
966 if clip:
ValueError: minvalue must be less than or equal to maxvalue
I think that the reason is vmin > vmax
originated from the part of codes in plot_unit.py
:
# {{{ Get the colormap limits
if options.exist('clim'):
lims = options.getfieldvalue('clim', [np.amin(data), np.amax(data)])
elif options.exist('caxis'):
lims = options.getfieldvalue('caxis', [np.amin(data), np.amax(data)])
else:
if np.amin(data) == np.amax(data):
lims = [np.amin(data) * 0.9, np.amax(data) * 1.1]
else:
lims = [np.amin(data), np.amax(data)]
# }}}
When the whole data is a negative value, it is obviously logical error. So I suggest the following bug fix:
# {{{ Get the colormap limits
if options.exist('clim'):
lims = options.getfieldvalue('clim', [np.amin(data), np.amax(data)])
elif options.exist('caxis'):
lims = options.getfieldvalue('caxis', [np.amin(data), np.amax(data)])
else:
if np.amin(data) == np.amax(data):
val = np.amax(data)
delta = np.abs(val)*0.1
lims = [val - delta, val + delta]
# lims = [np.amin(data) * 0.9, np.amax(data) * 1.1]
else:
lims = [np.amin(data), np.amax(data)]
# }}}