louis-richard / irfu-python

Python routines to work with space data, particularly with MMS data. Also some general plasma routines.
MIT License
15 stars 3 forks source link

plot_projection() is unable to plot VDFs where energy bins are equivalent to less than the spacecraft potential #16

Open harryclewis opened 7 months ago

harryclewis commented 7 months ago

The problem seems to come from the vdf_projection function, which is taking the square root of shifted energy bins. When the bins are smaller than the spacecraft potential, they are shifted to negative numbers and the np.sqrt() function is returning nan. The pcolormesh function can't accept nans as bin coordinates, which causes an error in plot_projection.py.

To fix this, I suggest np.sqrt(..., dtype=np.csingle) or np.emath.sqrt(...) on line 348 of vdf_projection.py.

Doing this gives 0 for the "negative" velocity bins, which I believe to be your intention based on the np.real() function on line 349. However, it might not be the perfect solution as it stretches the innermost bin to the center of the polar plot.

If you need an example timestep, use 1475257837.6974614 a.k.a ['2016-09-30T17:50:37.697'].

Running on pyrfu version 2.4.12 but with dependencies installed for 2.4.11 (see my other issue).

Hope this helps.

carawaters commented 3 months ago

Same issue experienced - as suggested above, np.sqrt(..., dtype=np.csingle) does fix the issue but stretches the innermost bin to the centre - example below. Have not yet found a better solution to this, and not sure if any other solution would make sense.

26