feat: Implement interactive 3D feature visualization #1345
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New Feature: Interactive 3D Feature View
This pull request introduces a new 3D feature view, allowing for interactive visualization of spike features in a 3D scatter plot. This provides a more intuitive way to explore the relationships between different principal components and other spike attributes.
The rotation is powered by a standard Yaw-Pitch camera model. Holding Shift while dragging the mouse controls the camera's pitch (up/down rotation around the X-axis) and yaw (left/right rotation around the Y-axis) around the data's center.
Technically, this is implemented in the _create_rotation_matrix function, which builds two separate 3x3 rotation matrices, R_x (for pitch) and R_y (for yaw). These are combined via matrix multiplication (R_x @ R_y) into a single transformation matrix. Applying yaw first and then pitch results in a smooth and intuitive orbiting behavior. This final matrix transforms the 3D feature coordinates before they are projected onto the 2D screen, creating a responsive exploration experience.
Key Features
Interactive 3D Scatter Plot: A new Feature3DView has been added to display features in a 3D space.
Rotation and Zoom: Users can rotate, pan, and zoom the 3D view to inspect the data from any angle.
Customizable Axes: The X, Y, and Z axes can be mapped to different principal components or other spike attributes.
Lasso Selection: Spikes can be selected in the 3D view using a lasso tool for further analysis or clustering.
Implementation Details
Created a new Feature3DView class in phy/cluster/views/featureview3d.py.
Integrated the new view into the TemplateGUI in phy/apps/template/gui.py.
Updated phy/gui/qt.py and other files to support the new view.
How to Test This Branch
These instructions outline how to set up a clean conda environment to test the changes in this PR. This assumes a base installation of Miniconda and an environment created with Python 3.11.
1. Install Git in Conda
If git is not already available in the environment, install it:
conda install git -y
2. Clone This Specific Branch
This command clones only the feature-3d-view branch into a new folder named phy-feature-3d-view.
(Note: Replace C:\Users\YourUsername\Desktop with your desired location.)
First, navigate to your desired directory:
cd C:\Users\YourUsername\Desktop
Then, run the clone command:
git clone --branch feature-3d-view --single-branch https://github.com/bshihab/phy.git phy-feature-3d-view
3. Install Dependencies
Navigate into the new directory and install the package in editable mode.
A critical step is to pin joblib to version 1.2.0. I found that recent versions of joblib are incompatible and cause the GUI to crash on launch due to a removed keyword argument in the Memory class.
First, change into the repository folder:
cd phy-feature-3d-view
Ensure pip and its core tools are up to date:
python -m pip install --upgrade pip setuptools wheel
Install the package in editable mode. This will install most dependencies from requirements.txt:
python -m pip install -e .
Install the full set of core dependencies with pinned versions to ensure stability:
python -m pip install joblib==1.2.0 pyopengl==3.1.6 numpy traitlets matplotlib click PyQt5 PyQtWebEngine qtconsole scipy toolz requests dask h5py cython
After these steps, the environment is ready for testing the new features.