Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jamaa opened this issue Oct 25, 2017 · 4 comments
Closed
Labels

Comments

@jamaa
Copy link

jamaa commented Oct 25, 2017

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.

@jamaa jamaa changed the title Crash when attempting to plot a variable whose min an max are equal Crash when attempting to plot a variable whose min and max are equal Oct 25, 2017
@lucduron
Copy link
Member

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

@lucduron lucduron added the bug label Oct 26, 2017
@jamaa
Copy link
Author

jamaa commented Nov 1, 2017

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
Copy link
Member

lucduron commented Nov 4, 2017

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
Copy link
Author

jamaa commented Nov 6, 2017

Thanks, that works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants