Skip to content

feat: add python accessors for drift time to os spec and msspectrum - #8423

Merged
timosachsenberg merged 29 commits into
developfrom
feature/drift_time_os_spec
Dec 6, 2025
Merged

timosachsenberg merged 29 commits into
developfrom
feature/drift_time_os_spec

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Dec 4, 2025 •

Copy link
Copy Markdown
Contributor

This pull request introduces several improvements and new features to the pyOpenMS interface for working with spectra and binary data arrays, focusing on safer and more efficient data access patterns, better documentation, and enhanced support for ion mobility data. It also updates the core C++ data structures to support setting binary data arrays directly. The most important changes are grouped below:

Data Access Improvements and Safety

  • Added get_data and get_data_mv methods to FloatDataArray and OSBinaryDataArray for safe (copy) and efficient (memory view) access to underlying data, along with clear documentation and usage warnings to prevent unsafe memory access patterns. [1] [2]
  • Updated MSSpectrum methods (get_mz_array, get_intensity_array, get_peaks) to use direct indexing for faster and safer NumPy array creation, and improved docstrings for clarity and usage examples. [1] [2]

Ion Mobility Data Support

  • Added new methods to MSSpectrum: get_drift_time_array, get_drift_time_array_mv, and get_drift_time_unit, providing convenient and safe access to ion mobility drift time data, both as copies and memory views, with comprehensive documentation and usage examples.

Core Data Structure Enhancements

  • Added setDataArrays method to both OSChromatogram and OSSpectrum C++ classes, allowing direct setting of binary data arrays for improved flexibility in data manipulation. [1] [2]

Test Suite Updates

  • Updated the test suite to replace test_MSSpectrumAndRichSpectrum.py with test_MSSpectrum.py, reflecting changes in the codebase and ensuring relevant tests are run.## Description

Checklist

  • Make sure that you are listed in the AUTHORS file
  • Add relevant changes and new features to the CHANGELOG file
  • I have commented my code, particularly in hard-to-understand areas
  • New and existing unit tests pass locally with my changes
  • Updated or added python bindings for changed or new classes (Tick if no updates were necessary.)

How can I get additional information on failed tests during CI

Click to expand If your PR is failing you can check out

Advanced commands (admins / reviewer only)

Click to expand
  • /reformat (experimental) applies the clang-format style changes as additional commit. Note: your branch must have a different name (e.g., yourrepo:feature/XYZ) than the receiving branch (e.g., OpenMS:develop). Otherwise, reformat fails to push.
  • setting the label "NoJenkins" will skip tests for this PR on jenkins (saves resources e.g., on edits that do not affect tests)
  • commenting with rebuild jenkins will retrigger Jenkins-based CI builds

⚠️ Note: Once you opened a PR try to minimize the number of pushes to it as every push will trigger CI (automated builds and test) and is rather heavy on our infrastructure (e.g., if several pushes per day are performed).

Summary by CodeRabbit

  • New Features

    • Added safe copy and zero-copy memory-view accessors for spectrum, chromatogram, and binary data arrays
    • Added direct drift‑time/ion‑mobility accessors and bulk get/set for data arrays
  • API Changes

    • Standardized public method names to snake_case and introduced paired copy vs. memory‑view APIs
  • Tests

    • Added extensive spectrum and OpenSwath data-structure tests; removed/updated a legacy test module
  • Documentation

    • Updated performance benchmarks to reflect new accessors and timings

✏️ Tip: You can customize this high-level summary in your review settings.

hroest and others added 24 commits September 27, 2022 00:56
- Remove unnecessary semicolons from test file (lines 50, 63, 134)
- Add documentation for setDataArrays() methods in DataStructures.h
- Add docstrings for getData() and getData_mv() in OSBinaryDataArray.pyx

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

Co-Authored-By: Claude <[email protected]>
Handle the case where arrays are empty when creating memory views.
When data.size() is 0, data.data() returns NULL, and trying to
create a Cython memory view from NULL causes ValueError.

This fix:
- Returns np.empty(0) for copy methods (getMZArray, getIntensityArray, etc.)
- Returns None for memory view methods (*_mv) when array is empty
- Adds size check before creating memory view

Fixes test failure in test_ChromatogramExtractorAlgorithm.py

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

Co-Authored-By: Claude <[email protected]>
- Add get_mz_array(), get_intensity_array(), get_drift_time_array() to MSSpectrum
- Add get_drift_time_array_mv() and get_drift_time_unit() for ion mobility data
- Optimize get_peaks() with direct indexing instead of iterator
- Standardize FloatDataArray: get_data() returns copy, get_data_mv() returns view
- Add docstrings to OSSpectrum, OSChromatogram, OSBinaryDataArray addon methods
- Use snake_case naming convention consistent with existing pyOpenMS style
- Fix empty array handling (copy methods return empty array, view methods return None)
- Update unit tests for new method signatures and semantics

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

Co-Authored-By: Claude <[email protected]>
RichSpectrum class no longer exists in OpenMS - update test file name
to reflect that it only tests MSSpectrum.

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

Co-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Dec 4, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Adds snake_case Python bindings, copy and zero-copy (memoryview) data accessors, drift-time (ion mobility) accessors, and bulk data-array getters/setters across OSSpectrum/OSChromatogram; updates C++ header, Cython .pxd/.pyx bindings, tests, and performance docs.

Changes

Cohort / File(s) Change Summary
C++ DataStructures
src/openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/DataStructures.h
Added public setDataArrays(std::vector<BinaryDataArrayPtr>&) to OSChromatogram and OSSpectrum.
Cython declarations (.pxd)
src/pyOpenMS/pxds/OpenSwathDataStructures.pxd
Added copy and memory-view accessors and getDataArrays/setDataArrays declarations for OSBinaryDataArray, OSSpectrum, and OSChromatogram; minor constructor signature formatting.
FloatDataArray addon
src/pyOpenMS/addons/FloatDataArray.pyx
Added get_data() (returns float32 copy) and get_data_mv() (returns float32 memoryview) with docstrings and empty-data handling.
OSBinaryDataArray addon
src/pyOpenMS/addons/OSBinaryDataArray.pyx
Added get_data() (float64 copy) and get_data_mv() (memoryview) with empty-data handling and lifetime warnings.
OSSpectrum addon
src/pyOpenMS/addons/OSSpectrum.pyx
Renamed camelCase→snake_case getters/setters; added memory-view variants; added drift-time accessors and get_data_arrays/set_data_arrays; replaced iterator-based loops with index-based access.
OSChromatogram addon
src/pyOpenMS/addons/OSChromatogram.pyx
Renamed camelCase→snake_case getters/setters; added memory-view variants; added get_data_arrays/set_data_arrays; updated setters to create _OSBinaryDataArray wrappers.
MSSpectrum addon
src/pyOpenMS/addons/MSSpectrum.pyx
Replaced iterator-based peak access with index-based loops; added IM/drift-time accessors (get_drift_time_array, get_drift_time_array_mv, get_drift_time_unit).
Python tests (added/removed/updated)
src/pyOpenMS/tests/unittests/test_MSSpectrum.py (new), src/pyOpenMS/tests/unittests/test_MSSpectrumAndRichSpectrum.py (removed), src/pyOpenMS/tests/unittests/test_OpenSwathDataStructures.py, src/pyOpenMS/tests/unittests/* (various updated)
Added comprehensive MSSpectrum tests (including FloatDataArray copy/view semantics and IM tests); removed older test; expanded OpenSwathDataStructures tests; updated many tests to use new snake_case APIs and to validate memory-view semantics.
Test registration
src/pyOpenMS/CMakeLists.txt
Replaced test_MSSpectrumAndRichSpectrum.py with test_MSSpectrum.py in unittest file list.
Documentation / Benchmarks
src/pyOpenMS/performance.rst
Updated benchmarks and timings for FloatDataArray and spectrum data-access scenarios to reflect new accessors and implementations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Areas to focus:
    • src/pyOpenMS/addons/FloatDataArray.pyx and src/pyOpenMS/addons/OSBinaryDataArray.pyx — memoryview creation, lifetime safety, dtype/shape correctness.
    • Consistency between .pxd and .pyx signatures and return types (empty-data handling, None vs empty array).
    • src/openswathalgo/.../DataStructures.h — ABI/semantics of new setters.
    • New/updated tests in src/pyOpenMS/tests/unittests/ for correct API expectations and dtypes.

Possibly related PRs

Suggested labels

codex

Suggested reviewers

  • poshul
  • jpfeuffer

Poem

🐰 I hopped through bindings, tidy and new,

snake_case paths and views both shallow and true.
Copies to guard, memoryviews to share,
drift-times that twinkle like dew in the air.
A little rabbit cheers — quick, safe, and fair.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.31% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'add python accessors for drift time to os spec and msspectrum' directly describes the main objective of the PR: introducing Python accessors for drift time data. While the PR includes broader changes (data access methods, optimizations, C++ updates), drift time accessors are the primary feature highlighted and match the changes across MSSpectrum, OSSpectrum, and related files.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/drift_time_os_spec

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@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: 2

🧹 Nitpick comments (9)
src/openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/DataStructures.h (2)

144-149: Consider using const reference for the parameter.

The current non-const lvalue reference prevents passing temporaries and could unintentionally suggest the input may be modified. Using const std::vector<BinaryDataArrayPtr>& would be more flexible and conventional for a setter.

-    void setDataArrays(std::vector<BinaryDataArrayPtr>& val)
+    void setDataArrays(const std::vector<BinaryDataArrayPtr>& val)

281-286: Same as above: prefer const reference.

For consistency with the suggestion for OSChromatogram::setDataArrays, consider using const std::vector<BinaryDataArrayPtr>& here as well.

-    void setDataArrays(std::vector<BinaryDataArrayPtr>& val)
+    void setDataArrays(const std::vector<BinaryDataArrayPtr>& val)
src/pyOpenMS/addons/OSBinaryDataArray.pyx (1)

28-61: Consider returning a NumPy array view for consistency.

FloatDataArray.get_data_mv() returns np.asarray(fda_view) (a NumPy array backed by the underlying data), while this method returns the raw memoryview. For API consistency, consider wrapping the memoryview:

         cdef double[::1] arr = <double [:n]>_r.get().data.data()
-        return arr
+        return np.asarray(arr)

This would also make the docstring's "Returns: memoryview" need updating to match FloatDataArray's documentation pattern.

src/pyOpenMS/tests/unittests/test_OpenSwathDataStructures.py (1)

9-9: Unused setUp method.

The setUp method only contains pass and doesn't initialize any fixtures. Consider removing it or adding shared test fixtures if needed.

-    def setUp(self):
-        pass
-
src/pyOpenMS/addons/OSSpectrum.pyx (2)

269-272: Unused variable _vec.

The variable _vec is declared but the list data is assigned directly to v0.get().data. This appears to be dead code.

         cdef shared_ptr[_OSBinaryDataArray] v0 = shared_ptr[_OSBinaryDataArray](new _OSBinaryDataArray() )
-        cdef libcpp_vector[double] _vec = data
         v0.get().data = data
         self.inst.get().setMZArray(v0)

296-299: Same unused variable _vec in set_intensity_array.

Consistent with set_mz_array, this unused variable can be removed.

         cdef shared_ptr[_OSBinaryDataArray] v0 = shared_ptr[_OSBinaryDataArray](new _OSBinaryDataArray() )
-        cdef libcpp_vector[double] _vec = data
         v0.get().data = data
         self.inst.get().setIntensityArray(v0)
src/pyOpenMS/tests/unittests/test_MSSpectrum.py (1)

9-11: Remove unused dirname variable.

The dirname variable is assigned but never used. Static analysis correctly flagged this.

     def setUp(self):
-        dirname = os.path.dirname(os.path.abspath(__file__))
-
+        pass

Or remove the setUp method entirely if no initialization is needed.

src/pyOpenMS/addons/OSChromatogram.pyx (2)

199-202: Unused variable _vec in set_time_array.

Same pattern as OSSpectrum - the _vec variable is declared but unused.

         cdef shared_ptr[_OSBinaryDataArray] v0 = shared_ptr[_OSBinaryDataArray](new _OSBinaryDataArray() )
-        cdef libcpp_vector[double] _vec = data
         v0.get().data = data
         self.inst.get().setTimeArray(v0)

225-228: Unused variable _vec in set_intensity_array.

Same unused variable pattern.

         cdef shared_ptr[_OSBinaryDataArray] v0 = shared_ptr[_OSBinaryDataArray](new _OSBinaryDataArray() )
-        cdef libcpp_vector[double] _vec = data
         v0.get().data = data
         self.inst.get().setIntensityArray(v0)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9e92c1b and eebeb6b.

📒 Files selected for processing (12)
  • src/openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/DataStructures.h (2 hunks)
  • src/pyOpenMS/CMakeLists.txt (1 hunks)
  • src/pyOpenMS/addons/FloatDataArray.pyx (1 hunks)
  • src/pyOpenMS/addons/MSSpectrum.pyx (2 hunks)
  • src/pyOpenMS/addons/OSBinaryDataArray.pyx (1 hunks)
  • src/pyOpenMS/addons/OSChromatogram.pyx (1 hunks)
  • src/pyOpenMS/addons/OSSpectrum.pyx (1 hunks)
  • src/pyOpenMS/performance.rst (4 hunks)
  • src/pyOpenMS/pxds/OpenSwathDataStructures.pxd (2 hunks)
  • src/pyOpenMS/tests/unittests/test_MSSpectrum.py (1 hunks)
  • src/pyOpenMS/tests/unittests/test_MSSpectrumAndRichSpectrum.py (0 hunks)
  • src/pyOpenMS/tests/unittests/test_OpenSwathDataStructures.py (2 hunks)
💤 Files with no reviewable changes (1)
  • src/pyOpenMS/tests/unittests/test_MSSpectrumAndRichSpectrum.py
🧰 Additional context used
📓 Path-based instructions (1)
src/pyOpenMS/tests/**/*.py

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Write pyOpenMS tests for new Python bindings

