Note
This page was generated from a Jupyter notebook.
Download: interactive_features.ipynb
Interactive Features in cdiutils#
This notebook demonstrates the interactive visualisation and data exploration tools available in cdiutils:
``plot_3d_isosurface``: Interactive 3D isosurface plotting with multiple quantities
``ThreeDViewer``: Widget for exploring complex 3D arrays (amplitude + phase)
``TabPlotData``: Interactive browser for exploring CDI reconstruction results
Installation#
These features require additional dependencies:
pip install cdiutils[interactive]
Or install individually:
pip install plotly scikit-image scipy ipywidgets h5glance
[ ]:
import numpy as np
import cdiutils
from cdiutils.interactive import TabPlotData, ThreeDViewer, plot_3d_isosurface
cdiutils.update_plot_params()
[ ]:
# load reconstruction data from CXI file (here, we assume it has been generated by CDIutils pipeline)
data_path = ""
data = cdiutils.io.load_cxi(
data_path,
"amplitude",
"phase",
"het_strain",
"lattice_parameter",
"dspacing",
"support",
)
voxel_size = cdiutils.io.load_cxi(data_path, "voxel_size")
print(f"Data shape: {data['amplitude'].shape}")
print(f"Voxel size: {voxel_size} nm")
plot_3d_isosurface#
Interactive isosurface plot with multiple quantities. Features:
Threshold slider: control isosurface level
Quantity dropdown: switch between different data arrays
Colormap dropdown: choose from 20+ colormaps
Colorbar controls: auto-scale, symmetric mode, or manual limits
Replace NaN checkbox: replace NaN values with mean to avoid artefacts
[ ]:
plot_3d_isosurface(
data["amplitude"],
data,
voxel_size=voxel_size,
)
ThreeDViewer Class#
A widget for exploring complex 3D arrays (amplitude + phase). Features:
Threshold slider: control isosurface level based on amplitude
Phase/Amplitude toggle: switch between phase and amplitude display
Colormap dropdown: choose from 20+ colormaps
Colorbar controls: auto-scale, symmetric mode, or manual limits
Replace NaN checkbox: replace NaN values with mean
Rotation toggle: enable continuous rotation animation
Theme toggle: switch between light and dark themes
[ ]:
# create complex 3D array
complex_3d = data["amplitude"] * np.exp(1j * data["phase"])
# create viewer
viewer = ThreeDViewer(complex_3d, voxel_size=voxel_size, figsize=(9, 6))
viewer.show()
Notes#
Try adjusting the threshold slider to explore different isosurface levels
Use the colormap dropdown to find the best visualisation for your data
Enable “Replace NaN with mean” if you see unusual colours (NaN artefacts)
For strain data, use symmetric colorbar with diverging colormaps like “cet_CET_D13”
The dark theme can be helpful when working in low-light environments
TabPlotData Class#
An interactive browser for exploring CDI reconstruction results from a folder structure. Features:
Tab navigation: browse through different scans and reconstructions
Interactive plots: 2D slices and 3D visualisations
Data inspection: view metadata and reconstruction parameters
Quick comparison: easily compare results from different scans
[ ]:
path_to_results_dir = ""
tab = TabPlotData(path_to_results_dir)
tab.show()