How can I plot data on the globe using Mayavi?

35 Views Asked by At

I wanted to plot the Indian ocean data on a globe. I am not able to get the proper positioning of the plot. https://github.com/rajivjha0599/cdf is the link to cdf file i've been working with. Another problem is that I am not able to plot all the points and the window crashes without completing the plotting and i'm only able to plot 100 points.

from mayavi import mlab
import numpy as np
from mayavi.sources.builtin_surface import BuiltinSurface
import xarray as xr
dataset = xr.open_dataset('indian_ocean.nc', decode_times=False)

# Extract latitude, longitude, and temperature data
latitude = dataset['LAT64_1376'].values
longitude = dataset['LON2501_3751'].values
temperature = dataset['WATER_TEMP'].values[0, 0, :, :]

mlab.figure(1, bgcolor=(0.48, 0.48, 0.48), fgcolor=(0, 0, 0),
               size=(400, 400))
continents_src = BuiltinSurface(source='earth', name='Continents')
continents_src.data_source.on_ratio = 1
continents = mlab.pipeline.surface(continents_src, color=(0, 0, 0))
sphere = mlab.points3d(0, 0, 0, scale_mode='none',
                                scale_factor=2,
                                color=(0.67, 0.77, 0.93),
                                resolution=50,
                                opacity=0.7,
                                name='Earth')
# These parameters, as well as the color, where tweaked through the GUI,
# with the record mode to produce lines of code usable in a script.
sphere.actor.property.specular = 0.45
sphere.actor.property.specular_power = 5
# Backface culling is necessary for more a beautiful transparent
# rendering.
sphere.actor.property.backface_culling = True

theta = np.linspace(0, 2 * np.pi, 100)

for angle in (- np.pi / 6, 0, np.pi / 6):
    x = np.cos(theta) * np.cos(angle)
    y = np.sin(theta) * np.cos(angle)
    z = np.ones_like(theta) * np.sin(angle)

    mlab.plot3d(x, y, z, color=(1, 1, 1),
                        opacity=0.2, tube_radius=None)

mlab.view(63.4, 73.8, 4, [-0.05, 0, 0])
########################################################
#######################################################################

test=[]
for lat in latitude:
    for long in longitude:
       x = np.cos(long* np.pi / 180) * np.cos(lat* np.pi / 180)
       y = np.cos(long* np.pi / 180) * np.sin(lat* np.pi / 180)
       z = np.sin(long* np.pi / 180) 
       test.append([x,y,z]) 
       print(len(test))
       #points = mlab.points3d(x, y, z,scale_mode='none',scale_factor=0.03,color=(0, 0, 1))
for element in test[1:100]:
    points = mlab.points3d(element[0], element[1], element[2],scale_mode='none',scale_factor=0.03,color=(0, 0, 1))
#######################################################################
######################################################
mlab.show()
0

There are 0 best solutions below