fmihpc / analysator

Python based package for analyzing vlsv files produced by Vlasiator
GNU General Public License v2.0
5 stars 32 forks source link

Added check to catch masked constants in read_interpolated_variable #247

Closed JonasSuni closed 2 weeks ago

JonasSuni commented 3 weeks ago

This is a fix for PR #82 :

The problem is that if for any reason the test_variable used in read_interpolated_variable is masked, isinstance(test_variable, Iterable) will return True but value_length=len(test_variable) will throw the error TypeError: len() of unsized object. This is because the masked value is of type np.ma.core.MaskedConstant, which inherits the property of Iterable from somewhere, but it's actually not iterable.

This PR adds an additional check for np.ma.core.MaskedConstant and sets value_length=1 if the value is masked.

alhom commented 3 weeks ago

This snippet is repeated everywhere. I added helper function to read the vectorsize of a variable from vlsv file to reduce code duplication, but it does not work on datareducers.

MaskedConstant inherits numpy.ndarray, so it has a .size and a .shape, which is what we just went through yesterday with @kostahoraites for a similar fix (in some place, I forget which...).