ascot4fusion / ascot5

ASCOT5 is a high-performance orbit-following code for fusion plasma physics and engineering
https://ascot4fusion.github.io/ascot5/
GNU Lesser General Public License v3.0
32 stars 9 forks source link

Add logscale for plotting distributions #82

Closed Otsooni closed 8 months ago

Otsooni commented 9 months ago

It would be nice to implement a new flag logscale, to show the distributions in logarithmic scale.

Otsooni commented 9 months ago

@miekkasarki I have this implemented, but the unyt arrays keep somethings throwing some cannot reduce warnings/errors after the plots are finished if cursor is overlapping the figures. I think it's trying to evaluate things on the cursor position, but the logarithm of unyt arrays don't like that.

Although I have seen same behaviour before this feature on some of the logarithmic plots.

Should I still push through? The plots do come out, the warnings/errors just follow after.

miekkasarki commented 9 months ago

Can you give an example? You can ofc push but don't do PR yet.

Units can be stripped with foo.v if they are in the way.

Otsooni commented 9 months ago

As an example, a 2d or even 1d plot, where at least one of the bins (in that integrated form) has zero inside. Then if you hover your mouse over the empty bin, the error will appear in the command line (of course only with plt.show(), if the figure has been saved, nothing weird should happen).

miekkasarki commented 9 months ago

I mean't what exactly is the error message. I haven't encountered that kind of thing before.

Otsooni commented 9 months ago

