vedo icon indicating copy to clipboard operation
vedo copied to clipboard

How to use masked array in vedo

Open lidong74 opened this issue 2 years ago • 7 comments

Dear all, I have tried using a masked array in Volume and Slicer3DPlotter utility, but it did not work. How can I do that?

lidong74 avatar Apr 21 '22 08:04 lidong74

Yuo need to be more specific! What have you tried to do that did not work?

marcomusy avatar Apr 21 '22 10:04 marcomusy

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()

lidong74 avatar Apr 23 '22 03:04 lidong74

Hi, sorry numpy.ma are not supported, but you can use vol.threshold(below=0, replace=0) to cure the array.

marcomusy avatar Apr 23 '22 11:04 marcomusy

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.

lidong74 avatar Apr 25 '22 01:04 lidong74

I see.. but would it only be for the sake of visualisation then? If so it's probably easy to implement.

marcomusy avatar Apr 25 '22 08:04 marcomusy

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.

lidong74 avatar Apr 25 '22 11:04 lidong74

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()

marcomusy avatar May 06 '22 12:05 marcomusy