Nan is legacy ascii files

Hi, I am reading some ascii vtk files, and based on the properties (on the SCALARS section of the file) I want to replace values less than a threshold to NaN.

I read some previous posts and it seems that NaN is not supported to ascii files. Is any trick that I can set the nan to a value (say -99) and then make it transparent in paraview?

First, I’ll say that if all that you are interested in is removing or making invisible all values of a certain type, you can use the Threshold filter to remove cells based on field values.

If for other reasons you want to keep all the points but make some NaN values, you can use the Programmable Filter to write a numpy expression that changes all values matching an expression to NaN. Add a Programmable Filter and use something like the following for the Script to make all values less than 0 be NaN:

indata = inputs[0].PointData['field_name']

# Copy numpy array
outdata = numpy.array(indata)
# Replace some values with NaN
outdata[outdata < 0] = float('nan')

output.PointData.append(outdata, 'field_name')

Of course, change field_name to the name of the scalars in your data. You can also change the outdata < 0 expression to something like outdata == -99. However, using == with floating point numbers sometimes does not work, so I would suggest using something like (outdata < -98.9) & (outdata > -99.1) instead.