Skip to content

Stream 3d plot#11

Merged
t0mdavid-m merged 9 commits into
developfrom
stream_3d_plot
May 15, 2025
Merged

Stream 3d plot#11
t0mdavid-m merged 9 commits into
developfrom
stream_3d_plot

Conversation

@t0mdavid-m

@t0mdavid-m t0mdavid-m commented May 13, 2025

Copy link
Copy Markdown
Member

Significantly increases performance for 3d plot

Summary by CodeRabbit

  • New Features
    • Improved data loading and filtering for the "Precursor Signals" and "3D_SN_plot" components, enabling more efficient handling of large datasets.
  • Bug Fixes
    • Enhanced robustness when filtering data by handling missing or out-of-range values for specific indices.
  • Chores
    • Updated internal dependencies for improved compatibility.

@coderabbitai

coderabbitai Bot commented May 13, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes introduce a new optional parameter, use_pyarrow, to the FileManager.get_results method, enabling parquet file loading via pyarrow as an alternative to pandas. This is utilized in the retrieval of data for the '3D_SN_plot' component. Additionally, data filtering for the 'Precursor Signals' component is refactored to use pyarrow for more efficient filtering and column extraction.

Changes

File(s) Change Summary
openms-streamlit-vue-component (subproject reference) Updated subproject commit reference from 1c8c9837fbdb554992f135bb909f3ed8d127b58c to 9aabf9919e7a46837a29030ff16cac7f1aad8319.
src/render/initialize.py Modified the call to file_manager.get_results for '3D_SN_plot' to include use_pyarrow=True, changing the data loading backend for this component.
src/render/update.py Added import for pyarrow.dataset. Refactored 'Precursor Signals' filtering to use pyarrow for filtering by scanIndex and extracting elements from list columns by massIndex. Removed previous approach from general block.
src/workflow/FileManager.py Added use_pyarrow parameter to get_results. If True, loads parquet with pyarrow.dataset.dataset; otherwise, uses pandas.read_parquet.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant initialize.py
    participant FileManager
    participant pyarrow

    Client->>initialize.py: Request '3D_SN_plot' data
    initialize.py->>FileManager: get_results(..., use_pyarrow=True)
    FileManager->>pyarrow: Load parquet dataset via pyarrow
    pyarrow-->>FileManager: Return dataset
    FileManager-->>initialize.py: Return results
    initialize.py-->>Client: Return data
Loading
sequenceDiagram
    participant update.py
    participant pyarrow
    participant pandas

    update.py->>pyarrow: Filter per_scan_data by scanIndex
    alt massIndex is provided
        pyarrow->>pandas: Convert filtered table to DataFrame
        pandas->>update.py: Extract SignalPeaks and NoisyPeaks by massIndex
    else massIndex not provided
        pyarrow-->>update.py: Return filtered table
    end
    update.py-->>update.py: Update data['per_scan_data']
Loading

Poem

In the meadow of code, a new path we burrow,
With pyarrow in paw, we fetch data thorough.
Filtering signals with hops oh so fleet,
Parquet or pandas, both tasty to eat!
A leap for our plots, with precision anew—
The bunny approves these changes for you!
🐇✨

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 21df97d and 80b2a65.

📒 Files selected for processing (1)
  • src/render/initialize.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/render/initialize.py
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build-openms
  • GitHub Check: build-full-app
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/render/update.py (2)

80-92: Performance optimized filtering for 'Precursor Signals', consider adding error handling.

The implementation now uses PyArrow dataset filtering instead of pandas operations, which should significantly improve performance for the 3D plot as mentioned in the PR objectives. The approach effectively:

  1. Filters data using PyArrow's predicate pushdown capability
  2. Only converts to pandas when necessary for the specific massIndex operations
  3. Handles missing indices gracefully

However, there's no explicit error handling if PyArrow operations fail.

Consider adding error handling to gracefully manage potential PyArrow-related exceptions:

    elif component == 'Precursor Signals':
        scan_index = selection_store.get("scanIndex")
        mass_index = selection_store.get("massIndex")
        if scan_index is None:
