Skip to content

refactor: comprehensive code review fixes and optimizations#44

Open
vudxlab wants to merge 3 commits intodagghe:mainfrom
vudxlab:claude/review-and-optimize-9VWit
Open

refactor: comprehensive code review fixes and optimizations#44
vudxlab wants to merge 3 commits intodagghe:mainfrom
vudxlab:claude/review-and-optimize-9VWit

Conversation

@vudxlab
Copy link

@vudxlab vudxlab commented Jan 12, 2026

This commit addresses multiple code quality issues, performance bottlenecks, and potential bugs identified during a comprehensive codebase review:

HIGH PRIORITY FIXES:

  • Remove debug print statements from ssi.py (lines 138, 141) left in production
  • Fix variable shadowing in ssi.py line 147 (variable 'j' used in nested loops)
  • Optimize O(n²) array building in ssi.py - replace inefficient np.vstack in loop with pre-allocated arrays for better performance
  • Replace ambiguous variable name 'l' with 'num_channels' throughout ssi.py for improved readability and maintainability

MEDIUM PRIORITY FIXES:

  • Add warning comments for global np.seterr() in ssi.py and plscf.py to document potential issues with global error suppression
  • Improve exception handling in gen.py - replace overly broad Exception catches with specific exceptions (ValueError, ZeroDivisionError, np.linalg.LinAlgError) and add debug logging
  • Fix comparison pattern in plscf.py - replace 'check.any() == False' with cleaner 'not check.any()' syntax

LOW PRIORITY FIXES:

  • Remove unnecessary self-assignments in setup/single.py
  • Convert inline comments to proper documentation format
  • Remove commented debug statement from clus.py
  • Fix typo in comment: 'channnels' -> 'channels'

These changes improve code quality, performance, and maintainability without altering the external API or functionality.

claude and others added 3 commits January 12, 2026 17:33
This commit addresses multiple code quality issues, performance bottlenecks,
and potential bugs identified during a comprehensive codebase review:

HIGH PRIORITY FIXES:
- Remove debug print statements from ssi.py (lines 138, 141) left in production
- Fix variable shadowing in ssi.py line 147 (variable 'j' used in nested loops)
- Optimize O(n²) array building in ssi.py - replace inefficient np.vstack
  in loop with pre-allocated arrays for better performance
- Replace ambiguous variable name 'l' with 'num_channels' throughout ssi.py
  for improved readability and maintainability

MEDIUM PRIORITY FIXES:
- Add warning comments for global np.seterr() in ssi.py and plscf.py
  to document potential issues with global error suppression
- Improve exception handling in gen.py - replace overly broad Exception
  catches with specific exceptions (ValueError, ZeroDivisionError,
  np.linalg.LinAlgError) and add debug logging
- Fix comparison pattern in plscf.py - replace 'check.any() == False'
  with cleaner 'not check.any()' syntax

LOW PRIORITY FIXES:
- Remove unnecessary self-assignments in setup/single.py
- Convert inline comments to proper documentation format
- Remove commented debug statement from clus.py
- Fix typo in comment: 'channnels' -> 'channels'

These changes improve code quality, performance, and maintainability
without altering the external API or functionality.
Add new `interactive=True` parameter to plot_stab() method in SSI and
pLSCF algorithms, enabling interactive pole selection with spectrum
overlay in a single unified interface.

Key features:
- Interactive GUI for pole selection using Tkinter
- Real-time spectrum (CMIF) overlay on secondary axis
- Toggle spectrum visibility during picking session
- Menu controls for unstable poles and spectrum
- Consistent API across SSI and pLSCF algorithms

Changes:
- src/pyoma2/support/sel_from_plot.py:
  * Add spectrum and nSv parameters to __init__
  * Add spectrum overlay support in plot_stab method
  * Add toggle_spectrum() method for runtime control
  * Add "Spectrum Overlay" menu for interactive toggling
  * Update class docstrings with new attributes

- src/pyoma2/algorithms/ssi.py:
  * Add interactive parameter to plot_stab()
  * Integrate SelFromPlot for interactive mode
  * Update docstrings with interactive controls

- src/pyoma2/algorithms/plscf.py:
  * Add spectrum, nSv, and interactive parameters
  * Add spectrum overlay support (new feature)
  * Integrate SelFromPlot for interactive mode
  * Update docstrings with full parameter list

- Examples/interactive_stability_chart_demo.py:
  * Comprehensive demo script showing new features
  * Examples for SSI and pLSCF algorithms
  * API comparison (old vs new)

- INTERACTIVE_STABILITY_CHART.md:
  * Complete Vietnamese documentation
  * Usage examples and API reference
  * Interactive controls guide
  * Troubleshooting section

API usage:
  # Old way (2 separate methods):
  ssicov.plot_stab(spectrum=True)  # View only
  ssicov.mpe_from_plot()            # Interactive, no spectrum

  # New way (unified):
  ssicov.plot_stab(spectrum=True, interactive=True)

Interactive controls:
- SHIFT + LEFT mouse: Select pole
- SHIFT + RIGHT mouse: Remove last pole
- SHIFT + MIDDLE mouse: Remove closest pole
- Menu > Spectrum Overlay: Toggle spectrum
- Menu > Show/Hide Unstable Poles: Toggle poles

Benefits:
- Unified workflow: single method instead of two
- Spectrum helps identify physical modes
- Real-time spectrum toggling during picking
- Backward compatible: default interactive=False
- Consistent interface across algorithms

Resolves: Interactive stability chart with spectrum overlay request
…-LD22E

Add interactive mode picking to stability chart
@dfm88
Copy link
Collaborator

dfm88 commented Jan 17, 2026

Hi @vudxlab thank you for yuor PR. Tests are failing, you can try to run them locally on your changes and update this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants