CNR-Engineering / PyTelTools

Python Telemac Tools for post-processing tasks (includes a workflow)
https://github.com/CNR-Engineering/PyTelTools/wiki
GNU General Public License v3.0
32 stars 15 forks source link

Crash when attempting to plot a variable whose min and max are equal #2

Closed jamaa closed 6 years ago

jamaa commented 7 years ago

When attempting to plot a variable (vertical cross section) whose min and max values are equal (e.g. both 0), PyTelTools crashes. Here is the traceback:

Traceback (most recent call last):
  File "D:\SOFTWARE\PyTelTools\src\pyteltools\PyTelTools\workflow\mono_gui.py", line 148, in mouseDoubleClickEvent
    node.configure()
  File "D:\SOFTWARE\PyTelTools\src\pyteltools\PyTelTools\workflow\nodes_vis.py", line 989, in configure
    if not self._prepare():
  File "D:\SOFTWARE\PyTelTools\src\pyteltools\PyTelTools\workflow\nodes_vis.py", line 1023, in _prepare
    self.plot_viewer.get_data(input_data, sections, line_interpolators_internal, section_indices)
  File "D:\SOFTWARE\PyTelTools\src\pyteltools\PyTelTools\workflow\util.py", line 1174, in get_data
    self.replot()
  File "D:\SOFTWARE\PyTelTools\src\pyteltools\PyTelTools\workflow\util.py", line 1142, in replot
    extend='both')
  File "D:\SOFTWARE\PyTelTools\lib\site-packages\matplotlib\axes\_axes.py", line 7677, in tricontourf
    return mtri.tricontourf(self, *args, **kwargs)
  File "D:\SOFTWARE\PyTelTools\lib\site-packages\matplotlib\tri\tricontour.py", line 283, in tricontourf
    return TriContourSet(ax, *args, **kwargs)
  File "D:\SOFTWARE\PyTelTools\lib\site-packages\matplotlib\tri\tricontour.py", line 40, in __init__
    ContourSet.__init__(self, ax, *args, **kwargs)
  File "D:\SOFTWARE\PyTelTools\lib\site-packages\matplotlib\contour.py", line 853, in __init__
    kwargs = self._process_args(*args, **kwargs)
  File "D:\SOFTWARE\PyTelTools\lib\site-packages\matplotlib\tri\tricontour.py", line 51, in _process_args
    tri, z = self._contour_args(args, kwargs)
  File "D:\SOFTWARE\PyTelTools\lib\site-packages\matplotlib\tri\tricontour.py", line 94, in _contour_args
    self._contour_level_args(z, args[1:])
  File "D:\SOFTWARE\PyTelTools\lib\site-packages\matplotlib\contour.py", line 1190, in _contour_level_args
    raise ValueError("Contour levels must be increasing")
ValueError: Contour levels must be increasing

I was able to work around this by adding some code to artificially increase the max value in replot(), but I'm sure there is a more elegant way of handling this.

lucduron commented 6 years ago

Thank you reporting this bug, I corrected by adding/substracting a constant value to color map bounds.

jamaa commented 6 years ago

Thanks for the quick fix. However, it does not work in all cases. When min and max are equal, but some random float value, the following works better (line 1139 in workflow\util.py): if abs(max_value - min_value) < EPS_VALUE:

lucduron commented 6 years ago

I tried to improved the correction when min and max are equal by using a relative value. Indeed an absolute value/correction has some limitations for very low (values can not be displayed, the correction being too high) and very high values (the correction might be cancelled by truncation errors). EPS_VALUE is now a relative value which is set to 0.001 (=0.1%). The relative difference between min and max values is at least equal to 2*EPS_VALUE. Sorry for this new correction, I hope you will not get into troubles again with the colormap levels being not increasing.

jamaa commented 6 years ago

Thanks, that works.