fmihpc/analysator

read_interpolated_fsgrid_variable() array size bug?

Closed this issue · 6 comments

I ran into an issue while trying to interpolate the EGI electric field, with the following snippet:

import pytools as pt
vlsv = pt.vlsvfile.VlsvReader('/wrk-vakka/group/spacephysics/vlasiator/3D/EGI/bulk/dense_cold_hall1e5_afterRestart374/bulk1.000{}.vlsv'.format(1000))
E = vlsv.read_interpolated_fsgrid_variable('fg_e', [1e8, 0,0])

The error message includes this line:

ValueError: cannot reshape array of size 1664090112 into shape (1024,736,736)

Looks like there's a mismatch of array sizes, since 1664090112 = (1024736736736) * 3 I'm thinking that maybe this function doesn't account for the 3 spatial dimensions of the vector field?

One workaround might be to read the 3 interpolated components of the field individually, using the operator keyword. But, trying the same function call, with operator='x' results in a different error.

Can you post exactly what the errors were and on what lines of vlsvreader.py they are occurring?

Sure!
`

E = vlsv.read_interpolated_fsgrid_variable('fg_e', [1e8, 0,0])
Did not find FsGrid decomposition from vlsv file.
Calculating fsGrid decomposition from the file
Computed FsGrid decomposition to be: [32, 16, 16]
Traceback (most recent call last):
File "", line 1, in
File "/proj/horakons/analysator/pyVlsv/vlsvreader.py", line 1112, in read_interpolated_fsgrid_variable
fg_data=np.reshape(fg_data,fg_size)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<array_function internals>", line 200, in reshape
File "/wrk-vakka/appl/easybuild/opt/Anaconda3/2023.09-0/lib/python3.11/site-packages/numpy/core/fromnumeric.py", line 298, in reshape
return _wrapfunc(a, 'reshape', newshape, order=order)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/wrk-vakka/appl/easybuild/opt/Anaconda3/2023.09-0/lib/python3.11/site-packages/numpy/core/fromnumeric.py", line 57, in _wrapfunc
return bound(*args, **kwds)
^^^^^^^^^^^^^^^^^^^^
ValueError: cannot reshape array of size 1664090112 into shape (1024,736,736)
`

and

`

E = vlsv.read_interpolated_fsgrid_variable('fg_e', [1e8, 0,0], operator="x")
Traceback (most recent call last):
File "", line 1, in
File "/proj/horakons/analysator/pyVlsv/vlsvreader.py", line 1191, in read_interpolated_fsgrid_variable
ret.append(interpolateSingle(r))
^^^^^^^^^^^^^^^^^^^^
File "/proj/horakons/analysator/pyVlsv/vlsvreader.py", line 1155, in interpolateSingle
if (len(r) !=3 ):
^^^^^^
TypeError: object of type 'float' has no len()
`

Ok I see what the issue is with the one where you pass operator="x": the coordinates argument is supposed to be a list of lists, you are passing it the coordinates of one point as a list of floats. Wrap your input coordinates in another list and it should work.

For the first error, hmm, yeah, vector variable functionality seems to not have been implemented. That can probably be fixed with a pull request at some point

Yep, the operator keyword works just fine for getting vector components. So with with that workaround, this issue becomes a lot less concerning.

But as you say, it would be nice to have vector variable functionality.

That will need to account for the different variable centerings, so there's a bit of more hassle with that. Some of that is already in the static_tracer functions, though.

We returned to this during today's merge day.
Commenting out a couple lines fixed the issues with the function. In the latest PR, fg_b data can be interpolated.

We also concluded that read_interpolated_fsgrid_variable() probably needs to be re-implemented to handle face- vs. edge-centered variables.