pyRTX.visual.utils
Functions
|
Converts a color to a list of colors of a specified size. |
|
Plots one or more trimesh meshes using matplotlib. |
|
Visualize a planet mesh with color-mapped field values on its surface. |
- pyRTX.visual.utils.color_convert(color, size=1)[source]
Converts a color to a list of colors of a specified size.
- pyRTX.visual.utils.plot_mesh(mesh, title='3D Mesh', figsize=(10, 8), alpha=0.7, edge_color='k', face_color=None, labels=None, elev=30, azim=45)[source]
Plots one or more trimesh meshes using matplotlib.
- Parameters:
mesh (
trimesh.Trimeshorlistoftrimesh.Trimesh) – The mesh or meshes to plot.title (
str, default"3D Mesh") – The title of the plot.figsize (
tuple, default(10,8)) – The size of the figure in inches.alpha (
float, default0.7) – The transparency of the mesh faces.edge_color (
strorlistofstr, default'k') – The color of the mesh edges.face_color (
str,listofstr, orNone, optional) – The color of the mesh faces. If None, automatic colors are used.labels (
listofstr, optional) – Labels for each mesh, for use in the legend.elev (
float, default30) – The elevation viewing angle in degrees.azim (
float, default45) – The azimuthal viewing angle in degrees.
- Returns:
A tuple containing the matplotlib figure and axis objects.
- Return type:
Examples
>>> # Single mesh with default colors >>> fig, ax = plot_mesh(mesh)
>>> # Single mesh with custom color >>> fig, ax = plot_mesh(mesh, face_color='lightblue')
>>> # Multiple meshes with automatic colors >>> fig, ax = plot_mesh([mesh1, mesh2, mesh3])
>>> # Multiple meshes with custom colors >>> fig, ax = plot_mesh([mesh1, mesh2], ... face_color=['red', 'blue'], ... labels=['Mesh 1', 'Mesh 2'])
>>> # Custom viewing angle (top-down view) >>> fig, ax = plot_mesh(mesh, elev=90, azim=0)
>>> # Side view >>> fig, ax = plot_mesh(mesh, elev=0, azim=0)
- pyRTX.visual.utils.visualize_planet_field(planet, field='temperature', epoch=None, cmap='viridis', figsize=(12, 10), show_colorbar=True, title=None, vmin=None, vmax=None, lighting=True, show_sun=False, elev=30, azim=45)[source]
Visualize a planet mesh with color-mapped field values on its surface.
Creates a 3D visualization of the planet with face colors representing physical properties such as temperature, albedo, or emissivity. Optionally displays the Sun direction vector. Useful for verifying planetary models and understanding spatial distributions of surface properties.
- Parameters:
planet (
Planet) – Planet object containing mesh geometry and surface properties.field (
str, default'temperature') –Surface field to visualize. Options:
’temperature’: Surface temperature (K)
’albedo’: Bond albedo (0-1)
’emissivity’: Infrared emissivity (0-1)
’area’: Face areas (for geometric verification)
epoch (
floatorNone, defaultNone) – SPICE ephemeris time for time-dependent fields. Required if temperature varies with time or if show_sun=True. If None, uses static values.cmap (
str, default'viridis') –Matplotlib colormap name. Common choices:
’viridis’: Good for temperature (dark to bright)
’plasma’: Alternative for temperature
’coolwarm’: Diverging colormap
’RdYlBu_r’: Red-yellow-blue (reversed)
figsize (
tuple, default(12,10)) – Figure size in inches (width, height).show_colorbar (
bool, defaultTrue) – If True, display colorbar showing the mapping from values to colors.title (
strorNone, defaultNone) – Custom plot title. If None, automatically generated based on field name.vmin (
floatorNone, defaultNone) – Minimum value for color scale. If None, uses data minimum.vmax (
floatorNone, defaultNone) – Maximum value for color scale. If None, uses data maximum.lighting (
bool, defaultTrue) – If True, apply directional lighting for better 3D perception. If False, use flat shading showing colors directly.show_sun (
bool, defaultFalse) – If True, draw an arrow showing the Sun direction. Requires epoch, spacecraft_name, and reference_frame to be specified.spacecraft_name (
strorNone, defaultNone) – Name of spacecraft for SPICE queries (e.g., ‘LRO’). Required if show_sun=True.reference_frame (
strorNone, defaultNone) – Reference frame for Sun direction vector (e.g., ‘LRO_SC_BUS’). Required if show_sun=True.elev (
float) – Elevation viewing angle in degrees (default: 30)azim (
float) – Azimuthal viewing angle in degrees (default: 45)
- Returns:
fig (
matplotlib.figure.Figure) – The figure object.ax (
matplotlib.axes.Axes) – The 3D axes object.
Notes
The function retrieves field values using Planet object methods: - Temperature: planet.getFaceTemperatures(epoch) - Albedo: planet.getFaceAlbedo() - Emissivity: planet.getFaceEmissivity()
Face colors are computed by mapping field values to the colormap range. The mesh is displayed using matplotlib’s 3D projection with face colors.
When show_sun=True, a yellow arrow is drawn from the planet center pointing toward the Sun. The arrow length is scaled to 1.5× the planet’s maximum dimension for visibility. The Sun position is queried from SPICE using the provided spacecraft_name and reference_frame.
For large meshes (>10000 faces), rendering may be slow. Consider using mesh subdivision or decimation to reduce face count.
Examples
>>> import spiceypy as sp >>> from pyRTX.classes import Planet >>> >>> # Create planet with temperature map >>> moon = Planet(name='Moon', radius=1737.4) >>> moon.dayside_temperature = 400 >>> moon.nightside_temperature = 100 >>> >>> # Visualize temperature at specific epoch with Sun direction >>> epoch = sp.str2et('2024-01-01T12:00:00') >>> fig, ax = visualize_planet_field(moon, field='temperature', ... epoch=epoch, cmap='plasma', ... show_sun=True, ... spacecraft_name='LRO', ... reference_frame='MOON_PA') >>> >>> # Visualize constant albedo >>> moon.albedo = 0.12 >>> fig, ax = visualize_planet_field(moon, field='albedo', cmap='gray')
See also
Planet.getFaceTemperaturesGet temperature values for mesh faces
Planet.getFaceAlbedoGet albedo values for mesh faces
Planet.getFaceEmissivityGet emissivity values for mesh faces
trimesh.Trimesh.visualTrimesh visualization utilities