Files:

  • src/pyOpenMS/tests/unittests/test_MSSpectrum.py
  • src/pyOpenMS/tests/unittests/test_OpenSwathDataStructures.py
🧠 Learnings (13)
📓 Common learnings
Learnt from: jpfeuffer
Repo: OpenMS/OpenMS PR: 7970
File: src/pyOpenMS/addons/MSSpectrum.pyx:24-28
Timestamp: 2025-04-07T21:16:06.557Z
Learning: In OpenMS, the proper way to access ion mobility data in MSSpectrum is to use the `getIMData()` method, which returns a tuple with (position, unit). The position corresponds to the index in the FloatDataArrays where the ion mobility data is stored. Always use this method rather than assuming the first FloatDataArray contains ion mobility data.
Learnt from: jpfeuffer
Repo: OpenMS/OpenMS PR: 7970
File: src/pyOpenMS/addons/MSSpectrum.pyx:24-28
Timestamp: 2025-04-07T21:16:06.557Z
Learning: In OpenMS, the proper way to access ion mobility data in MSSpectrum is to use the `getIMData()` method, which returns a tuple with (position, unit). The position corresponds to the index in the FloatDataArrays where the ion mobility data is stored. Always use this method rather than assuming the first FloatDataArray contains ion mobility data.
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/pyOpenMS/tests/**/*.py : Write pyOpenMS tests for new Python bindings
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/pyOpenMS/**/*.h : Add Doxygen comments for new public methods and classes in pyOpenMS bindings
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/openms/**/*.{cpp,h,hpp,cc,cxx} : Use OpenMS data structures (e.g., MSExperiment, FeatureMap, PeptideIdentification)

Applied to files:

  • src/openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/DataStructures.h
  • src/pyOpenMS/pxds/OpenSwathDataStructures.pxd
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/openms/**/*.{cpp,h,hpp,cc,cxx} : Use appropriate OpenMS containers and algorithms

Applied to files:

  • src/openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/DataStructures.h
  • src/pyOpenMS/pxds/OpenSwathDataStructures.pxd
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/openms/**/*.{cpp,h,hpp,cc,cxx} : Be mindful of memory usage when processing large datasets

Applied to files:

  • src/openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/DataStructures.h
  • src/pyOpenMS/pxds/OpenSwathDataStructures.pxd
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/pyOpenMS/**/*.h : Add Doxygen comments for new public methods and classes in pyOpenMS bindings

Applied to files:

  • src/pyOpenMS/performance.rst
  • src/pyOpenMS/pxds/OpenSwathDataStructures.pxd
  • src/pyOpenMS/addons/OSSpectrum.pyx
  • src/pyOpenMS/CMakeLists.txt
  • src/pyOpenMS/addons/MSSpectrum.pyx
  • src/pyOpenMS/addons/OSChromatogram.pyx
  • src/pyOpenMS/tests/unittests/test_MSSpectrum.py
📚 Learning: 2025-04-07T21:16:06.557Z
Learnt from: jpfeuffer
Repo: OpenMS/OpenMS PR: 7970
File: src/pyOpenMS/addons/MSSpectrum.pyx:24-28
Timestamp: 2025-04-07T21:16:06.557Z
Learning: In OpenMS, the proper way to access ion mobility data in MSSpectrum is to use the `getIMData()` method, which returns a tuple with (position, unit). The position corresponds to the index in the FloatDataArrays where the ion mobility data is stored. Always use this method rather than assuming the first FloatDataArray contains ion mobility data.

Applied to files:

  • src/pyOpenMS/performance.rst
  • src/pyOpenMS/addons/OSSpectrum.pyx
  • src/pyOpenMS/addons/MSSpectrum.pyx
  • src/pyOpenMS/tests/unittests/test_MSSpectrum.py
📚 Learning: 2025-11-18T20:08:08.900Z
Learnt from: timosachsenberg
Repo: OpenMS/OpenMS PR: 8374
File: src/pyOpenMS/pxds/SimpleSVM.pxd:0-0
Timestamp: 2025-11-18T20:08:08.900Z
Learning: In pyOpenMS .pxd files, copy constructors should be declared for wrapped C++ classes (e.g., `ClassName(ClassName&) except + nogil`) even when the C++ class has a deleted copy constructor. This is a standard pyOpenMS/Cython convention required for proper wrapper generation and Python object semantics.