-           data['per_scan_data'] = data['per_scan_data'].to_table(filter=(ds.field("index") == -1)).slice(0, 0)
+           try:
+               data['per_scan_data'] = data['per_scan_data'].to_table(filter=(ds.field("index") == -1)).slice(0, 0)
+           except Exception as e:
+               st.error(f"Error filtering data: {e}")
+               data['per_scan_data'] = pd.DataFrame()
        else:
-           filtered_table = data['per_scan_data'].to_table(filter=(ds.field("index") == scan_index))
-           if mass_index is not None:
-               df = filtered_table.to_pandas()
-               df['SignalPeaks'] = df['SignalPeaks'].apply(lambda peaks: peaks[mass_index] if len(peaks) > mass_index else None)
-               df['NoisyPeaks'] = df['NoisyPeaks'].apply(lambda peaks: peaks[mass_index] if len(peaks) > mass_index else None)
-               filtered_table = df
-           data['per_scan_data'] = filtered_table
+           try:
+               filtered_table = data['per_scan_data'].to_table(filter=(ds.field("index") == scan_index))
+               if mass_index is not None:
+                   df = filtered_table.to_pandas()
+                   df['SignalPeaks'] = df['SignalPeaks'].apply(lambda peaks: peaks[mass_index] if len(peaks) > mass_index else None)
+                   df['NoisyPeaks'] = df['NoisyPeaks'].apply(lambda peaks: peaks[mass_index] if len(peaks) > mass_index else None)
+                   filtered_table = df
+               data['per_scan_data'] = filtered_table
+           except Exception as e:
+               st.error(f"Error processing data: {e}")
+               data['per_scan_data'] = pd.DataFrame()

89-90: Consider using vectorized operations for better performance.

The current approach uses apply with lambda functions to transform the 'SignalPeaks' and 'NoisyPeaks' columns. For even better performance, consider using vectorized operations if possible, especially since this is part of a performance optimization PR.

-               df['SignalPeaks'] = df['SignalPeaks'].apply(lambda peaks: peaks[mass_index] if len(peaks) > mass_index else None)
-               df['NoisyPeaks'] = df['NoisyPeaks'].apply(lambda peaks: peaks[mass_index] if len(peaks) > mass_index else None)
+               # Vectorized approach if lists are of uniform length
+               # Check if any list is shorter than mass_index to avoid index errors
+               has_short_lists = any(len(peaks) <= mass_index for peaks in df['SignalPeaks'] if peaks is not None)
+               
+               if not has_short_lists:
+                   # Fast path: vectorized extraction
+                   df['SignalPeaks'] = df['SignalPeaks'].map(lambda peaks: None if peaks is None else peaks[mass_index])
+                   df['NoisyPeaks'] = df['NoisyPeaks'].map(lambda peaks: None if peaks is None else peaks[mass_index])
+               else:
+                   # Fallback: safe element-wise extraction
+                   df['SignalPeaks'] = df['SignalPeaks'].apply(lambda peaks: peaks[mass_index] if peaks is not None and len(peaks) > mass_index else None)
+                   df['NoisyPeaks'] = df['NoisyPeaks'].apply(lambda peaks: peaks[mass_index] if peaks is not None and len(peaks) > mass_index else None)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 62252e3 and b4431dd.

