render_volume#
- crispy.visualize.render_volume(cube, savename=None, showfig=False, vmin=None, vmax=None, surface_count=12, opacity=None, colorscale='YlGnBu', z_stretch=1, showscale=True, fig=None, val_fill=0.0, cbar_label='')[source]#
Render a 3D volume using layers of isosurfaces.
This function creates a 3D interactive volume rendering visualization of a 3D data cube by plotting multiple isosurfaces at specified value intervals.
- Parameters:
cube (numpy.ndarray or str) – A 3D numpy array of float values or a file path to a FITS file. If the input is a file path, the data will be loaded and used. NaN values are replaced with val_fill before rendering.
savename (str, optional) – Path to save the interactive HTML file. If None, the figure is not saved. Default is None.
showfig (bool, optional) – Whether to display the figure interactively. Default is False.
vmin (float, optional) – Minimum isosurface value. If None, the 10-sigma level above the estimated RMS is used. Default is None.
vmax (float, optional) – Maximum isosurface value. If None, the 99.99th percentile of the data is used. Default is None.
surface_count (int, optional) – Number of isosurfaces to plot. Higher values create finer visualization but increase rendering cost. Default is 12.
opacity (float, optional) – Opacity of the isosurfaces. If None, it is set to 2 / surface_count for semi-transparency. Default is None.
colorscale (str, optional) – Colormap for the isosurfaces. Uses Plotly-compatible colormap names. Default is “YlGnBu”.
z_stretch (float, optional) – Scaling factor for the Z-axis to modify aspect ratio. Default is 1.
showscale (bool, optional) – Whether to display the color scale bar. Default is True.
fig (plotly.graph_objects.Figure, optional) – Existing Plotly figure to add the volume rendering to. If None, a new figure is created. Default is None.
val_fill (float, optional) – Value to replace NaN voxels in the cube. Default is 0.0.
cbar_label (str, optional) – Label for the colorbar. Default is an empty string.
- Returns:
The Plotly figure object containing the 3D volume rendering.
- Return type:
plotly.graph_objects.Figure
Notes
NaN values in the cube are replaced with val_fill before visualization.
Isosurface values range between vmin and vmax, divided into surface_count levels.
The visualization requires non-NaN input data for accurate results.
Examples
>>> import numpy as np >>> X, Y, Z = np.mgrid[-1:1:30j, -1:1:30j, -1:1:30j] >>> cube = np.sin(np.pi * X) * np.cos(np.pi * Z) * np.sin(np.pi * Y) >>> render_volume(cube, showfig=True, surface_count=10)