Quentin Delaunay
Quentin Delaunay

Reputation: 1

How do I align a texture on mayavi (using tvtk) with data around the earth in python?

I have calculated emissions of supersonic planes going around the earth. I now want to visualize it. Matplotlib being absolutely terrible at it, I decided to do it with mayavi in python.

I can correctly generate a sphere with the display of the data around it, but my data (originaly in lat,long,alt converted in cartesian) does NOT align correctly with the texture (while it's not a problem with matplotlib, the texture is correctly displayed, with the right orientation).

Here is the visual I have:

Earth with data not correctly displayed
As you can see, the USA should be align with a lot of the emissions computed. But it's not the case and I can't find a way to properly align the texture with the data.

Here is my code (just the relevant part):

import netCDF4
import numpy as np
from mayavi import mlab
from tvtk.api import tvtk
from metpy.calc import pressure_to_height_std
from metpy.units import units

# Mayavi figure for visualization
    fig = mlab.figure(size=(800, 600))
    
    # Plot Earth texture
    img = tvtk.JPEGReader()
    img.file_name = texture_image_path
    texture = tvtk.Texture(input_connection=img.output_port, interpolate=1)
    sphere = tvtk.TexturedSphereSource(radius=earth_radius, theta_resolution=500, phi_resolution=500 )
    sphere_mapper = tvtk.PolyDataMapper(input_connection=sphere.output_port)
    sphere_actor = tvtk.Actor(position=(0, 0, 0),mapper=sphere_mapper, texture=texture, orientation=(1,1,0))
    fig.scene.add_actor(sphere_actor)
    
    # Plot emissions
    sc = mlab.points3d(
        emissions_x, emissions_y, emissions_z, emissions_values,
        color=(1, 0, 0), opacity=1,
    )

    mlab.title(f"3D Visualization of {variable_name} Emissions")
    mlab.show()

    nc_file.close()

I tried to play with the orientation of the sphere hoping the texture would follow, and it doesn't seem to be the case.
I also tried to find a way to specify coordinates to map the texture correctly.

Upvotes: 0

Views: 18

Answers (0)

Related Questions