⛔ Files ignored due to path filters (2)
  • js-component/dist/assets/index-e2941e20.js is excluded by !**/dist/**
  • js-component/dist/index.html is excluded by !**/dist/**
📒 Files selected for processing (7)
  • environment.yml (1 hunks)
  • openms-streamlit-vue-component (1 hunks)
  • requirements.txt (1 hunks)
  • src/render/components.py (1 hunks)
  • src/render/initialize.py (1 hunks)
  • src/render/update.py (2 hunks)
  • src/workflow/FileManager.py (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/render/initialize.py (1)
src/workflow/FileManager.py (1)
  • get_results (404-449)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build-openms
  • GitHub Check: build-full-app
🔇 Additional comments (10)
openms-streamlit-vue-component (1)

1-1: Confirm correctness of the submodule commit update
The subproject pointer has been bumped to 9aabf9919e7a46837a29030ff16cac7f1aad8319. Please verify that this commit includes all required Vue component changes, that the submodule is properly initialized/updated, and that the component build and integration tests pass with this new reference.

src/render/initialize.py (1)

80-80: PyArrow optimization for 3D plot data loading

The addition of use_pyarrow=True to the get_results call for the 3D scatter and noise plot component enables more efficient loading of parquet data using PyArrow's dataset API instead of pandas.read_parquet. This change aligns with the PR objective of improving 3D plot performance.

requirements.txt (1)

12-12: Consistent PyArrow version constraint

Adding the minimum version pyarrow>=15 to complement the existing pyarrow<16 ensures compatibility with the new PyArrow dataset API features being used. This version range is appropriately specified across both dependency files.

environment.yml (1)

13-13: Consistent PyArrow version constraint

Adding the minimum version constraint pyarrow>=15 to match requirements.txt ensures consistent dependency management across both conda and pip installations. This is necessary for the PyArrow dataset features being used for the 3D plot performance enhancement.

src/workflow/FileManager.py (3)

9-9: PyArrow dataset module import

Added import for PyArrow's dataset module to enable more efficient loading and filtering of parquet files. This is appropriate for optimizing the 3D plot performance.


404-405: Optional PyArrow data loading parameter

The addition of use_pyarrow parameter with a default of False maintains backward compatibility while enabling improved performance for specific components that opt-in to the feature.


441-444: PyArrow dataset loading implementation

This implementation provides a performance optimization by allowing components to use PyArrow's dataset API for loading parquet files when use_pyarrow=True. This approach is more memory-efficient and faster for large datasets, especially when combined with filtering operations, making it well-suited for 3D visualization data.

src/render/update.py (3)

3-3: Appropriate import for PyArrow integration.

The addition of PyArrow enables more efficient data filtering operations, aligning with the PR's performance improvement objective.


73-73: LGTM: Component list extension.

Inclusion of 'Augmented Deconvolved Spectrum' in the list of components that share the same filtering logic is appropriate.


84-84:

Details

❓ Verification inconclusive

Verify that the field name is correct.

The code uses ds.field("index") to filter the dataset, but make sure that "index" is the correct field name in the PyArrow dataset. Sometimes dataset field names might differ from DataFrame column names.


🏁 Script executed:

#!/bin/bash
# Verify field names in PyArrow datasets
# Look for usages of PyArrow dataset creation to confirm field names

rg -A 3 "pyarrow\.dataset\.(dataset|parquet_dataset)"
rg -A 3 "ds\.dataset" 

Length of output: 368


To confirm whether the "index" field actually exists on per_scan_data, let’s inspect how per_scan_data is defined and where it comes from in src/render/update.py.


🏁 Script executed:

#!/bin/bash
# Show how per_scan_data is populated and used around line 84
rg -n "per_scan_data" -A5 -B5 src/render/update.py

# Dump the first 200 lines of update.py for broader context
sed -n '1,200p' src/render/update.py

Length of output: 6720


Confirm Parquet column name for filtering

At src/render/update.py:84, you’re using ds.field("index") to filter the dataset. Please verify that your Parquet source actually defines a column named "index". You can inspect the schema (for example, in a REPL or small script) with:

import pyarrow.dataset as ds
dataset = ds.dataset(<your_parquet_path>, format="parquet")
print(dataset.schema.names)

If the field is named differently (e.g. "scanIndex"), update the filter to use the correct column name.

Comment thread src/render/components.py Outdated
@t0mdavid-m t0mdavid-m merged commit 24c7fbe into develop May 15, 2025
5 checks passed
@t0mdavid-m t0mdavid-m deleted the stream_3d_plot branch May 15, 2025 11:25
t0mdavid-m added a commit that referenced this pull request Mar 6, 2026
Change the nginx listen directive from `listen 8501` to
`listen 0.0.0.0:8501` so the load balancer explicitly accepts
connections on all network interfaces, not just the default.

https://claude.ai/code/session_01721rHYJhSZfJnnUpWHXbVs

Co-authored-by: Claude <noreply@anthropic.com>
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.

1 participant