Applied to files:

  • src/pyOpenMS/pxds/OpenSwathDataStructures.pxd
📚 Learning: 2025-06-16T15:49:26.504Z
Learnt from: FreezB11
Repo: OpenMS/OpenMS PR: 7969
File: src/pyOpenMS/pxds/TMTThirtyTwoPlexQuantitationMethod.pxd:1-3
Timestamp: 2025-06-16T15:49:26.504Z
Learning: In OpenMS Python bindings (.pxd files), derived quantitation method classes like TMTThirtyTwoPlexQuantitationMethod only need to declare their constructors. All other public methods (getName, getChannelInformation, getNumberOfChannels, getIsotopeCorrectionMatrix, getReferenceChannel) are inherited from the base IsobaricQuantitationMethod class and don't need to be redeclared explicitly.

Applied to files:

  • src/pyOpenMS/pxds/OpenSwathDataStructures.pxd
  • src/pyOpenMS/addons/OSChromatogram.pyx
📚 Learning: 2025-06-16T15:48:09.667Z
Learnt from: FreezB11
Repo: OpenMS/OpenMS PR: 7969
File: src/pyOpenMS/pxds/TMTThirtyTwoPlexQuantitationMethod.pxd:4-4
Timestamp: 2025-06-16T15:48:09.667Z
Learning: In OpenMS .pxd files, the established pattern for extern from statements is to include angle brackets inside the string literal, like `cdef extern from "<OpenMS/PATH/TO/FILE.h>" namespace "OpenMS":`. This is consistent across all existing quantitation method .pxd files and other .pxd files in the OpenMS codebase.

Applied to files:

  • src/pyOpenMS/pxds/OpenSwathDataStructures.pxd
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/pyOpenMS/tests/**/*.py : Write pyOpenMS tests for new Python bindings

Applied to files:

  • src/pyOpenMS/CMakeLists.txt
  • src/pyOpenMS/tests/unittests/test_MSSpectrum.py
  • src/pyOpenMS/tests/unittests/test_OpenSwathDataStructures.py
📚 Learning: 2025-09-03T12:58:20.032Z
Learnt from: timosachsenberg
Repo: OpenMS/OpenMS PR: 8177
File: src/tests/topp/CMakeLists.txt:1857-1865
Timestamp: 2025-09-03T12:58:20.032Z
Learning: OpenMS tests: When adding new TOPP tests in src/tests/topp/CMakeLists.txt that compare outputs via FuzzyDiff, always add set_tests_properties("<tool>_<n>_out<m>" PROPERTIES DEPENDS "<tool>_<n>") to avoid flakiness under parallel CTest runs.

Applied to files:

  • src/pyOpenMS/CMakeLists.txt
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/tests/class_tests/openms/*Test.cpp : Follow naming convention: `ClassNameTest.cpp` for `ClassName`

Applied to files:

  • src/pyOpenMS/CMakeLists.txt
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/tests/class_tests/openms/**/*.cpp : Write unit tests for new functionality

Applied to files:

  • src/pyOpenMS/CMakeLists.txt
  • src/pyOpenMS/tests/unittests/test_MSSpectrum.py
  • src/pyOpenMS/tests/unittests/test_OpenSwathDataStructures.py
🧬 Code graph analysis (2)
src/pyOpenMS/tests/unittests/test_MSSpectrum.py (1)
src/openms/include/OpenMS/KERNEL/Peak1D.h (1)
  • Peak1D (46-52)
src/pyOpenMS/tests/unittests/test_OpenSwathDataStructures.py (1)
src/openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/DataStructures.h (2)
  • OSBinaryDataArray (41-51)
  • OSChromatogram (72-151)
🪛 Ruff (0.14.7)
src/pyOpenMS/tests/unittests/test_MSSpectrum.py

10-10: Local variable dirname is assigned to but never used

Remove assignment to unused variable dirname

(F841)


48-48: zip() without an explicit strict= parameter

Add explicit value for parameter strict=

(B905)


50-50: zip() without an explicit strict= parameter

Add explicit value for parameter strict=

(B905)


73-73: zip() without an explicit strict= parameter

Add explicit value for parameter strict=

(B905)


86-86: zip() without an explicit strict= parameter

Add explicit value for parameter strict=

(B905)

src/pyOpenMS/tests/unittests/test_OpenSwathDataStructures.py

38-38: zip() without an explicit strict= parameter

Add explicit value for parameter strict=

(B905)


41-41: zip() without an explicit strict= parameter

Add explicit value for parameter strict=

(B905)


59-59: zip() without an explicit strict= parameter

Add explicit value for parameter strict=

(B905)


124-124: zip() without an explicit strict= parameter

Add explicit value for parameter strict=

(B905)


127-127: zip() without an explicit strict= parameter

Add explicit value for parameter strict=

(B905)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: build-and-test (ubuntu-22.04, clang++, 15)
  • GitHub Check: build-and-test (ubuntu-22.04, g++, 11)
  • GitHub Check: build-lnx-arm
  • GitHub Check: build-and-test (ubuntu-22.04-arm, g++, 11)
  • GitHub Check: build-and-test (ubuntu-22.04, g++, 11)
  • GitHub Check: build-lnx
  • GitHub Check: build-and-test (ubuntu-22.04, clang++, 15)
  • GitHub Check: build-and-test (windows-2022, cl.exe, 14.36)
🔇 Additional comments (25)
src/pyOpenMS/CMakeLists.txt (1)

594-594: LGTM!

The test file rename aligns with the PR's consolidation of MSSpectrum tests.

src/pyOpenMS/addons/OSBinaryDataArray.pyx (1)

5-26: LGTM!

The get_data method correctly returns a safe copy of the underlying data. The docstring clearly documents the behavior with a useful example.

src/pyOpenMS/performance.rst (1)

84-88: LGTM!

Updated benchmark timings accurately reflect the performance improvements from the indexing-based data access changes.

src/pyOpenMS/addons/FloatDataArray.pyx (2)

29-61: LGTM!

The updated get_data method with improved docstring clearly communicates the safe copy semantics. The index-based implementation is straightforward and correct.


63-108: Well-documented memory view method with appropriate safety warnings.

The implementation correctly provides zero-copy access, and the docstring's explicit warning about temporary object lifetime (especially the getFloatDataArrays()[0].get_data_mv() anti-pattern) is excellent for preventing common user errors.

src/pyOpenMS/tests/unittests/test_OpenSwathDataStructures.py (3)

28-75: Good test coverage for OSSpectrum snake_case API and drift time arrays.

The test comprehensively validates:

  • Basic m/z and intensity array operations
  • Drift time array handling (including None when no IM data)
  • Data array management (get/set/append)
  • OSBinaryDataArray get_data() accessor

The use of b"Ion Mobility" for the description correctly matches the expected C++ string type.


76-113: Excellent memory view semantics validation.

This test correctly demonstrates the critical difference between copy and memory view behavior:

  • Modifying a copy does not affect underlying data
  • Modifying a memory view changes the underlying data

This is important documentation-by-test for users working with the new API.


114-145: Good test coverage for OSChromatogram API.

The test validates the chromatogram-specific accessors and data array management, mirroring the OSSpectrum tests appropriately.

src/pyOpenMS/addons/OSSpectrum.pyx (3)

3-23: Well-documented API with proper copy semantics.

The docstring clearly explains that this returns a copy, making it safe to modify. The implementation correctly handles the empty case by returning an empty array rather than None, which provides consistent return types.


25-57: Critical memory view warning is well documented.

The warning about not storing memory views after the spectrum goes out of scope is essential. The implementation correctly returns None for empty arrays, distinguishing from the copy variant's empty array return.


135-142: Drift time NULL check is correct.

Checking _r.get() == NULL before accessing data is the right approach since drift time arrays may not exist. This aligns with the PR's intent to safely expose ion mobility data.

src/pyOpenMS/tests/unittests/test_MSSpectrum.py (2)

100-128: Good test for ion mobility data access.

This test correctly validates drift time array retrieval when IM data is present. The use of setName("Ion Mobility") on the FloatDataArray is the standard OpenMS pattern for identifying ion mobility data, which is then detected by containsIMData().

Based on learnings, the proper way to access IM data uses getIMData() internally. The test correctly validates the public API (get_drift_time_array) without assuming which FloatDataArray index contains the IM data.


129-165: Comprehensive FloatDataArray copy vs view semantics tests.

These tests clearly validate the critical behavioral difference:

  • get_data() returns a copy (modifications don't affect original)
  • get_data_mv() returns a view (modifications affect original)
  • Empty arrays handled correctly (empty array vs None)

This is essential coverage for the new data access patterns.

src/pyOpenMS/pxds/OpenSwathDataStructures.pxd (3)

19-37: OSSpectrum declarations are well-organized.

The separation of copy-returning methods and memory-view methods with comments is clear. The #wrap-ignore annotations correctly indicate these are implemented in the addon file.


43-59: OSChromatogram declarations mirror OSSpectrum pattern.

Consistent API design between OSSpectrum and OSChromatogram with matching accessor patterns.


13-14: The addon implementations for get_data() and get_data_mv() already exist in OSBinaryDataArray.pyx and are properly implemented with comprehensive docstrings, NumPy array handling for copies, and memory view access with appropriate safety warnings. No action needed.

src/pyOpenMS/addons/OSChromatogram.pyx (3)

3-23: Well-implemented chromatogram time array accessor.

The implementation mirrors OSSpectrum's m/z array accessor with appropriate chromatogram-specific documentation. Return type consistency (empty array vs None for memory views) is maintained.


115-144: Consistent get_data_arrays implementation.

The implementation correctly wraps C++ shared_ptr objects into Python OSBinaryDataArray wrappers, matching the OSSpectrum pattern.


146-178: set_data_arrays implementation is correct.

The method properly validates input types and correctly updates the underlying C++ data structure. The pattern of clearing the vector and repopulating it ensures clean state management.

src/pyOpenMS/addons/MSSpectrum.pyx (6)

3-27: LGTM! Index-based access implementation is clean and safe.

The refactor from iterator-based to index-based access is well-implemented with proper bounds checking and empty spectrum handling. The enhanced docstring with examples improves usability.


29-53: LGTM! Consistent implementation with appropriate data types.

The refactor matches the pattern used in get_mz_array. Using float32 for intensities is appropriate and saves memory compared to float64.


55-87: LGTM! Efficient single-pass implementation.

The refactor correctly handles empty spectra and efficiently fills both arrays in a single loop. The docstring example demonstrating base peak identification is a nice touch.


204-225: LGTM! Docstring improvements clarify proper usage.

The enhanced documentation correctly demonstrates the pattern of checking containsIMData() before calling getIMData(), which aligns with best practices for accessing ion mobility data in OpenMS.

Based on learnings, this is the proper way to access ion mobility data rather than assuming the first FloatDataArray contains it.


227-262: LGTM! Correctly implements drift time access using getIMData().

The implementation properly uses containsIMData() and getIMData() to locate the drift time array, which aligns with OpenMS best practices. The handling of edge cases (no IM data, empty array) is correct.

Based on learnings, this correctly uses the getIMData() method rather than assuming the position of ion mobility data.


303-320: LGTM! Clear and consistent API for accessing drift time units.

The implementation correctly uses containsIMData() and getIMData() to retrieve the unit. The docstring helpfully documents the enum values, making the API more accessible.

Comment thread src/pyOpenMS/addons/MSSpectrum.pyx Resolved
Comment thread src/pyOpenMS/performance.rst Resolved

Copilot AI commented Dec 4, 2025

Copy link
Copy Markdown
Contributor

@timosachsenberg I've opened a new pull request, #8424, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI commented Dec 4, 2025

Copy link
Copy Markdown
Contributor

@timosachsenberg I've opened a new pull request, #8425, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI commented Dec 4, 2025

Copy link
Copy Markdown
Contributor

@timosachsenberg I've opened a new pull request, #8426, to work on those changes. Once the pull request is ready, I'll request review from you.

…#8424)

* Initial plan

* Update benchmark snippets to use snake_case Python method names

Co-authored-by: timosachsenberg <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: timosachsenberg <[email protected]>

@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: 0

🧹 Nitpick comments (1)
src/pyOpenMS/performance.rst (1)

11-21: Clarify the benchmark intent for FloatDataArray copy operations.

Lines 11-12 benchmark f.get_data() (copy), while lines 14-15 benchmark raw NumPy operations on the original array, and lines 20-21 benchmark NumPy's own .copy(). The relationship between these benchmarks could be clearer: lines 11-12 should explicitly note that this measures the cost of copying FloatDataArray data to NumPy, while lines 14-15 show the cost of summing pre-existing NumPy data.

Consider adding inline comments to clarify which operation is being benchmarked and why:

+ python -m timeit -s '...' 'np.sum(f.get_data())'  # Copy from FloatDataArray to NumPy + sum
  10000 loops, best of 5: 27.9 usec per loop
  
+ python -m timeit -s '...' 'np.sum(d)'  # Direct sum on existing NumPy array (baseline)
  10000 loops, best of 5: 26.4 usec per loop
  
+ python -m timeit -s '...' 'q = d.copy()'  # Pure NumPy copy overhead
  20000 loops, best of 5: 14.5 usec per loop
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eebeb6b and 543dd37.

📒 Files selected for processing (1)
  • src/pyOpenMS/performance.rst (4 hunks)
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: jpfeuffer
Repo: OpenMS/OpenMS PR: 7970
File: src/pyOpenMS/addons/MSSpectrum.pyx:24-28
Timestamp: 2025-04-07T21:16:06.557Z
Learning: In OpenMS, the proper way to access ion mobility data in MSSpectrum is to use the `getIMData()` method, which returns a tuple with (position, unit). The position corresponds to the index in the FloatDataArrays where the ion mobility data is stored. Always use this method rather than assuming the first FloatDataArray contains ion mobility data.
Learnt from: jpfeuffer
Repo: OpenMS/OpenMS PR: 7970
File: src/pyOpenMS/addons/MSSpectrum.pyx:24-28
Timestamp: 2025-04-07T21:16:06.557Z
Learning: In OpenMS, the proper way to access ion mobility data in MSSpectrum is to use the `getIMData()` method, which returns a tuple with (position, unit). The position corresponds to the index in the FloatDataArrays where the ion mobility data is stored. Always use this method rather than assuming the first FloatDataArray contains ion mobility data.
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/pyOpenMS/tests/**/*.py : Write pyOpenMS tests for new Python bindings
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/pyOpenMS/**/*.h : Add Doxygen comments for new public methods and classes in pyOpenMS bindings
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/pyOpenMS/tests/**/*.py : Write pyOpenMS tests for new Python bindings

Applied to files:

  • src/pyOpenMS/performance.rst
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/openms/**/*.{cpp,h,hpp,cc,cxx} : Consider algorithmic complexity for data processing operations

Applied to files:

  • src/pyOpenMS/performance.rst
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/pyOpenMS/**/*.h : Add Doxygen comments for new public methods and classes in pyOpenMS bindings

Applied to files:

  • src/pyOpenMS/performance.rst
📚 Learning: 2025-04-07T21:16:06.557Z
Learnt from: jpfeuffer
Repo: OpenMS/OpenMS PR: 7970
File: src/pyOpenMS/addons/MSSpectrum.pyx:24-28
Timestamp: 2025-04-07T21:16:06.557Z
Learning: In OpenMS, the proper way to access ion mobility data in MSSpectrum is to use the `getIMData()` method, which returns a tuple with (position, unit). The position corresponds to the index in the FloatDataArrays where the ion mobility data is stored. Always use this method rather than assuming the first FloatDataArray contains ion mobility data.

Applied to files:

  • src/pyOpenMS/performance.rst
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build-and-test (ubuntu-22.04, g++, 11)
  • GitHub Check: build-and-test (ubuntu-22.04-arm, g++, 11)
🔇 Additional comments (2)
src/pyOpenMS/performance.rst (2)

47-67: Verified: Benchmark examples use correct snake_case method names.

The extracted data benchmarks correctly use get_mz_array(), get_mz_array_mv(), get_data_arrays(), and get_data_mv() instead of camelCase variants. The performance improvements shown (from 6.19 msec to 111 usec for copying, 32.6 usec for memory views) reflect the optimizations from direct indexing and zero-copy access patterns.


1-112: Verify drift time (ion mobility) benchmarks are present in the complete file.

The AI-generated summary indicates that new benchmark sections for ion mobility data access should be included (drift time array copying and memory-view variants). However, the provided code snippet ends at line 112 and does not show these benchmarks. Per the PR objectives, get_drift_time_array(), get_drift_time_array_mv(), and get_drift_time_unit() methods are being added.

Please verify that:

  1. Ion mobility / drift time benchmark sections exist elsewhere in the file after line 112
  2. If they should be in this document, provide those sections for review to ensure they follow the same performance documentation patterns as the spectrum data access benchmarks (lines 47-67)

This will confirm the PR's documentation is complete as described in the PR objectives.

Copilot AI and others added 2 commits December 4, 2025 14:15
…#8425)

* Initial plan

* Update docstring example to use get_drift_time_array_mv() method

Co-authored-by: timosachsenberg <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: timosachsenberg <[email protected]>
* Initial plan

* Remove unused setUp method and os import from test_MSSpectrum.py

Co-authored-by: timosachsenberg <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: timosachsenberg <[email protected]>

@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: 0

🧹 Nitpick comments (3)
src/pyOpenMS/tests/unittests/test_MSSpectrum.py (3)

15-27: Consider using self.assertEqual for consistency.

Lines 16-27 use bare assert statements while other test methods use self.assertEqual. This is a minor inconsistency but self.assertEqual provides better error messages on failure.


43-46: Consider adding strict=True to zip() calls.

Per Ruff B905, using zip() without strict= can silently truncate if iterables have different lengths. In tests where lengths are expected to match, strict=True would catch unexpected mismatches.

-        for m, e in zip(mz, mz_exp):
+        for m, e in zip(mz, mz_exp, strict=True):
             self.assertAlmostEqual(m, e)
-        for i, e in zip(intensities, int_exp):
+        for i, e in zip(intensities, int_exp, strict=True):
             self.assertAlmostEqual(i, e, places=1)

This applies similarly to lines 68 and 81.


95-122: Consider adding a test for get_drift_time_array_mv with IM data.

The test verifies get_drift_time_array (copy) returns correct values, but doesn't verify that get_drift_time_array_mv returns valid data when IM data is present. Adding this would complete the coverage for the memory view variant.

         # Test get_drift_time_unit
         unit = spectrum.get_drift_time_unit()
         self.assertIsNotNone(unit)
+
+        # Test get_drift_time_array_mv (memory view)
+        drift_mv = spec.get_drift_time_array_mv()
+        self.assertIsNotNone(drift_mv)
+        self.assertEqual(len(drift_mv), 3)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 543dd37 and cc5c90c.

📒 Files selected for processing (2)
  • src/pyOpenMS/addons/MSSpectrum.pyx (2 hunks)
  • src/pyOpenMS/tests/unittests/test_MSSpectrum.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/pyOpenMS/tests/**/*.py

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Write pyOpenMS tests for new Python bindings

Files:

  • src/pyOpenMS/tests/unittests/test_MSSpectrum.py
🧠 Learnings (5)
📓 Common learnings
Learnt from: jpfeuffer
Repo: OpenMS/OpenMS PR: 7970
File: src/pyOpenMS/addons/MSSpectrum.pyx:24-28
Timestamp: 2025-04-07T21:16:06.557Z
Learning: In OpenMS, the proper way to access ion mobility data in MSSpectrum is to use the `getIMData()` method, which returns a tuple with (position, unit). The position corresponds to the index in the FloatDataArrays where the ion mobility data is stored. Always use this method rather than assuming the first FloatDataArray contains ion mobility data.
Learnt from: jpfeuffer
Repo: OpenMS/OpenMS PR: 7970
File: src/pyOpenMS/addons/MSSpectrum.pyx:24-28
Timestamp: 2025-04-07T21:16:06.557Z
Learning: In OpenMS, the proper way to access ion mobility data in MSSpectrum is to use the `getIMData()` method, which returns a tuple with (position, unit). The position corresponds to the index in the FloatDataArrays where the ion mobility data is stored. Always use this method rather than assuming the first FloatDataArray contains ion mobility data.
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/pyOpenMS/tests/**/*.py : Write pyOpenMS tests for new Python bindings
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/pyOpenMS/**/*.h : Add Doxygen comments for new public methods and classes in pyOpenMS bindings
📚 Learning: 2025-04-07T21:16:06.557Z
Learnt from: jpfeuffer
Repo: OpenMS/OpenMS PR: 7970
File: src/pyOpenMS/addons/MSSpectrum.pyx:24-28
Timestamp: 2025-04-07T21:16:06.557Z
Learning: In OpenMS, the proper way to access ion mobility data in MSSpectrum is to use the `getIMData()` method, which returns a tuple with (position, unit). The position corresponds to the index in the FloatDataArrays where the ion mobility data is stored. Always use this method rather than assuming the first FloatDataArray contains ion mobility data.

Applied to files:

  • src/pyOpenMS/addons/MSSpectrum.pyx
  • src/pyOpenMS/tests/unittests/test_MSSpectrum.py
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/pyOpenMS/**/*.h : Add Doxygen comments for new public methods and classes in pyOpenMS bindings

Applied to files:

  • src/pyOpenMS/addons/MSSpectrum.pyx
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/pyOpenMS/tests/**/*.py : Write pyOpenMS tests for new Python bindings

Applied to files:

  • src/pyOpenMS/tests/unittests/test_MSSpectrum.py
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/tests/class_tests/openms/**/*.cpp : Write unit tests for new functionality

Applied to files:

  • src/pyOpenMS/tests/unittests/test_MSSpectrum.py
🧬 Code graph analysis (1)
src/pyOpenMS/tests/unittests/test_MSSpectrum.py (1)
src/openms/include/OpenMS/KERNEL/Peak1D.h (1)
  • Peak1D (46-52)
🪛 Ruff (0.14.7)
src/pyOpenMS/tests/unittests/test_MSSpectrum.py

43-43: zip() without an explicit strict= parameter

Add explicit value for parameter strict=

(B905)


45-45: zip() without an explicit strict= parameter

Add explicit value for parameter strict=

(B905)


68-68: zip() without an explicit strict= parameter

Add explicit value for parameter strict=

(B905)


81-81: zip() without an explicit strict= parameter

Add explicit value for parameter strict=

(B905)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: cppcheck-test
🔇 Additional comments (9)
src/pyOpenMS/tests/unittests/test_MSSpectrum.py (2)

1-6: Good test coverage for new Python bindings.

The test file comprehensively covers the new MSSpectrum and FloatDataArray APIs including basic operations, peak access, drift time handling, and memory view vs copy semantics. This aligns well with the coding guidelines for pyOpenMS tests.


143-159: Excellent test for memory view mutation semantics.

This test properly validates that get_data_mv returns a view that mutates the original data, which is critical for documenting the "unsafe" nature of this API. The test correctly demonstrates that modifying the view affects the underlying FloatDataArray.

src/pyOpenMS/addons/MSSpectrum.pyx (7)

3-27: Clean implementation with proper empty spectrum handling.

The refactored index-based access is cleaner and the empty spectrum case is handled correctly by returning an empty array with the proper dtype.


29-53: LGTM!

Consistent implementation with get_mz_array, correctly using float32 for intensities which matches the underlying Peak1D type.


55-87: Good optimization combining both extractions in a single loop.

The refactored implementation efficiently extracts both m/z and intensity values in a single pass through the spectrum, which is better than making two separate iterations.


227-262: Correctly uses getIMData() to locate ion mobility data.

This implementation properly follows the OpenMS pattern of using getIMData() to get the position of IM data in FloatDataArrays, rather than assuming it's at a fixed index. The copy semantics ensure safe access. Based on learnings, this is the correct approach.


264-301: Memory view method with appropriate safety warnings.

The implementation correctly includes bounds checking and clear documentation about the need to keep references to prevent garbage collection. The docstring example has been updated to demonstrate the method properly.

One subtle issue: the example shows getting fdas and drift_mv separately, but drift_mv internally calls getFloatDataArrays() again. The user should understand that keeping fdas referenced is what matters for the underlying data validity.


303-320: Good documentation of enum values.

The docstring helpfully documents the DriftTimeUnit enum values (0=NONE, 1=MILLISECOND, etc.) which aids users who may not have easy access to the enum definition.


204-225: Well-documented with proper usage example.

The docstring clearly explains that containsIMData() should be checked first and shows the pattern for accessing the FloatDataArray at the returned index. This aligns with the learnings about proper ion mobility data access in OpenMS.

@timosachsenberg timosachsenberg changed the title add python accessors for drift time to os spec and msspectrum feat: add python accessors for drift time to os spec and msspectrum Dec 4, 2025
@poshul poshul added this to the 3.5 milestone Dec 5, 2025
- Fix Cython `nogil` position in OpenSwathDataStructures.pxd (use `except + nogil` not `nogil except +`)
- Update pyOpenMS tests to use new snake_case method names:
  - getMZArray() → get_mz_array()
  - getIntensityArray() → get_intensity_array()
  - setMZArray() → set_mz_array()
  - setIntensityArray() → set_intensity_array()
  - getTimeArray() → get_time_array()

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

Co-Authored-By: Claude <[email protected]>

@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: 0

🧹 Nitpick comments (1)
src/pyOpenMS/tests/unittests/test_ChromatogramExtractorAlgorithm.py (1)

48-48: API rename is correct; consider reusing local variables for arrays

The switch to get_intensity_array() / get_time_array() matches the updated OSChromatogram API and keeps the test logic intact. For slightly clearer test code, you could store these arrays in locals before asserting on length and first element to avoid repeated calls, but this is purely optional.

Also applies to: 61-66

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cc5c90c and 5c117a3.

📒 Files selected for processing (6)
  • src/pyOpenMS/pxds/OpenSwathDataStructures.pxd (2 hunks)
  • src/pyOpenMS/tests/unittests/test_ChromatogramExtractor.py (1 hunks)
  • src/pyOpenMS/tests/unittests/test_ChromatogramExtractorAlgorithm.py (2 hunks)
  • src/pyOpenMS/tests/unittests/test_DIAScoring.py (1 hunks)
  • src/pyOpenMS/tests/unittests/test_ISpectrumAccess.py (4 hunks)
  • src/pyOpenMS/tests/unittests/test_SpectrumAccessOpenMS.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/pyOpenMS/pxds/OpenSwathDataStructures.pxd
🧰 Additional context used
📓 Path-based instructions (1)
src/pyOpenMS/tests/**/*.py

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Write pyOpenMS tests for new Python bindings

Files:

  • src/pyOpenMS/tests/unittests/test_DIAScoring.py
  • src/pyOpenMS/tests/unittests/test_ChromatogramExtractor.py
  • src/pyOpenMS/tests/unittests/test_SpectrumAccessOpenMS.py
  • src/pyOpenMS/tests/unittests/test_ChromatogramExtractorAlgorithm.py
  • src/pyOpenMS/tests/unittests/test_ISpectrumAccess.py
🧠 Learnings (2)
📓 Common learnings
Learnt from: jpfeuffer
Repo: OpenMS/OpenMS PR: 7970
File: src/pyOpenMS/addons/MSSpectrum.pyx:24-28
Timestamp: 2025-04-07T21:16:06.557Z
Learning: In OpenMS, the proper way to access ion mobility data in MSSpectrum is to use the `getIMData()` method, which returns a tuple with (position, unit). The position corresponds to the index in the FloatDataArrays where the ion mobility data is stored. Always use this method rather than assuming the first FloatDataArray contains ion mobility data.
Learnt from: jpfeuffer
Repo: OpenMS/OpenMS PR: 7970
File: src/pyOpenMS/addons/MSSpectrum.pyx:24-28
Timestamp: 2025-04-07T21:16:06.557Z
Learning: In OpenMS, the proper way to access ion mobility data in MSSpectrum is to use the `getIMData()` method, which returns a tuple with (position, unit). The position corresponds to the index in the FloatDataArrays where the ion mobility data is stored. Always use this method rather than assuming the first FloatDataArray contains ion mobility data.
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/pyOpenMS/tests/**/*.py : Write pyOpenMS tests for new Python bindings
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/pyOpenMS/**/*.h : Add Doxygen comments for new public methods and classes in pyOpenMS bindings
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/pyOpenMS/tests/**/*.py : Write pyOpenMS tests for new Python bindings

Applied to files:

  • src/pyOpenMS/tests/unittests/test_SpectrumAccessOpenMS.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: build-lnx-arm
  • GitHub Check: build-lnx
  • GitHub Check: build-and-test (ubuntu-22.04-arm, g++, 11)
  • GitHub Check: build-and-test (ubuntu-22.04, clang++, 15)
  • GitHub Check: build-and-test (ubuntu-22.04, g++, 11)
  • GitHub Check: build-win
  • GitHub Check: build-and-test (windows-2022, cl.exe, 14.36)
  • GitHub Check: cppcheck-test
🔇 Additional comments (4)
src/pyOpenMS/tests/unittests/test_DIAScoring.py (1)

33-34: Use of snake_case OSSpectrum setters looks correct

Switch to set_mz_array / set_intensity_array is consistent with the new API; data lengths match and test behavior is unchanged.

src/pyOpenMS/tests/unittests/test_ISpectrumAccess.py (1)

17-18: Consistent migration to snake_case spectrum accessors

All spectrum reads now use get_mz_array() / get_intensity_array(), matching the renamed API while keeping the original assertions and coverage intact.

Also applies to: 40-41, 79-80, 110-111

src/pyOpenMS/tests/unittests/test_ChromatogramExtractor.py (1)

45-49: Chromatogram accessors correctly updated to snake_case

Using get_intensity_array() and get_time_array() here aligns with the new OSChromatogram API and keeps the existing semantics of the test (non‑empty, length == exp.size()).

src/pyOpenMS/tests/unittests/test_SpectrumAccessOpenMS.py (1)

17-18: SpectrumAccessOpenMS test updated correctly to new accessors

Using get_mz_array() and get_intensity_array() here matches the renamed API and preserves the original numerical checks.

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.

4 participants