Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

tkoyama010
Copy link
Member

@tkoyama010 tkoyama010 commented Jul 10, 2025

Summary

This PR adds Principal Component Analysis (PCA) statistics computation capability to PyVista's DataSetFilters class by implementing a compute_pca_statistics method that wraps VTK's vtkPCAStatistics filter.

Changes

  • Added vtkPCAStatistics import to _vtk_core.py
  • Implemented compute_pca_statistics method in DataSetFilters class
  • Added comprehensive tests covering various use cases and error conditions
  • Follows PyVista's established patterns for filter implementation

Features

  • Compute PCA statistics on point or cell data arrays
  • Support for analyzing all arrays or specific scalar arrays
  • Returns statistical measures including means and variances
  • Progress bar support
  • Comprehensive error handling

Test plan

  • Basic functionality test with correlated data
  • Test with specific scalar array parameter
  • Test with cell data preference
  • Test with progress bar enabled
  • Test error handling for invalid parameters
  • All tests pass locally
  • Code follows linting standards

🤖 Generated with Claude Code

This commit adds Principal Component Analysis (PCA) statistics computation
capability to PyVista's DataSetFilters class. The implementation wraps VTK's
vtkPCAStatistics filter to provide easy access to PCA analysis from PyVista.

Key features:
- Compute PCA statistics on point or cell data arrays
- Support for analyzing all arrays or specific scalar arrays
- Returns meaningful statistical measures including means and variances
- Comprehensive test coverage with error handling
- Follows PyVista's established patterns for filter implementation

The method integrates seamlessly with PyVista's existing API and provides
a Pythonic interface to VTK's statistical capabilities for data analysis
and dimensionality reduction tasks.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@tkoyama010 tkoyama010 marked this pull request as draft July 10, 2025 17:01
@pyvista-bot pyvista-bot added the enhancement Changes that enhance the library label Jul 10, 2025
Copy link

codecov bot commented Jul 10, 2025

Codecov Report

Attention: Patch coverage is 92.15686% with 4 lines in your changes missing coverage. Please review.

Project coverage is 96.26%. Comparing base (7879962) to head (e1679ae).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7694      +/-   ##
==========================================
- Coverage   96.38%   96.26%   -0.12%     
==========================================
  Files         150      150              
  Lines       32527    32578      +51     
  Branches     4114     4129      +15     
==========================================
+ Hits        31351    31362      +11     
- Misses        569      593      +24     
- Partials      607      623      +16     

Add type ignore comment for unreachable code warning when checking
preference parameter that is already constrained by Literal type.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@tkoyama010 tkoyama010 changed the title Add vtkPCAStatistics features to PyVista Add compute_pca_statistics method to DataSetFilters Jul 11, 2025
tkoyama010 and others added 7 commits July 10, 2025 17:10
- Add missing return type annotation: -> pyvista.Table
- Fix docstring example to use correct output keys ('means' instead of 'eigenvalues')
- Update Returns section to accurately describe the actual output structure

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
When no meaningful data is extracted in compute_pca_statistics,
return an empty Table as declared in the return type annotation
instead of trying to return a wrapped multiblock output.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Add test for KeyError when scalar not found in point data
- Add test for KeyError when scalar not found in cell data
- Improve test coverage for uncovered lines

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@tkoyama010 tkoyama010 marked this pull request as ready for review July 11, 2025 09:55
@pyvista-bot
Copy link
Contributor

pyvista-bot commented Jul 11, 2025

@pyvista-bot pyvista-bot temporarily deployed to pull request July 11, 2025 12:16 Inactive
Add tests for specific scalar arrays, result field validation, and empty mesh handling to improve test coverage of the compute_pca_statistics functionality.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@pyvista-bot pyvista-bot temporarily deployed to pull request July 11, 2025 20:19 Inactive
@user27182 user27182 self-requested a review July 12, 2025 03:16
Copy link
Contributor

@user27182 user27182 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vtkPCAStatistics looks really interesting and powerful. But compute_pca_statistics seems to only implement very basic parts of that class to compute the mean and variance of arrays, which doesn't seem much more useful than using np.mean and np.var on the arrays directly.
If we could expand on this class and bit and show its use with an example like dimensionality reduction, I think it would make this more useful. There is vtk demo:
https://examples.vtk.org/site/PythonicAPI/Utilities/PCADemo/

@tkoyama010 tkoyama010 marked this pull request as draft July 20, 2025 04:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Changes that enhance the library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants