vedo
vedo copied to clipboard
How to use masked array in vedo
Dear all, I have tried using a masked array in Volume and Slicer3DPlotter utility, but it did not work. How can I do that?
Yuo need to be more specific! What have you tried to do that did not work?
I'm sorry I didn't make myself clear. The following code works well:
import numpy as np
from vedo import Volume, show
X, Y, Z = np.mgrid[:30, :30, :30]
scalar_field = ((X-15)**2 + (Y-15)**2 + (Z-15)**2) /225
vol = Volume(scalar_field)
vol.addScalarBar3D()
But it doesn't seem to work if use a masked array like this:
import numpy as np
from vedo import Volume, show
import numpy.ma as ma
X, Y, Z = np.mgrid[:30, :30, :30]
scalar_field = ((X-15)**2 + (Y-15)**2 + (Z-15)**2) /225
scalar_field[15,15,15] = -9999
scalar_field = ma.masked_where(scalar_field<0,scalar_field)
vol = Volume(scalar_field)
vol.addScalarBar3D()
Hi, sorry numpy.ma
are not supported, but you can use vol.threshold(below=0, replace=0)
to cure the array.
Thanks for your reply,but that's not exactly what I want. I don't want the area to be masked to be filled with any value. For example, to show the water temperature distribution in the ocean, I need to mask the seabed terrain instead of filling in other values for the seabed area. I think it's a pity that numpy.ma are not supported. Do you have any good suggestions for that case? Thanks.
I see.. but would it only be for the sake of visualisation then? If so it's probably easy to implement.
Yeah, for the sake of visualisation only. I'm a beginner to veto. My purpose is to visualize the ocean simulation results, which is required to mask the land and seabed terrain.
Hi sorry for the long wait, you may try with this example
pip install -U git+https://github.com/marcomusy/vedo.git
from vedo import np, Volume, show
data_matrix = np.zeros([75, 75, 75], dtype=np.uint8)
# all voxels have value zero except:
data_matrix[0:35, 0:35, 0:35] = 1
data_matrix[35:55, 35:55, 35:55] = 2
data_matrix[55:74, 55:74, 55:74] = 3
vol = Volume(data_matrix, c=['white','b','g','r'], mapper='gpu')
data_mask = np.zeros_like(data_matrix)
data_mask[10:65, 10:45, 20:75] = 1
vol.mask(data_mask)
show(vol, axes=1).close()