`Traceback (most recent call last): File "/usr/lib/python3/dist-packages/matplotlib/cbook/init.py", line 287, in process func(*args, kwargs) File "/usr/lib/python3/dist-packages/matplotlib/backend_bases.py", line 3061, in mouse_move s = self._mouse_event_to_message(event) File "/usr/lib/python3/dist-packages/matplotlib/backend_bases.py", line 3053, in _mouse_event_to_message data_str = a.format_cursor_data(data).rstrip() File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 1284, in format_cursor_data delta = abs(neighbors - data).max() File "/home/hyvaotso/ascot/ascotenv/lib/python3.10/site-packages/numpy/ma/core.py", line 4218, in sub return subtract(self, other) File "/home/hyvaotso/ascot/ascotenv/lib/python3.10/site-packages/numpy/ma/core.py", line 1020, in call result = self.f(da, db, *args, *kwargs) File "/home/hyvaotso/ascot/ascotenv/lib/python3.10/site-packages/unyt/array.py", line 1892, in array_ufunc__ raise UnitOperationError(ufunc, u0, u1) unyt.exceptions.UnitOperationError: The <ufunc 'subtract'> operator for unyt_arrays with units "dimensionless" (dimensions "1") and "particles/degree" (dimensions "1/(angle)") is not well defined. Traceback (most recent call last): File "/usr/lib/python3/dist-packages/matplotlib/cbook/init__.py", line 287, in process func(args, kwargs) File "/usr/lib/python3/dist-packages/matplotlib/backend_bases.py", line 3061, in mouse_move s = self._mouse_event_to_message(event) File "/usr/lib/python3/dist-packages/matplotlib/backend_bases.py", line 3053, in _mouse_event_to_message data_str = a.format_cursor_data(data).rstrip() File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 1284, in format_cursor_data delta = abs(neighbors - data).max() File "/home/hyvaotso/ascot/ascotenv/lib/python3.10/site-packages/numpy/ma/core.py", line 4218, in sub return subtract(self, other) File "/home/hyvaotso/ascot/ascotenv/lib/python3.10/site-packages/numpy/ma/core.py", line 1020, in call result = self.f(da, db, *args, kwargs) File "/home/hyvaotso/ascot/ascotenv/lib/python3.10/site-packages/unyt/array.py", line 1892, in array_ufunc__ raise UnitOperationError(ufunc, u0, u1) unyt.exceptions.UnitOperationError: The <ufunc 'subtract'> operator for unyt_arrays with units "dimensionless" (dimensions "1") and "particles/degree" (dimensions "1/(angle)") is not well defined. Traceback (most recent call last): File "/usr/lib/python3/dist-packages/matplotlib/cbook/init.py", line 287, in process func(*args, **kwargs) File "/usr/lib/python3/dist-packages/matplotlib/backend_bases.py", line 3061, in mouse_move s = self._mouse_event_to_message(event) File "/usr/lib/python3/dist-packages/matplotlib/backend_bases.py", line 3053, in _mouse_event_to_message data_str = a.format_cursor_data(data).rstrip() File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 1284, in format_cursor_data delta = abs(neighbors - data).max() File "/home/hyvaotso/ascot/ascotenv/lib/python3.10/site-packages/numpy/ma/core.py", line 4218, in sub return subtract(self, other) File "/home/hyvaotso/ascot/ascotenv/lib/python3.10/site-packages/numpy/ma/core.py", line 1020, in call__ result = self.f(da, db, *args, kwargs) File "/home/hyvaotso/ascot/ascotenv/lib/python3.10/site-packages/unyt/array.py", line 1892, in array_ufunc__ raise UnitOperationError(ufunc, u0, u1) unyt.exceptions.UnitOperationError: The <ufunc 'subtract'> operator for unyt_arrays with units "dimensionless" (dimensions "1") and "particles/degree" (dimensions "1/(angle)") is not well defined. Traceback (most recent call last): File "/usr/lib/python3/dist-packages/matplotlib/cbook/init.py", line 287, in process func(*args, **kwargs) File "/usr/lib/python3/dist-packages/matplotlib/backend_bases.py", line 3061, in mouse_move s = self._mouse_event_to_message(event) File "/usr/lib/python3/dist-packages/matplotlib/backend_bases.py", line 3053, in _mouse_event_to_message data_str = a.format_cursor_data(data).rstrip() File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 1284, in format_cursor_data delta = abs(neighbors - data).max() File "/home/hyvaotso/ascot/ascotenv/lib/python3.10/site-packages/numpy/ma/core.py", line 4218, in sub return subtract(self, other) File "/home/hyvaotso/ascot/ascotenv/lib/python3.10/site-packages/numpy/ma/core.py", line 1020, in call result = self.f(da, db, *args, **kwargs) File "/home/hyvaotso/ascot/ascotenv/lib/python3.10/site-packages/unyt/array.py", line 1892, in array_ufunc raise UnitOperationError(ufunc, u0, u1) unyt.exceptions.UnitOperationError: The <ufunc 'subtract'> operator for unyt_arrays with units "dimensionless" (dimensions "1") and "particles/degree" (dimensions "1/(angle)") is not well defined. Traceback (most recent call last): File "/usr/lib/python3/dist-packages/matplotlib/cbook/init.py", line 287, in process func(*args, *kwargs) File "/usr/lib/python3/dist-packages/matplotlib/backend_bases.py", line 3061, in mouse_move s = self._mouse_event_to_message(event) File "/usr/lib/python3/dist-packages/matplotlib/backend_bases.py", line 3053, in _mouse_event_to_message data_str = a.format_cursor_data(data).rstrip() File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 1284, in format_cursor_data delta = abs(neighbors - data).max() File "/home/hyvaotso/ascot/ascotenv/lib/python3.10/site-packages/numpy/ma/core.py", line 4218, in sub return subtract(self, other) File "/home/hyvaotso/ascot/ascotenv/lib/python3.10/site-packages/numpy/ma/core.py", line 1020, in call result = self.f(da, db, args, **kwargs) File "/home/hyvaotso/ascot/ascotenv/lib/python3.10/site-packages/unyt/array.py", line 1892, in __array_ufunc raise UnitOperationError(ufunc, u0, u1) unyt.exceptions.UnitOperationError: The <ufunc 'subtract'> operator for unyt_arrays with units "dimensionless" (dimensions "1") and "particles/degree" (dimensions "1/(angle)") is not well defined. Traceback (most recent call last): File "/usr/lib/python3/dist-packages/matplotlib/cbook/init.py", line 287, in process func(*args, kwargs) File "/usr/lib/python3/dist-packages/matplotlib/backend_bases.py", line 3061, in mouse_move s = self._mouse_event_to_message(event) File "/usr/lib/python3/dist-packages/matplotlib/backend_bases.py", line 3053, in _mouse_event_to_message data_str = a.format_cursor_data(data).rstrip() File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 1284, in format_cursor_data delta = abs(neighbors - data).max() File "/home/hyvaotso/ascot/ascotenv/lib/python3.10/site-packages/numpy/ma/core.py", line 4218, in sub return subtract(self, other) File "/home/hyvaotso/ascot/ascotenv/lib/python3.10/site-packages/numpy/ma/core.py", line 1020, in call result = self.f(da, db, *args, *kwargs) File "/home/hyvaotso/ascot/ascotenv/lib/python3.10/site-packages/unyt/array.py", line 1892, in array_ufunc__ raise UnitOperationError(ufunc, u0, u1) unyt.exceptions.UnitOperationError: The <ufunc 'subtract'> operator for unyt_arrays with units "dimensionless" (dimensions "1") and "particles/degree" (dimensions "1/(angle)") is not well defined. Traceback (most recent call last): File "/usr/lib/python3/dist-packages/matplotlib/cbook/init__.py", line 287, in process func(args, kwargs) File "/usr/lib/python3/dist-packages/matplotlib/backend_bases.py", line 3061, in mouse_move s = self._mouse_event_to_message(event) File "/usr/lib/python3/dist-packages/matplotlib/backend_bases.py", line 3053, in _mouse_event_to_message data_str = a.format_cursor_data(data).rstrip() File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 1284, in format_cursor_data delta = abs(neighbors - data).max() File "/home/hyvaotso/ascot/ascotenv/lib/python3.10/site-packages/numpy/ma/core.py", line 4218, in sub return subtract(self, other) File "/home/hyvaotso/ascot/ascotenv/lib/python3.10/site-packages/numpy/ma/core.py", line 1020, in call result = self.f(da, db, *args, kwargs) File "/home/hyvaotso/ascot/ascotenv/lib/python3.10/site-packages/unyt/array.py", line 1892, in array_ufunc__ raise UnitOperationError(ufunc, u0, u1) unyt.exceptions.UnitOperationError: The <ufunc 'subtract'> operator for unyt_arrays with units "dimensionless" (dimensions "1") and "particles/degree" (dimensions "1/(angle)") is not well defined. Traceback (most recent call last): File "/usr/lib/python3/dist-packages/matplotlib/cbook/init.py", line 287, in process func(*args, **kwargs) File "/usr/lib/python3/dist-packages/matplotlib/backend_bases.py", line 3061, in mouse_move s = self._mouse_event_to_message(event) File "/usr/lib/python3/dist-packages/matplotlib/backend_bases.py", line 3053, in _mouse_event_to_message data_str = a.format_cursor_data(data).rstrip() File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 1284, in format_cursor_data delta = abs(neighbors - data).max() File "/home/hyvaotso/ascot/ascotenv/lib/python3.10/site-packages/numpy/ma/core.py", line 4218, in sub return subtract(self, other) File "/home/hyvaotso/ascot/ascotenv/lib/python3.10/site-packages/numpy/ma/core.py", line 1020, in call__ result = self.f(da, db, *args, kwargs) File "/home/hyvaotso/ascot/ascotenv/lib/python3.10/site-packages/unyt/array.py", line 1892, in array_ufunc__ raise UnitOperationError(ufunc, u0, u1) unyt.exceptions.UnitOperationError: The <ufunc 'subtract'> operator for unyt_arrays with units "dimensionless" (dimensions "1") and "particles/degree" (dimensions "1/(angle)") is not well defined. Traceback (most recent call last): File "/usr/lib/python3/dist-packages/matplotlib/cbook/init.py", line 287, in process func(*args, **kwargs) File "/usr/lib/python3/dist-packages/matplotlib/backend_bases.py", line 3061, in mouse_move s = self._mouse_event_to_message(event) File "/usr/lib/python3/dist-packages/matplotlib/backend_bases.py", line 3053, in _mouse_event_to_message data_str = a.format_cursor_data(data).rstrip() File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 1284, in format_cursor_data delta = abs(neighbors - data).max() File "/home/hyvaotso/ascot/ascotenv/lib/python3.10/site-packages/numpy/ma/core.py", line 4218, in sub return subtract(self, other) File "/home/hyvaotso/ascot/ascotenv/lib/python3.10/site-packages/numpy/ma/core.py", line 1020, in call result = self.f(da, db, *args, **kwargs) File "/home/hyvaotso/ascot/ascotenv/lib/python3.10/site-packages/unyt/array.py", line 1892, in array_ufunc raise UnitOperationError(ufunc, u0, u1) unyt.exceptions.UnitOperationError: The <ufunc 'subtract'> operator for unyt_arrays with units "dimensionless" (dimensions "1") and "particles/degree" (dimensions "1/(angle)") is not well defined. Traceback (most recent call last): File "/usr/lib/python3/dist-packages/matplotlib/cbook/init.py", line 287, in process func(*args, *kwargs) File "/usr/lib/python3/dist-packages/matplotlib/backend_bases.py", line 3061, in mouse_move s = self._mouse_event_to_message(event) File "/usr/lib/python3/dist-packages/matplotlib/backend_bases.py", line 3053, in _mouse_event_to_message data_str = a.format_cursor_data(data).rstrip() File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 1284, in format_cursor_data delta = abs(neighbors - data).max() File "/home/hyvaotso/ascot/ascotenv/lib/python3.10/site-packages/numpy/ma/core.py", line 4218, in sub return subtract(self, other) File "/home/hyvaotso/ascot/ascotenv/lib/python3.10/site-packages/numpy/ma/core.py", line 1020, in call result = self.f(da, db, args, **kwargs) File "/home/hyvaotso/ascot/ascotenv/lib/python3.10/site-packages/unyt/array.py", line 1892, in __array_ufunc raise UnitOperationError(ufunc, u0, u1) unyt.exceptions.UnitOperationError: The <ufunc 'subtract'> operator for unyt_arrays with units "dimensionless" (dimensions "1") and "particles/degree" (dimensions "1/(angle)") is not well defined. Traceback (most recent call last): File "/usr/lib/python3/dist-packages/matplotlib/cbook/init.py", line 287, in process func(*args, *kwargs) File "/usr/lib/python3/dist-packages/matplotlib/backend_bases.py", line 3061, in mouse_move s = self._mouse_event_to_message(event) File "/usr/lib/python3/dist-packages/matplotlib/backend_bases.py", line 3053, in _mouse_event_to_message data_str = a.format_cursor_data(data).rstrip() File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 1284, in format_cursor_data delta = abs(neighbors - data).max() File "/home/hyvaotso/ascot/ascotenv/lib/python3.10/site-packages/numpy/ma/core.py", line 4218, in sub return subtract(self, other) File "/home/hyvaotso/ascot/ascotenv/lib/python3.10/site-packages/numpy/ma/core.py", line 1020, in call result = self.f(da, db, args, **kwargs) File "/home/hyvaotso/ascot/ascotenv/lib/python3.10/site-packages/unyt/array.py", line 1892, in __array_ufunc__ raise UnitOperationError(ufunc, u0, u1) unyt.exceptions.UnitOperationError: The <ufunc 'subtract'> operator for unyt_arrays with units "dimensionless" (dimensions "1") and "particles/degree" (dimensions "1/(angle)") is not well defined.

`

miekkasarki commented 9 months ago

What is the unyt version in pip list? If it is 2.9.5 as required, then we'll have to look at the code so go ahead and make a PR.