titusjan / argos

Argos: a data viewer that can read HDF5, NetCDF4, and other file formats.
GNU General Public License v3.0
176 stars 26 forks source link

Image plot crosshair fails on NetCDF scalars set to fill value. #16

Closed titusjan closed 3 years ago

titusjan commented 3 years ago

When cross hair plots are enabled in the Image Plot inspector, and the user hovers above plot, and the selected item is a NetCDF scalar set to the fill value, the application exits with the following error:

Traceback (most recent call last):
  File "C:\Users\kenter\Documents\src\argos\argos\inspector\pgplugins\imageplot2d.py", line 587, in mouseMoved
    rowData = replaceMaskedValueWithFloat(rowData, np.isinf(rowData),
  File "C:\Users\kenter\Documents\src\argos\argos\utils\masks.py", line 252, in replaceMaskedValueWithFloat
    return replaceMaskedValue(data, mask, replacementValue, copyOnReplace=copyOnReplace)
  File "C:\Users\kenter\Documents\src\argos\argos\utils\masks.py", line 231, in replaceMaskedValue
    result[mask] = replacementValue
ValueError: assignment destination is read-only

This can be reproduced with the scalars.nc/masked_scalar item that can be generated by create_test_data.py

titusjan commented 3 years ago

The problem was that, apparently, ma.copy doesn't copy all the data. After copying the OWNDATA and WRITEABLE flags where still False.

Starting from Numpy 1.19.0, np.copy(..., subok=True) can be used to copy masked arrays as well. This fixes the issue.