Skip to content

Deleted LinearResampler - #9153

Merged
timosachsenberg merged 1 commit into
OpenMS:developfrom
LuBox2K:delete_LinearResampler
Apr 16, 2026
Merged

timosachsenberg merged 1 commit into
OpenMS:developfrom
LuBox2K:delete_LinearResampler

Conversation

@LuBox2K

@LuBox2K LuBox2K commented Apr 15, 2026 •

Copy link
Copy Markdown
Contributor

Description

We have found the base class of LinearResaplerAlign, LinearResampler to be obsolete. We have deleted the Class and merged the tests and funcs. Additionally we have built a warn message into the Resampler, reminding the user that too high a sampling rate may result in false Peaks to be created. This is a result of the resampler redistributing peaks into the direct neighbours on the resampled spectrum. This creates Areas of 0 intensity if more than three output points are enclosed by two input Points
(if sampling rate is smaller than the smallest gap in the spectrum - presumably the dead time of the detector)

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

  • Refactor
    • Resampling subsystem consolidated into a single improved implementation with better parameter handling, progress reporting, and spacing-validation warnings.
  • Documentation
    • Tutorials and changelog updated to reference the consolidated resampler and note removal of the previous implementation.
  • Chores
    • Added two new contributors to the authors list.
  • Tests
    • Test suite updated to exercise the consolidated resampler; tests for the removed implementation were removed.

@github-actions

Copy link
Copy Markdown
Contributor

Welcome @LuBox2K and thank you for your contribution to OpenMS! To help us better understand our userbase and contributors, we would appreciate if you could complete the survey at the link below. Completing this survey will help us get to your PR sooner. Thank you for your participation!

Survey

@github-actions

Copy link
Copy Markdown
Contributor

@LuBox2K The following names might be missing from the AUTHORS file:

  • luik42

Please consider applying the following patch:

--- AUTHORS	2026-04-15 12:27:20.613546199 +0000
+++ AUTHORS.new	2026-04-15 12:27:24.757258956 +0000
@@ -5,18 +5,19 @@
 The following authors contributed to OpenMS at some point. For the
 authors contributing to a specific piece of code, please refer to
 the authors tag in the respective file header.
+ - Michael R. Crusoe
  - Achal Bajpai
  - Aditya Muzumdar
  - Ahmed Khalil
  - Alen Saric
  - Alexandra Scherbart
- - Axel Walter
  - Alexandra Zerck
  - Amanda Wein
  - Andreas Bertsch
  - Andreas Simon
  - Anton Kriese
  - Anton Pervukhin
+ - Axel Walter
  - Bastian Blank
  - Chenghao Zhu
  - Chirag Dave
@@ -27,8 +28,8 @@
  - Cornelia Friedle
  - Daniel Jameson
  - Darren Kessner
- - David Wojnar
  - David Voigt
+ - David Wojnar
  - Dhanmoni Nath
  - Dilek Dere
  - Dimitri Schachmann
@@ -55,14 +56,14 @@
  - Jang Jang Jin
  - Jeremi Maciejewski
  - Jihyung Kim
- - Johan Teleman
  - Johannes Junker
  - Johannes Veit
  - Johannes von Kleist
+ - Johan Teleman
  - Joshua Charkow
- - Julia Thueringer
  - Juliane Schmachtenberg
  - Julianus Pfeuffer
+ - Julia Thueringer
  - Justin Sing
  - Katharina Albers
  - Khue Nguyen
@@ -74,6 +75,7 @@
  - Leon Bichmann
  - Leon Kuchenbecker
  - Lucia Espona
+ - luik42
  - Luis Jacob Keller
  - Lukas Mueller
  - Lukas Zimmermann
@@ -86,7 +88,6 @@
  - Matteo Pilz
  - Matthew The
  - Matthias Bernt
- - Michael R. Crusoe
  - Michał Startek
  - Mohamed Ali
  - Nico Pfeifer
@@ -112,11 +113,11 @@
  - Sven Nahnsen
  - Svetlana Kutuzova
  - Swenja Wagner
- - Taraneh Strunk
  - Tapasweni Pathak
+ - Taraneh Strunk
+ - Till Englert
  - Timo Sachsenberg
  - Tinatin Kasradze
- - Till Englert
  - Tom David Müller
  - Tom Lukas Lankenau
  - Tom Waschischeck

@coderabbitai

coderabbitai Bot commented Apr 15, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The standalone LinearResampler class and its global instances were removed. Functionality was consolidated into LinearResamplerAlign (now inheriting DefaultParamHandler and ProgressLogger), which gained spacing verification and an experiment-level rasterExperiment with progress reporting. Examples, docs, bindings, tests, and CMake lists were updated accordingly.

Changes

Cohort / File(s) Summary
Metadata
AUTHORS, CHANGELOG
Added authors Alen Saric and Luis Jacob Keller; added changelog note stating LinearResampler was deleted and refactored into LinearResamplerAlign (#9153).
Removed resampler implementation
src/openms/include/OpenMS/PROCESSING/RESAMPLING/LinearResampler.h, src/openms/source/PROCESSING/RESAMPLING/LinearResampler.cpp
Deleted the LinearResampler header and source, removing its APIs (raster, rasterExperiment) and two global default instances.
Refactored resampler header
src/openms/include/OpenMS/PROCESSING/RESAMPLING/LinearResamplerAlign.h
Changed base classes to DefaultParamHandler, ProgressLogger; added constructor init, spacing_ member, verifySpacing_() helper, inserted spacing checks into raster entry points, and added rasterExperiment(PeakMap&).
Build lists
src/openms/include/.../sources.cmake, src/openms/source/.../sources.cmake, src/tests/class_tests/openms/executables.cmake
Removed LinearResampler.h/.cpp from CMake lists and removed LinearResampler_test from test executables.
Python bindings & tests
src/pyOpenMS/bindings/bind_misc.cpp, src/pyOpenMS/tests/unittests/test000.py
Removed Python binding for LinearResampler; adjusted LinearResamplerAlign binding base class and exposed raster overloads; renamed/updated test to testLinearResamplerAlign.
C++ tests
src/tests/class_tests/openms/source/LinearResampler_test.cpp, src/tests/class_tests/openms/source/LinearResamplerAlign_test.cpp
Deleted old LinearResampler C++ test; expanded/modified LinearResamplerAlign test (construction/destruction, rasterExperiment, iterator-based raster).
Docs, examples & UI
doc/code_examples/Tutorial_SavitzkyGolayFilter.cpp, doc/doxygen/parameters/DefaultParamHandlerDocumenter.cpp, src/openms_gui/.../ImageCreator.cpp, src/topp/Resampler.cpp
Example switched includes/usage to LinearResamplerAlign; removed DOCME(LinearResampler) include and include in GUI; minor comment tweaks in Resampler.

Sequence Diagram(s)

sequenceDiagram
    rect rgba(200,200,255,0.5)
    participant Tool as Resampler (topp/Resampler)
    participant Align as LinearResamplerAlign
    participant Exp as MSExperiment/PeakMap
    participant Logger as ProgressLogger
    end

    Tool->>Align: construct & setParameters(param)
    Tool->>Align: rasterExperiment(exp)
    Align->>Logger: startProgress(total_spectra)
    loop per spectrum
        Align->>Exp: get spectrum[i]
        Align->>Align: verifySpacing_(spectrum)
        Align->>Align: raster(spectrum)
        Align->>Logger: setProgress(i)
    end
    Align->>Logger: endProgress()
    Align-->>Tool: return
Loading

Possibly related PRs

Suggested reviewers

  • cbielow
  • jpfeuffer

Poem

🐰 I hopped through headers, tests, and more,
The LinearResampler left the door.
Align now checks spacing, logs the run,
Examples, bindings, and changelogs done.
Two new names added — hooray, hooray for four!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 'Deleted LinearResampler' directly and accurately describes the main change in the pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/pyOpenMS/bindings/bind_misc.cpp (1)

2646-2654: ⚠️ Potential issue | 🟠 Major

LinearResamplerAlign binding is missing inherited DefaultParamHandler interface and raster method

The test in src/pyOpenMS/tests/unittests/test000.py:1862-1866 explicitly expects getDefaults() and raster() methods on LinearResamplerAlign, but the current binding at line 2646 neither declares DefaultParamHandler as a base class nor exposes the raster methods. This breaks the test and removes user-visible API surface.

Additionally, per coding guidelines, the binding lacks copy constructor, __copy__, and __deepcopy__ methods.

Proposed fix
-    auto linearresampleralign_class = nb::class_<OpenMS::LinearResamplerAlign>(m, "LinearResamplerAlign", 
+    auto linearresampleralign_class = nb::class_<OpenMS::LinearResamplerAlign, OpenMS::DefaultParamHandler>(m, "LinearResamplerAlign", 
         R"doc(
 Linear Resampling of raw data with alignment
 LinearResamplerAlign
 )doc")
         .def(nb::init<>())
+        .def(nb::init<const OpenMS::LinearResamplerAlign &>())
+        .def("__copy__", [](const OpenMS::LinearResamplerAlign& self) { return OpenMS::LinearResamplerAlign(self); })
+        .def("__deepcopy__", [](const OpenMS::LinearResamplerAlign& self, nb::dict) { return OpenMS::LinearResamplerAlign(self); }, "memo"_a)
+        .def("raster", [](OpenMS::LinearResamplerAlign& self, OpenMS::MSSpectrum& spectrum) { self.raster(spectrum); }, "spectrum"_a, "Resamples a single spectrum")
         .def("rasterExperiment", [](OpenMS::LinearResamplerAlign& self, OpenMS::MSExperiment& exp) { return self.rasterExperiment(exp); }, "exp"_a, "Resamples the data in an MSExperiment")
         ;
     def_ProgressLogger<OpenMS::LinearResamplerAlign>(linearresampleralign_class);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/pyOpenMS/bindings/bind_misc.cpp` around lines 2646 - 2654, The
LinearResamplerAlign binding needs to inherit DefaultParamHandler, expose its
raster overloads, and add copy semantics: modify the nb::class_ declaration for
OpenMS::LinearResamplerAlign to include nb::base<OpenMS::DefaultParamHandler>(),
add bindings for both raster methods (e.g., raster(OpenMS::MSChromatogram&) and
raster(OpenMS::MSExperiment&)) in addition to the existing rasterExperiment, and
add the copy constructor and Python helpers by binding the copy ctor and methods
__copy__ and __deepcopy__ (forwarding to the copy ctor) so
getDefaults()/DefaultParamHandler methods and proper copy behavior are
available; keep def_ProgressLogger<OpenMS::LinearResamplerAlign>(...) as-is.
🧹 Nitpick comments (5)
src/openms/include/OpenMS/PROCESSING/RESAMPLING/LinearResamplerAlign.h (3)

339-344: Misplaced member variable comment.

The comment "Spacing of the resampled data" on line 343 appears to describe spacing_ but is positioned above ppm_. Consider moving it to the correct location.

♻️ Suggested fix
 protected:
 
+    /// Spacing of the resampled output peaks
     double spacing_;
 
-    /// Spacing of the resampled data
+    /// Whether spacing is in ppm or Th
     bool ppm_;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openms/include/OpenMS/PROCESSING/RESAMPLING/LinearResamplerAlign.h`
around lines 339 - 344, The doc comment "Spacing of the resampled data" is
attached to the wrong member; move that comment so it documents spacing_ (double
spacing_) rather than ppm_ (bool ppm_). In the class LinearResamplerAlign
(header OpenMS/PROCESSING/RESAMPLING/LinearResamplerAlign.h) adjust the member
declarations so spacing_ is immediately preceded by the "Spacing of the
resampled data" comment and leave ppm_ with an appropriate or no comment.

112-112: Inconsistent lambda syntax across verifySpacing_ calls.

Line 112 uses C++20 explicit template lambda syntax []<typename PeakTypeIterator>(...), while line 155 uses a simpler generic lambda [](auto x){...}. For consistency and simplicity, consider using the same style across all call sites.

♻️ Suggested fix
-      verifySpacing_(first, last, []<typename PeakTypeIterator>(PeakTypeIterator x){return x->getPos();});
+      verifySpacing_(first, last, [](auto x){return x->getPos();});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openms/include/OpenMS/PROCESSING/RESAMPLING/LinearResamplerAlign.h` at
line 112, The two calls to verifySpacing_ use inconsistent lambda forms; replace
the explicit template lambda in the call that currently uses []<typename
PeakTypeIterator>(PeakTypeIterator x){ return x->getPos(); } with a generic
lambda using auto (i.e. [](auto x){ return x->getPos(); }) so both
verifySpacing_ invocations use the same simple generic-lambda style; update the
call site that references PeakTypeIterator/getPos to use the [](auto x){...}
form.

386-406: Inconsistent brace style and potential improvement for iterator handling.

Per coding guidelines, braces should be on their own lines. Additionally, the loop condition could be made more consistent with line 390.

♻️ Suggested improvements
     template <typename PeakTypeIterator>
     void verifySpacing_(PeakTypeIterator it, PeakTypeIterator end, auto access)
     {
       if (it == end || std::next(it) == end) return;
       double min_dist = std::numeric_limits<double>::infinity();
       double current_dist{};
   
-      while (it != end-1)
+      while (std::next(it) != end)
       {
         current_dist = (access(std::next(it)) - access(it));
         if (min_dist > current_dist) min_dist = current_dist;
         ++it;
       }
   
-      if (spacing_ < min_dist){
-          OPENMS_LOG_WARN << "you have chosen a resampling rate of: " << spacing_ <<\
-          "\n this is smaller than the smallest Distance (" << min_dist << ") between Datapoints.\n\
-           Since this approximates the dead time of the Detector this can result in fake peaks";
-        }
+      if (spacing_ < min_dist)
+      {
+        OPENMS_LOG_WARN << "Resampling spacing (" << spacing_
+                        << ") is smaller than the smallest distance between data points ("
+                        << min_dist << "). This may result in spurious peaks.\n";
+      }
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openms/include/OpenMS/PROCESSING/RESAMPLING/LinearResamplerAlign.h`
around lines 386 - 406, The verifySpacing_ helper uses inconsistent brace
placement and an unsafe loop condition; update the function (verifySpacing_) to
place opening braces on their own lines per style, and replace while (it !=
end-1) with while (std::next(it) != end) (or equivalently while (it + 1 != end)
for random-access) to avoid iterator arithmetic on non-random-access iterators;
keep the initial guard (if (it == end || std::next(it) == end) return) and the
access(...) distance calculation unchanged, and ensure the OPENMS_LOG_WARN call
remains after the loop with its braces on separate lines as well.
src/pyOpenMS/tests/unittests/test000.py (1)

1865-1866: Consider adding one behavioral assertion for rasterExperiment.

Line 1865 and Line 1866 currently validate method presence only. A tiny round-trip/shape-intensity assertion would better catch binding regressions.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/pyOpenMS/tests/unittests/test000.py` around lines 1865 - 1866, Create a
small behavioral round-trip for LinearResamplerAlign.rasterExperiment:
instantiate pyopenms.LinearResamplerAlign(), build a tiny pyopenms.MSExperiment
with one spectrum containing a single peak (set m/z and intensity), assign it to
lr.rasterExperiment, then retrieve lr.rasterExperiment and assert the spectrum
count and the first spectrum's peak m/z/intensity match the original; reference
LinearResamplerAlign, rasterExperiment, MSExperiment and
getNrSpectra()/get_peaks()/or spectrum peak accessors to locate where to add the
test.
src/tests/class_tests/openms/source/LinearResamplerAlign_test.cpp (1)

63-73: Prefer stack objects over raw pointers in this test section.

Line 63 to Line 73 use manual new/delete only to exercise ctor/dtor. Use scoped stack allocation instead; it’s simpler and avoids pointer management noise.

As per coding guidelines: "Avoid pointers; prefer references in C++".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/tests/class_tests/openms/source/LinearResamplerAlign_test.cpp` around
lines 63 - 73, Replace the heap allocation and manual delete with a
stack-allocated object: remove lr_ptr and lr_nullPointer, and in
START_SECTION(LinearResamplerAlign()) construct a local LinearResamplerAlign lr;
then assert the object exists by e.g. TEST_NOT_EQUAL(&lr,
static_cast<LinearResamplerAlign*>(nullptr)) or other non-null pointer check if
you need a pointer; remove the explicit delete in the destructor section since
the stack object will be destroyed automatically. Ensure references to lr_ptr
are updated to use lr (or &lr where a pointer is required).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@doc/doxygen/parameters/DefaultParamHandlerDocumenter.cpp`:
- Line 435: The inline comment beside DOCME2(BinnedSpectrumCompareFunctor,
(BinnedSharedPeakCount())); is incorrect: it refers to BaseModel but the
documented symbol is BinnedSpectrumCompareFunctor. Update the comment to refer
to the actual symbol—e.g., note that BinnedSpectrumCompareFunctor is the base
functor and parameters are taken from the subclass BinnedSharedPeakCount (or
state that BinnedSpectrumCompareFunctor documents parameters from
BinnedSharedPeakCount), so replace the mismatched "BaseModel" text with
"BinnedSpectrumCompareFunctor" (or rephrase to clarify the relationship between
BinnedSpectrumCompareFunctor and BinnedSharedPeakCount).

In `@src/openms/include/OpenMS/PROCESSING/RESAMPLING/LinearResamplerAlign.h`:
- Around line 36-37: The Doxygen `@warning` block in LinearResamplerAlign.h is
malformed and unclear: replace the invalid "@param spacing_" usage with a proper
inline reference (e.g., "@p spacing_" or "spacing_") and rewrite the warning
text to be syntactically correct and clearer (for example: "@warning If the
minimal distance between two points is less than `@p` spacing_, using a sampling
rate below the instrument dead time can produce incorrectly distributed or
missing peaks."). Update the comment for the LinearResamplerAlign class/function
where spacing_ is documented to use this corrected `@warning` formatting and
wording.
- Around line 327-336: Add Doxygen documentation for the public method
rasterExperiment describing purpose, parameters (PeakMap& exp), behavior and
return, and explicitly state whether chromatograms are processed; if
chromatograms must be resampled, update rasterExperiment to iterate
exp.getChromatograms() and call the appropriate resampling routine, otherwise
document why chromatograms are intentionally excluded. Also fix the indentation
of the opening brace for rasterExperiment to use 4 spaces to match project
style. Ensure you reference rasterExperiment, raster(exp[i]) and
getChromatograms() in the comment so reviewers can see the intended handling.

---

Outside diff comments:
In `@src/pyOpenMS/bindings/bind_misc.cpp`:
- Around line 2646-2654: The LinearResamplerAlign binding needs to inherit
DefaultParamHandler, expose its raster overloads, and add copy semantics: modify
the nb::class_ declaration for OpenMS::LinearResamplerAlign to include
nb::base<OpenMS::DefaultParamHandler>(), add bindings for both raster methods
(e.g., raster(OpenMS::MSChromatogram&) and raster(OpenMS::MSExperiment&)) in
addition to the existing rasterExperiment, and add the copy constructor and
Python helpers by binding the copy ctor and methods __copy__ and __deepcopy__
(forwarding to the copy ctor) so getDefaults()/DefaultParamHandler methods and
proper copy behavior are available; keep
def_ProgressLogger<OpenMS::LinearResamplerAlign>(...) as-is.

---

Nitpick comments:
In `@src/openms/include/OpenMS/PROCESSING/RESAMPLING/LinearResamplerAlign.h`:
- Around line 339-344: The doc comment "Spacing of the resampled data" is
attached to the wrong member; move that comment so it documents spacing_ (double
spacing_) rather than ppm_ (bool ppm_). In the class LinearResamplerAlign
(header OpenMS/PROCESSING/RESAMPLING/LinearResamplerAlign.h) adjust the member
declarations so spacing_ is immediately preceded by the "Spacing of the
resampled data" comment and leave ppm_ with an appropriate or no comment.
- Line 112: The two calls to verifySpacing_ use inconsistent lambda forms;
replace the explicit template lambda in the call that currently uses []<typename
PeakTypeIterator>(PeakTypeIterator x){ return x->getPos(); } with a generic
lambda using auto (i.e. [](auto x){ return x->getPos(); }) so both
verifySpacing_ invocations use the same simple generic-lambda style; update the
call site that references PeakTypeIterator/getPos to use the [](auto x){...}
form.
- Around line 386-406: The verifySpacing_ helper uses inconsistent brace
placement and an unsafe loop condition; update the function (verifySpacing_) to
place opening braces on their own lines per style, and replace while (it !=
end-1) with while (std::next(it) != end) (or equivalently while (it + 1 != end)
for random-access) to avoid iterator arithmetic on non-random-access iterators;
keep the initial guard (if (it == end || std::next(it) == end) return) and the
access(...) distance calculation unchanged, and ensure the OPENMS_LOG_WARN call
remains after the loop with its braces on separate lines as well.

In `@src/pyOpenMS/tests/unittests/test000.py`:
- Around line 1865-1866: Create a small behavioral round-trip for
LinearResamplerAlign.rasterExperiment: instantiate
pyopenms.LinearResamplerAlign(), build a tiny pyopenms.MSExperiment with one
spectrum containing a single peak (set m/z and intensity), assign it to
lr.rasterExperiment, then retrieve lr.rasterExperiment and assert the spectrum
count and the first spectrum's peak m/z/intensity match the original; reference
LinearResamplerAlign, rasterExperiment, MSExperiment and
getNrSpectra()/get_peaks()/or spectrum peak accessors to locate where to add the
test.

In `@src/tests/class_tests/openms/source/LinearResamplerAlign_test.cpp`:
- Around line 63-73: Replace the heap allocation and manual delete with a
stack-allocated object: remove lr_ptr and lr_nullPointer, and in
START_SECTION(LinearResamplerAlign()) construct a local LinearResamplerAlign lr;
then assert the object exists by e.g. TEST_NOT_EQUAL(&lr,
static_cast<LinearResamplerAlign*>(nullptr)) or other non-null pointer check if
you need a pointer; remove the explicit delete in the destructor section since
the stack object will be destroyed automatically. Ensure references to lr_ptr
are updated to use lr (or &lr where a pointer is required).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 783b3f49-a918-43dc-a254-c4dd965947f5

📥 Commits

Reviewing files that changed from the base of the PR and between cf71232 and 0a1c46c.

📒 Files selected for processing (16)
  • AUTHORS
  • CHANGELOG
  • doc/code_examples/Tutorial_SavitzkyGolayFilter.cpp
  • doc/doxygen/parameters/DefaultParamHandlerDocumenter.cpp
  • src/openms/include/OpenMS/PROCESSING/RESAMPLING/LinearResampler.h
  • src/openms/include/OpenMS/PROCESSING/RESAMPLING/LinearResamplerAlign.h
  • src/openms/include/OpenMS/PROCESSING/RESAMPLING/sources.cmake
  • src/openms/source/PROCESSING/RESAMPLING/LinearResampler.cpp
  • src/openms/source/PROCESSING/RESAMPLING/sources.cmake
  • src/openms_gui/source/VISUAL/APPLICATIONS/GUITOOLS/ImageCreator.cpp
  • src/pyOpenMS/bindings/bind_misc.cpp
  • src/pyOpenMS/tests/unittests/test000.py
  • src/tests/class_tests/openms/executables.cmake
  • src/tests/class_tests/openms/source/LinearResamplerAlign_test.cpp
  • src/tests/class_tests/openms/source/LinearResampler_test.cpp
  • src/topp/Resampler.cpp
💤 Files with no reviewable changes (7)
  • src/openms/source/PROCESSING/RESAMPLING/sources.cmake
  • src/openms/include/OpenMS/PROCESSING/RESAMPLING/sources.cmake
  • src/tests/class_tests/openms/executables.cmake
  • src/openms/source/PROCESSING/RESAMPLING/LinearResampler.cpp
  • src/openms_gui/source/VISUAL/APPLICATIONS/GUITOOLS/ImageCreator.cpp
  • src/openms/include/OpenMS/PROCESSING/RESAMPLING/LinearResampler.h
  • src/tests/class_tests/openms/source/LinearResampler_test.cpp

timosachsenberg added a commit to LuBox2K/OpenMS that referenced this pull request Apr 16, 2026
LinearResamplerAlign is a strict superset of LinearResampler (adds
explicit raster alignment, ppm-spaced rasters, chromatogram support
and a linear-interpolation mode). Delete the narrower LinearResampler
class and redirect its callers (Tutorial_SavitzkyGolayFilter,
ImageCreator, DefaultParamHandlerDocumenter, pyOpenMS binding) to
LinearResamplerAlign.

Also add a runtime warning (verifySpacing_) when the configured
spacing is finer than the minimum distance between adjacent input
points, which can produce spurious peaks below the detector dead time.

Co-authored-by: Luis Jacob Keller <[email protected]>
Co-authored-by: Alen Saric <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@timosachsenberg
timosachsenberg force-pushed the delete_LinearResampler branch from 4a7865a to f2a96b9 Compare April 16, 2026 09:20

@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 (1)
src/tests/class_tests/openms/source/LinearResamplerAlign_test.cpp (1)

59-65: Use snake_case here and simplify the null check.

Line 60 (lr_nullPointer) breaks snake_case and is unnecessary for the assertion; compare directly to nullptr.

Proposed cleanup
-LinearResamplerAlign* lr_ptr = nullptr;
-LinearResamplerAlign* lr_nullPointer = nullptr;
+LinearResamplerAlign* lr_ptr = nullptr;

 START_SECTION(LinearResamplerAlign())
   lr_ptr = new LinearResamplerAlign;
-  TEST_NOT_EQUAL(lr_ptr, lr_nullPointer);
+  TEST_NOT_EQUAL(lr_ptr, nullptr);
 END_SECTION

As per coding guidelines, "Use snake_case for variable names in C++".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/tests/class_tests/openms/source/LinearResamplerAlign_test.cpp` around
lines 59 - 65, The test creates an unnecessary camelCase variable lr_nullPointer
and should use snake_case and a direct nullptr comparison: remove
lr_nullPointer, keep (or rename) lr_ptr as a snake_case pointer variable,
allocate it with new LinearResamplerAlign in the START_SECTION block, and
replace TEST_NOT_EQUAL(lr_ptr, lr_nullPointer) with TEST_NOT_EQUAL(lr_ptr,
nullptr) (references: LinearResamplerAlign, lr_ptr, START_SECTION,
TEST_NOT_EQUAL).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/pyOpenMS/bindings/bind_misc.cpp`:
- Around line 2646-2655: The LinearResamplerAlign binding currently exposes only
nb::init<>(), so add the copy constructor and Python copy support: include
nb::init<const OpenMS::LinearResamplerAlign &>() for the copy ctor, then add
.def("__copy__", [](const OpenMS::LinearResamplerAlign &self){ return
OpenMS::LinearResamplerAlign(self); }) and .def("__deepcopy__", [](const
OpenMS::LinearResamplerAlign &self, nb::object /*memo*/){ return
OpenMS::LinearResamplerAlign(self); }) to the nb::class_ chain for
OpenMS::LinearResamplerAlign so it matches other pyOpenMS classes and preserves
copy/deepcopy behavior.

---

Nitpick comments:
In `@src/tests/class_tests/openms/source/LinearResamplerAlign_test.cpp`:
- Around line 59-65: The test creates an unnecessary camelCase variable
lr_nullPointer and should use snake_case and a direct nullptr comparison: remove
lr_nullPointer, keep (or rename) lr_ptr as a snake_case pointer variable,
allocate it with new LinearResamplerAlign in the START_SECTION block, and
replace TEST_NOT_EQUAL(lr_ptr, lr_nullPointer) with TEST_NOT_EQUAL(lr_ptr,
nullptr) (references: LinearResamplerAlign, lr_ptr, START_SECTION,
TEST_NOT_EQUAL).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9bb062db-952f-4929-845f-9f96405c1e85

📥 Commits

Reviewing files that changed from the base of the PR and between 4a7865a and f2a96b9.

📒 Files selected for processing (16)
  • AUTHORS
  • CHANGELOG
  • doc/code_examples/Tutorial_SavitzkyGolayFilter.cpp
  • doc/doxygen/parameters/DefaultParamHandlerDocumenter.cpp
  • src/openms/include/OpenMS/PROCESSING/RESAMPLING/LinearResampler.h
  • src/openms/include/OpenMS/PROCESSING/RESAMPLING/LinearResamplerAlign.h
  • src/openms/include/OpenMS/PROCESSING/RESAMPLING/sources.cmake
  • src/openms/source/PROCESSING/RESAMPLING/LinearResampler.cpp
  • src/openms/source/PROCESSING/RESAMPLING/sources.cmake
  • src/openms_gui/source/VISUAL/APPLICATIONS/GUITOOLS/ImageCreator.cpp
  • src/pyOpenMS/bindings/bind_misc.cpp
  • src/pyOpenMS/tests/unittests/test000.py
  • src/tests/class_tests/openms/executables.cmake
  • src/tests/class_tests/openms/source/LinearResamplerAlign_test.cpp
  • src/tests/class_tests/openms/source/LinearResampler_test.cpp
  • src/topp/Resampler.cpp
💤 Files with no reviewable changes (8)
  • doc/doxygen/parameters/DefaultParamHandlerDocumenter.cpp
  • src/openms/include/OpenMS/PROCESSING/RESAMPLING/sources.cmake
  • src/tests/class_tests/openms/executables.cmake
  • src/openms/source/PROCESSING/RESAMPLING/sources.cmake
  • src/openms/source/PROCESSING/RESAMPLING/LinearResampler.cpp
  • src/openms_gui/source/VISUAL/APPLICATIONS/GUITOOLS/ImageCreator.cpp
  • src/tests/class_tests/openms/source/LinearResampler_test.cpp
  • src/openms/include/OpenMS/PROCESSING/RESAMPLING/LinearResampler.h
✅ Files skipped from review due to trivial changes (5)
  • AUTHORS
  • src/topp/Resampler.cpp
  • CHANGELOG
  • doc/code_examples/Tutorial_SavitzkyGolayFilter.cpp
  • src/openms/include/OpenMS/PROCESSING/RESAMPLING/LinearResamplerAlign.h
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/pyOpenMS/tests/unittests/test000.py

Comment thread src/pyOpenMS/bindings/bind_misc.cpp Resolved
Comment on lines +128 to +162
START_SECTION(( template <typename PeakType > void rasterExperiment(MSExperiment<PeakType>& exp)))
{
MSSpectrum spec;
spec.resize(5);
spec[0].setMZ(0);
spec[0].setIntensity(3.0f);
spec[1].setMZ(0.5);
spec[1].setIntensity(6.0f);
spec[2].setMZ(1.);
spec[2].setIntensity(8.0f);
spec[3].setMZ(1.6);
spec[3].setIntensity(2.0f);
spec[4].setMZ(1.8);
spec[4].setIntensity(1.0f);

PeakMap exp;
exp.addSpectrum(spec);
exp.addSpectrum(spec);

LinearResamplerAlign lr;
Param param;
param.setValue("spacing",0.5);
lr.setParameters(param);
lr.rasterExperiment(exp);


for (Size s=0; s<exp.size(); ++s)
{
double sum = 0.0;
for (Size i=0; i<exp[s].size(); ++i)
{
sum += exp[s][i].getIntensity();
}
TEST_REAL_SIMILAR(sum, 20);
}

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.

⚠️ Potential issue | 🟠 Major

rasterExperiment assertions are too weak for this new coverage.

The section currently checks only summed intensity (Line 161). That can pass even when peak redistribution is wrong. Please add point-wise assertions (or explicit expected bins) so regressions in resampling shape are caught.

Suggested stronger assertions
   lr.rasterExperiment(exp);

-  for (Size s=0; s<exp.size(); ++s)
+  TEST_EQUAL(exp.size(), 2);
+  TEST_EQUAL(exp[0].size(), exp[1].size());
+
+  for (Size s = 0; s < exp.size(); ++s)
   {
     double sum = 0.0;
-    for (Size i=0; i<exp[s].size(); ++i)
+    for (Size i = 0; i < exp[s].size(); ++i)
     {
       sum += exp[s][i].getIntensity();
     }
     TEST_REAL_SIMILAR(sum, 20);
   }
+
+  for (Size i = 0; i < exp[0].size(); ++i)
+  {
+    TEST_REAL_SIMILAR(exp[0][i].getMZ(), exp[1][i].getMZ());
+    TEST_REAL_SIMILAR(exp[0][i].getIntensity(), exp[1][i].getIntensity());
+  }

Based on learnings, "Write unit tests for new functionality and ensure existing tests pass before suggesting changes."

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
START_SECTION(( template <typename PeakType > void rasterExperiment(MSExperiment<PeakType>& exp)))
{
MSSpectrum spec;
spec.resize(5);
spec[0].setMZ(0);
spec[0].setIntensity(3.0f);
spec[1].setMZ(0.5);
spec[1].setIntensity(6.0f);
spec[2].setMZ(1.);
spec[2].setIntensity(8.0f);
spec[3].setMZ(1.6);
spec[3].setIntensity(2.0f);
spec[4].setMZ(1.8);
spec[4].setIntensity(1.0f);
PeakMap exp;
exp.addSpectrum(spec);
exp.addSpectrum(spec);
LinearResamplerAlign lr;
Param param;
param.setValue("spacing",0.5);
lr.setParameters(param);
lr.rasterExperiment(exp);
for (Size s=0; s<exp.size(); ++s)
{
double sum = 0.0;
for (Size i=0; i<exp[s].size(); ++i)
{
sum += exp[s][i].getIntensity();
}
TEST_REAL_SIMILAR(sum, 20);
}
START_SECTION(( template <typename PeakType > void rasterExperiment(MSExperiment<PeakType>& exp)))
{
MSSpectrum spec;
spec.resize(5);
spec[0].setMZ(0);
spec[0].setIntensity(3.0f);
spec[1].setMZ(0.5);
spec[1].setIntensity(6.0f);
spec[2].setMZ(1.);
spec[2].setIntensity(8.0f);
spec[3].setMZ(1.6);
spec[3].setIntensity(2.0f);
spec[4].setMZ(1.8);
spec[4].setIntensity(1.0f);
PeakMap exp;
exp.addSpectrum(spec);
exp.addSpectrum(spec);
LinearResamplerAlign lr;
Param param;
param.setValue("spacing",0.5);
lr.setParameters(param);
lr.rasterExperiment(exp);
TEST_EQUAL(exp.size(), 2);
TEST_EQUAL(exp[0].size(), exp[1].size());
for (Size s = 0; s < exp.size(); ++s)
{
double sum = 0.0;
for (Size i = 0; i < exp[s].size(); ++i)
{
sum += exp[s][i].getIntensity();
}
TEST_REAL_SIMILAR(sum, 20);
}
for (Size i = 0; i < exp[0].size(); ++i)
{
TEST_REAL_SIMILAR(exp[0][i].getMZ(), exp[1][i].getMZ());
TEST_REAL_SIMILAR(exp[0][i].getIntensity(), exp[1][i].getIntensity());
}

@LuBox2K

LuBox2K commented Apr 16, 2026

Copy link
Copy Markdown
Contributor Author

RasterExperiment was removed since it was only used in testing..

Comment on lines +6 to +7
// $Authors: Hannes Roest, Luis Jacob Keller, Alen Saric$
// $Authors: Hannes Roest, Luis Jacob Keller, Alen Saric$

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.

I think you merged into your old local state... wait a second and give me permissions to commit on your branch and I will gix

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.

Fixed — force-pushed 9b4c16dbe4 which resets to the clean squash and cherry-picks only the compiling parts of your CodeRabbit-response commit (stack-alloc test, new pyOpenMS overloads). The duplicated class inheritance etc. was from git trying to merge your new commit against the pre-squash history.

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

♻️ Duplicate comments (1)
src/pyOpenMS/bindings/bind_misc.cpp (1)

2664-2666: ⚠️ Potential issue | 🟠 Major

Add rasterExperiment binding or update Python API documentation.

The C++ class has a rasterExperiment(PeakMap& exp) method (with progress tracking), but only raster overloads are exposed in Python bindings. This breaks existing Python code calling linearresampleralign.rasterExperiment(...). If intentionally replacing the method, ensure the change is documented and consider whether progress tracking is needed in the Python API.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/pyOpenMS/bindings/bind_misc.cpp` around lines 2664 - 2666, The Python
bindings expose LinearResamplerAlign::raster overloads but omit
LinearResamplerAlign::rasterExperiment(PeakMap&), breaking callers of
linearresampleralign.rasterExperiment; restore the binding in
src/pyOpenMS/bindings/bind_misc.cpp by adding a .def for "rasterExperiment" that
forwards to self.rasterExperiment(exp) (use OpenMS::MSExperiment/PeakMap as the
argument type used elsewhere) and ensure the binding signature supports progress
reporting if desired (mirror any existing progress-tracking overloads or provide
an optional callback/parameter consistent with other bindings), or if the method
was intentionally replaced, update the Python API docs to state rasterExperiment
was removed and map callers to the available raster overloads.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/openms/include/OpenMS/PROCESSING/RESAMPLING/LinearResamplerAlign.h`:
- Around line 164-167: The code calls verifySpacing_ twice on the same input
range, causing redundant full-range scans and duplicate warnings; remove the
duplicate invocations so each overload only calls verifySpacing_ once — update
both the m/z-intensity overload and the raster_interpolate() code paths to
eliminate the second verifySpacing_ call (keep a single verifySpacing_(raw_it,
raw_end, [](auto x){return x->getPos();}) per path).
- Around line 44-55: The class LinearResamplerAlign contains duplicate
base-specifiers (DefaultParamHandler, ProgressLogger) and two declarations of
the default constructor LinearResamplerAlign(), which makes the class invalid;
remove the duplicated inheritance list and the redundant constructor declaration
so there is a single inheritance clause and a single constructor definition for
LinearResamplerAlign (keeping the intended
DefaultParamHandler("LinearResamplerAlign") initializer in the one remaining
constructor).
- Around line 408-428: The comparison in verifySpacing_ is invalid when ppm_
mode is enabled because spacing_ is in ppm while min_dist is in absolute m/z
units; convert spacing_ to an absolute gap before comparing: inside
verifySpacing_ (use access, spacing_, ppm_, min_dist and the iterator it)
compute a local absolute spacing_abs = ppm_ ? (current_mz * spacing_ / 1e6)
where current_mz can be the m/z of the current iterator (or midpoint between it
and std::next(it)) and then compare spacing_abs < min_dist (and use spacing_abs
in the warning message), otherwise keep the existing absolute spacing_
comparison and message.

In `@src/pyOpenMS/bindings/bind_misc.cpp`:
- Around line 2660-2661: The Python bindings for LinearResamplerAlign are
calling the wrong C++ method and dropping results: update both lambdas to call
self.raster_interpolate(...) instead of self.raster(...), accept the output
parameter by reference (std::vector<...>& output) so the resampled peaks are
written into the caller-provided container, and return the (now-populated)
output vector to Python; apply this change for both Peak1D and Peak2D wrappers
referencing LinearResamplerAlign::raster_interpolate.
- Around line 2670-2717: The lambdas for OpenMS::LinearResamplerAlign::raster
currently mutate STL vectors (vector<double>, vector<OpenMS::Peak1D>,
vector<OpenMS::Peak2D> overloads and the eight-argument variants) which are
copied across the nanobind boundary, so change each lambda to call
self.raster(...) as today but then return the resampled output container(s)
(e.g., return the resampled vector or a tuple of resampled vectors) instead of
relying on in-place mutation; update the corresponding .def(...) bindings to
reflect the returned object(s) for the overloads referencing self.raster and the
argument names mz_resample/int_resample or resampled so Python callers receive
the modified containers.

In `@src/pyOpenMS/tests/unittests/test000.py`:
- Around line 1856-1869: Remove the duplicated function definition and repeated
lines for testLinearResamplerAlign: keep a single def
testLinearResamplerAlign(): block containing the docstring, one instantiation of
pyopenms.LinearResamplerAlign(), calling ff.getDefaults(), _testParam(p), and
the final assert checking .raster; delete the extra duplicate def and the
repeated statements so the test function is defined only once (references:
testLinearResamplerAlign, pyopenms.LinearResamplerAlign, ff.getDefaults,
_testParam, .raster).

In `@src/tests/class_tests/openms/source/LinearResamplerAlign_test.cpp`:
- Around line 14-24: Remove the duplicated `#include` directives: keep one each of
<OpenMS/KERNEL/MSSpectrum.h>, <OpenMS/KERNEL/Peak1D.h>, and
<OpenMS/test_config.h> and delete the extra occurrences (they are repeated in
the includes surrounding LinearResamplerAlign.h); update the top of
LinearResamplerAlign_test.cpp so each header is included only once to eliminate
merge-artifact duplicates.
- Around line 6-7: Remove the duplicated metadata author line by keeping a
single occurrence of the "$Authors: Hannes Roest, Luis Jacob Keller, Alen
Saric$" line in the file; locate the two identical "$Authors" lines (they appear
consecutively) and delete one so only one "$Authors" metadata line remains.

---

Duplicate comments:
In `@src/pyOpenMS/bindings/bind_misc.cpp`:
- Around line 2664-2666: The Python bindings expose LinearResamplerAlign::raster
overloads but omit LinearResamplerAlign::rasterExperiment(PeakMap&), breaking
callers of linearresampleralign.rasterExperiment; restore the binding in
src/pyOpenMS/bindings/bind_misc.cpp by adding a .def for "rasterExperiment" that
forwards to self.rasterExperiment(exp) (use OpenMS::MSExperiment/PeakMap as the
argument type used elsewhere) and ensure the binding signature supports progress
reporting if desired (mirror any existing progress-tracking overloads or provide
an optional callback/parameter consistent with other bindings), or if the method
was intentionally replaced, update the Python API docs to state rasterExperiment
was removed and map callers to the available raster overloads.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: df747143-6988-4004-a60b-f4bd70afe79c

📥 Commits

Reviewing files that changed from the base of the PR and between f2a96b9 and 4f6d43c.

📒 Files selected for processing (5)
  • doc/doxygen/parameters/DefaultParamHandlerDocumenter.cpp
  • src/openms/include/OpenMS/PROCESSING/RESAMPLING/LinearResamplerAlign.h
  • src/pyOpenMS/bindings/bind_misc.cpp
  • src/pyOpenMS/tests/unittests/test000.py
  • src/tests/class_tests/openms/source/LinearResamplerAlign_test.cpp

Comment on lines +164 to +167
verifySpacing_(raw_it, raw_end, [](auto x){return x->getPos();});

verifySpacing_(raw_it, raw_end, [](auto x){return x->getPos();});

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.

⚠️ Potential issue | 🟡 Minor

Call verifySpacing_ only once per overload.

Each of these paths invokes verifySpacing_ twice on the same input range. That doubles the full-range scan and prints the same warning twice for a single resampling call.

Proposed fix
-      verifySpacing_(raw_it, raw_end, [](auto x){return x->getPos();});
       verifySpacing_(raw_it, raw_end, [](auto x){return x->getPos();});

Apply the same deletion in the m/z-intensity overload and in raster_interpolate().

Also applies to: 245-248, 316-319

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openms/include/OpenMS/PROCESSING/RESAMPLING/LinearResamplerAlign.h`
around lines 164 - 167, The code calls verifySpacing_ twice on the same input
range, causing redundant full-range scans and duplicate warnings; remove the
duplicate invocations so each overload only calls verifySpacing_ once — update
both the m/z-intensity overload and the raster_interpolate() code paths to
eliminate the second verifySpacing_ call (keep a single verifySpacing_(raw_it,
raw_end, [](auto x){return x->getPos();}) per path).

Comment on lines +408 to +428
/// helper function to warn the user when the resampling rate is too high
template <typename PeakTypeIterator>
void verifySpacing_(PeakTypeIterator it, PeakTypeIterator end, auto access)
{
if (it == end || std::next(it) == end) return;
double min_dist = std::numeric_limits<double>::infinity();
double current_dist{};

while (it != end-1)
{
current_dist = (access(std::next(it)) - access(it));
if (min_dist > current_dist) min_dist = current_dist;
++it;
}

if (spacing_ < min_dist)
{
OPENMS_LOG_WARN << "you have chosen a resampling rate of: " << spacing_ <<\
"\n this is smaller than the smallest Distance (" << min_dist << ") between Datapoints.\n\
Since this approximates the dead time of the Detector this can result in fake peaks";
}

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.

⚠️ Potential issue | 🟠 Major

Don’t compare ppm spacing to absolute point distances.

min_dist is computed in the container’s coordinate units, but spacing_ is a ppm value when ppm_ is enabled. In that mode this warning becomes misleading, because the comparison is no longer dimensionally valid.

Safer short-term fix
-      if (spacing_ < min_dist)
+      if (!ppm_ && spacing_ < min_dist)

If you want the warning in ppm mode as well, convert the configured ppm spacing to a local absolute gap before comparing.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openms/include/OpenMS/PROCESSING/RESAMPLING/LinearResamplerAlign.h`
around lines 408 - 428, The comparison in verifySpacing_ is invalid when ppm_
mode is enabled because spacing_ is in ppm while min_dist is in absolute m/z
units; convert spacing_ to an absolute gap before comparing: inside
verifySpacing_ (use access, spacing_, ppm_, min_dist and the iterator it)
compute a local absolute spacing_abs = ppm_ ? (current_mz * spacing_ / 1e6)
where current_mz can be the m/z of the current iterator (or midpoint between it
and std::next(it)) and then compare spacing_abs < min_dist (and use spacing_abs
in the warning message), otherwise keep the existing absolute spacing_
comparison and message.

Comment thread src/pyOpenMS/bindings/bind_misc.cpp Outdated
Comment on lines +2660 to +2661
.def("raster_interpolate", [](OpenMS::LinearResamplerAlign& self, std::vector<OpenMS::Peak1D> input, std::vector<OpenMS::Peak1D> output) { return self.raster(input.begin(), input.end(), output.begin(), output.end()); }, "input"_a, "output"_a, "Resamples the data a container (P1D) to the peak positions in another (P1D)")
.def("raster_interpolate", [](OpenMS::LinearResamplerAlign& self, std::vector<OpenMS::Peak2D> input, std::vector<OpenMS::Peak2D> output) { return self.raster(input.begin(), input.end(), output.begin(), output.end()); }, "input"_a, "output"_a, "Resamples the data a container (P2D) to the peak positions in another (P2D)")

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.

⚠️ Potential issue | 🔴 Critical

raster_interpolate currently calls the wrong algorithm and drops the result.

These wrappers invoke self.raster(...) instead of self.raster_interpolate(...), so Python gets redistribution-based resampling rather than interpolation. They also return None after mutating a local output copy, so the computed peaks never reach the caller.

♻️ Proposed fix
-        .def("raster_interpolate", [](OpenMS::LinearResamplerAlign& self, std::vector<OpenMS::Peak1D> input, std::vector<OpenMS::Peak1D> output) { return self.raster(input.begin(), input.end(), output.begin(), output.end()); }, "input"_a, "output"_a, "Resamples the data a container (P1D) to the peak positions in another (P1D)")
-        .def("raster_interpolate", [](OpenMS::LinearResamplerAlign& self, std::vector<OpenMS::Peak2D> input, std::vector<OpenMS::Peak2D> output) { return self.raster(input.begin(), input.end(), output.begin(), output.end()); }, "input"_a, "output"_a, "Resamples the data a container (P2D) to the peak positions in another (P2D)")
+        .def("raster_interpolate", [](OpenMS::LinearResamplerAlign& self, std::vector<OpenMS::Peak1D> input, std::vector<OpenMS::Peak1D> output) {
+                                self.raster_interpolate(input.begin(), input.end(), output.begin(), output.end());
+                                return output;
+                                }, "input"_a, "output"_a, "Interpolate intensities from one Peak1D container onto another")
+        .def("raster_interpolate", [](OpenMS::LinearResamplerAlign& self, std::vector<OpenMS::Peak2D> input, std::vector<OpenMS::Peak2D> output) {
+                                self.raster_interpolate(input.begin(), input.end(), output.begin(), output.end());
+                                return output;
+                                }, "input"_a, "output"_a, "Interpolate intensities from one Peak2D container onto another")
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/pyOpenMS/bindings/bind_misc.cpp` around lines 2660 - 2661, The Python
bindings for LinearResamplerAlign are calling the wrong C++ method and dropping
results: update both lambdas to call self.raster_interpolate(...) instead of
self.raster(...), accept the output parameter by reference (std::vector<...>&
output) so the resampled peaks are written into the caller-provided container,
and return the (now-populated) output vector to Python; apply this change for
both Peak1D and Peak2D wrappers referencing
LinearResamplerAlign::raster_interpolate.

Comment thread src/pyOpenMS/bindings/bind_misc.cpp Resolved
Comment thread src/pyOpenMS/tests/unittests/test000.py Resolved
Comment on lines +6 to +7
// $Authors: Hannes Roest, Luis Jacob Keller, Alen Saric$
// $Authors: Hannes Roest, Luis Jacob Keller, Alen Saric$

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.

⚠️ Potential issue | 🟡 Minor

Duplicate $Authors line.

The author metadata line is duplicated. Remove one instance.

🔧 Proposed fix
 // $Maintainer: Hannes Roest $
 // $Authors: Hannes Roest, Luis Jacob Keller, Alen Saric$
-// $Authors: Hannes Roest, Luis Jacob Keller, Alen Saric$
 // --------------------------------------------------------------------------
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/tests/class_tests/openms/source/LinearResamplerAlign_test.cpp` around
lines 6 - 7, Remove the duplicated metadata author line by keeping a single
occurrence of the "$Authors: Hannes Roest, Luis Jacob Keller, Alen Saric$" line
in the file; locate the two identical "$Authors" lines (they appear
consecutively) and delete one so only one "$Authors" metadata line remains.

timosachsenberg added a commit to LuBox2K/OpenMS that referenced this pull request Apr 16, 2026
LinearResamplerAlign is a strict superset of LinearResampler (adds
explicit raster alignment, ppm-spaced rasters, chromatogram support
and a linear-interpolation mode). Delete the narrower LinearResampler
class and redirect its callers (Tutorial_SavitzkyGolayFilter,
ImageCreator, DefaultParamHandlerDocumenter, pyOpenMS binding) to
LinearResamplerAlign.

Also add a runtime warning (verifySpacing_) when the configured
spacing is finer than the minimum distance between adjacent input
points, which can produce spurious peaks below the detector dead time.

Co-authored-by: Luis Jacob Keller <[email protected]>
Co-authored-by: Alen Saric <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@timosachsenberg
timosachsenberg force-pushed the delete_LinearResampler branch from 4f6d43c to cef0aa6 Compare April 16, 2026 09:47
LinearResamplerAlign is a strict superset of LinearResampler (adds
explicit raster alignment, ppm-spaced rasters, chromatogram support
and a linear-interpolation mode). Delete the narrower LinearResampler
class and redirect its callers (Tutorial_SavitzkyGolayFilter,
ImageCreator, DefaultParamHandlerDocumenter, pyOpenMS binding) to
LinearResamplerAlign.

Also add a runtime warning (verifySpacing_) when the configured
spacing is finer than the minimum distance between adjacent input
points, which can produce spurious peaks below the detector dead time.

Co-authored-by: Luis Jacob Keller <[email protected]>
Co-authored-by: Alen Saric <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@timosachsenberg
timosachsenberg force-pushed the delete_LinearResampler branch from cef0aa6 to 9b4c16d Compare April 16, 2026 09:52
@timosachsenberg

Copy link
Copy Markdown
Contributor

Force-pushed 9b4c16dbe4 to repair the broken merge and address the new CodeRabbit feedback on top of the clean squash.

Fixed (from the merge breakage)

  • Duplicated class inheritance / constructor / includes / $Authors line / verifySpacing_ call in LinearResamplerAlign.h.
  • Duplicated #include block and duplicate function definition in test000.py / test.
  • raster_interpolate binding that was calling self.raster(...) instead of raster_interpolate(...) → removed (the old binding shape was not correct for that algorithm).
  • The out-of-scope DefaultParamHandlerDocumenter.cpp reformat sneaked back in via the merge — reverted again.

Cherry-picked from d4d9eec07f

  • Stack-alloc ctor/dtor sections in LinearResamplerAlign_test.cpp (CodeRabbit nit).
  • Added raster(MSChromatogram&), raster_align(MSSpectrum&, start, end), raster_align(MSChromatogram&, start, end) pyOpenMS overloads (the only ones that actually compile — raster(MSExperiment&) and raster_align(MSExperiment&) don't, since MSExperiment::begin() yields MSSpectrum which has no getPos(); use rasterExperiment(MSExperiment&) instead).

New review items addressed

  • ppm vs absolute distance bug (CodeRabbit #3092246838): verifySpacing_ early-returns when ppm_=true since the relative ppm value cannot be compared to the absolute neighbour-distance.
  • Missing copy semantics (CodeRabbit #3092153107): added nb::init<const LinearResamplerAlign&>(), __copy__, __deepcopy__ to the binding.

Kept (disagreeing with one bit of feedback)

  • rasterExperiment(MSExperiment&) is restored and bound. @LuBox2K — it's not only used in tests, it's a user-facing pyOpenMS API and the raster(MSExperiment&) replacement can't compile (see above). Happy to remove if you'd rather expose an alternative.

Verified locally

  • OpenMS, LinearResamplerAlign_test, BrukerTimsFile_test, Resampler build; LinearResamplerAlign_test passes.
  • pyopenms builds; pyopenms.LinearResamplerAlign() supports getDefaults, raster(spectrum|chromatogram), raster_align, rasterExperiment, copy.copy, copy.deepcopy.

CI has the workflows in action_required state on every push (external-contributor gate) — you'll need to hit Approve on the Actions tab for each run.

@timosachsenberg

Copy link
Copy Markdown
Contributor

let's see if CI passes now. I will merge if it does. thanks!

@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.

♻️ Duplicate comments (3)
src/openms/include/OpenMS/PROCESSING/RESAMPLING/LinearResamplerAlign.h (1)

395-416: ⚠️ Potential issue | 🟠 Major

Dimensionally invalid comparison when ppm_ mode is enabled.

The comparison spacing_ < min_dist on line 410 compares apples to oranges when ppm_ is true: spacing_ is in parts-per-million while min_dist is computed in absolute m/z units (Th). This will produce misleading warnings or fail to warn when appropriate.

As noted in a previous review, the safest short-term fix is to skip this check in ppm mode. If warnings in ppm mode are desired, convert the configured ppm spacing to an absolute value for comparison.

🔧 Proposed short-term fix
-      if (spacing_ < min_dist)
+      if (!ppm_ && spacing_ < min_dist)
       {
         OPENMS_LOG_WARN << "Resampling spacing (" << spacing_
                         << ") is smaller than the smallest distance between data points ("
                         << min_dist << "). This approximates the detector dead time and may produce spurious peaks.\n";
       }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openms/include/OpenMS/PROCESSING/RESAMPLING/LinearResamplerAlign.h`
around lines 395 - 416, The warning in verifySpacing_ compares spacing_ (ppm
when ppm_ is true) to min_dist (absolute m/z), which is invalid; modify
verifySpacing_ to skip the spacing_ < min_dist check when ppm_ is true (or
alternatively convert spacing_ to absolute m/z before comparing), i.e., add a
guard using the ppm_ flag so the OPENMS_LOG_WARN branch only runs when ppm_ is
false (or compute absolute_spacing from spacing_ and current m/z and compare
absolute_spacing < min_dist) while keeping the rest of the min_dist computation
unchanged.
src/pyOpenMS/bindings/bind_misc.cpp (1)

2646-2653: ⚠️ Potential issue | 🟡 Minor

Restore copy/deepcopy bindings for LinearResamplerAlign.

Line 2652 currently exposes only nb::init<>(); copy constructor plus __copy__/__deepcopy__ are missing for this class.

♻️ Proposed fix
     auto linearresampleralign_class = nb::class_<OpenMS::LinearResamplerAlign, OpenMS::DefaultParamHandler>(m, "LinearResamplerAlign",
         R"doc(
 Linear Resampling of raw data with alignment
 DefaultParamHandler
 ProgressLogger
 )doc")
         .def(nb::init<>())
+        .def(nb::init<const OpenMS::LinearResamplerAlign &>())
+        .def("__copy__", [](const OpenMS::LinearResamplerAlign& self) { return OpenMS::LinearResamplerAlign(self); })
+        .def("__deepcopy__", [](const OpenMS::LinearResamplerAlign& self, nb::dict) { return OpenMS::LinearResamplerAlign(self); }, "memo"_a)
         .def("raster", [](OpenMS::LinearResamplerAlign& self, OpenMS::MSSpectrum& spectrum) { return self.raster(spectrum); }, "spectrum"_a, "Applies the resampling algorithm to an MSSpectrum")
#!/bin/bash
# Verify required copy bindings are present for LinearResamplerAlign
rg -n -C3 'LinearResamplerAlign|nb::init<const OpenMS::LinearResamplerAlign|__copy__|__deepcopy__' src/pyOpenMS/bindings/bind_misc.cpp

As per coding guidelines, "Class bindings must include default constructor nb::init<>(), copy constructor nb::init<const ClassName &>(), __copy__ method, and __deepcopy__ method with memo parameter".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/pyOpenMS/bindings/bind_misc.cpp` around lines 2646 - 2653, The
LinearResamplerAlign binding only exposes nb::init<> but must also provide copy
construction and Python copy semantics; update the linearresampleralign_class
binding for OpenMS::LinearResamplerAlign to add nb::init<const
OpenMS::LinearResamplerAlign &>() and define "__copy__" and "__deepcopy__"
methods that return a copy (use a lambda that constructs
OpenMS::LinearResamplerAlign(self) for __copy__ and __deepcopy__(self, memo)
respectively), keeping the existing "raster" def intact.
src/tests/class_tests/openms/source/LinearResamplerAlign_test.cpp (1)

155-163: ⚠️ Potential issue | 🟠 Major

Strengthen rasterExperiment validation beyond total-intensity conservation.

At Line 155-Line 163, the test only checks summed intensity (20) per spectrum. That can still pass with incorrect peak redistribution. Please assert expected resampled bins (m/z grid + per-bin intensities), especially since this section is new API-level coverage.

Suggested assertion upgrade
-  for (Size s=0; s<exp.size(); ++s)
+  TEST_EQUAL(exp.size(), 2);
+  for (Size s = 0; s < exp.size(); ++s)
   {
-    double sum = 0.0;
-    for (Size i=0; i<exp[s].size(); ++i)
-    {
-      sum += exp[s][i].getIntensity();
-    }
-    TEST_REAL_SIMILAR(sum, 20);
+    TEST_EQUAL(exp[s].size(), 5);
+    TEST_REAL_SIMILAR(exp[s][0].getMZ(), 0.0);
+    TEST_REAL_SIMILAR(exp[s][1].getMZ(), 0.5);
+    TEST_REAL_SIMILAR(exp[s][2].getMZ(), 1.0);
+    TEST_REAL_SIMILAR(exp[s][3].getMZ(), 1.5);
+    TEST_REAL_SIMILAR(exp[s][4].getMZ(), 2.0);
+
+    TEST_REAL_SIMILAR(exp[s][0].getIntensity(), 3.0);
+    TEST_REAL_SIMILAR(exp[s][1].getIntensity(), 6.0);
+    TEST_REAL_SIMILAR(exp[s][2].getIntensity(), 8.0);
+    TEST_REAL_SIMILAR(exp[s][3].getIntensity(), 2.0);
+    TEST_REAL_SIMILAR(exp[s][4].getIntensity(), 1.0);
   }
Based on learnings, "Write unit tests for new functionality and ensure existing tests pass before suggesting changes."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/tests/class_tests/openms/source/LinearResamplerAlign_test.cpp` around
lines 155 - 163, The test currently only asserts total intensity per spectrum
(loop over exp in LinearResamplerAlign_test.cpp), which can mask incorrect peak
redistribution; update the test to validate the resampled m/z grid and per-bin
intensities explicitly by asserting expected spectrum sizes (exp[s].size()),
each bin's m/z (exp[s][i].getMZ()) and each bin's intensity
(exp[s][i].getIntensity()) against the known expected vectors for the
rasterExperiment case; target the loop that iterates over exp and add checks for
exact bin positions and per-bin values (or approximate equality with
TEST_REAL_SIMILAR) so the resampler behavior is fully specified.
🧹 Nitpick comments (1)
src/openms/include/OpenMS/PROCESSING/RESAMPLING/LinearResamplerAlign.h (1)

304-305: Minor style inconsistency: use auto for lambda parameter.

Other verifySpacing_ calls use auto in the lambda parameter (e.g., line 113, 156, 235), but this one explicitly specifies PeakTypeIterator. Consider using auto for consistency.

♻️ Suggested fix
-      verifySpacing_(raw_it, raw_end, [](PeakTypeIterator x){return x->getPos();});
+      verifySpacing_(raw_it, raw_end, [](auto x){return x->getPos();});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openms/include/OpenMS/PROCESSING/RESAMPLING/LinearResamplerAlign.h`
around lines 304 - 305, The call to verifySpacing_(raw_it, raw_end,
[](PeakTypeIterator x){return x->getPos();}); uses an explicit PeakTypeIterator
lambda parameter which is inconsistent with other calls; change the lambda
parameter to auto (i.e., [](auto x){ return x->getPos(); }) so verifySpacing_,
the lambda, raw_it and raw_end use the same style as the other calls for
consistency.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@src/openms/include/OpenMS/PROCESSING/RESAMPLING/LinearResamplerAlign.h`:
- Around line 395-416: The warning in verifySpacing_ compares spacing_ (ppm when
ppm_ is true) to min_dist (absolute m/z), which is invalid; modify
verifySpacing_ to skip the spacing_ < min_dist check when ppm_ is true (or
alternatively convert spacing_ to absolute m/z before comparing), i.e., add a
guard using the ppm_ flag so the OPENMS_LOG_WARN branch only runs when ppm_ is
false (or compute absolute_spacing from spacing_ and current m/z and compare
absolute_spacing < min_dist) while keeping the rest of the min_dist computation
unchanged.

In `@src/pyOpenMS/bindings/bind_misc.cpp`:
- Around line 2646-2653: The LinearResamplerAlign binding only exposes
nb::init<> but must also provide copy construction and Python copy semantics;
update the linearresampleralign_class binding for OpenMS::LinearResamplerAlign
to add nb::init<const OpenMS::LinearResamplerAlign &>() and define "__copy__"
and "__deepcopy__" methods that return a copy (use a lambda that constructs
OpenMS::LinearResamplerAlign(self) for __copy__ and __deepcopy__(self, memo)
respectively), keeping the existing "raster" def intact.

In `@src/tests/class_tests/openms/source/LinearResamplerAlign_test.cpp`:
- Around line 155-163: The test currently only asserts total intensity per
spectrum (loop over exp in LinearResamplerAlign_test.cpp), which can mask
incorrect peak redistribution; update the test to validate the resampled m/z
grid and per-bin intensities explicitly by asserting expected spectrum sizes
(exp[s].size()), each bin's m/z (exp[s][i].getMZ()) and each bin's intensity
(exp[s][i].getIntensity()) against the known expected vectors for the
rasterExperiment case; target the loop that iterates over exp and add checks for
exact bin positions and per-bin values (or approximate equality with
TEST_REAL_SIMILAR) so the resampler behavior is fully specified.

---

Nitpick comments:
In `@src/openms/include/OpenMS/PROCESSING/RESAMPLING/LinearResamplerAlign.h`:
- Around line 304-305: The call to verifySpacing_(raw_it, raw_end,
[](PeakTypeIterator x){return x->getPos();}); uses an explicit PeakTypeIterator
lambda parameter which is inconsistent with other calls; change the lambda
parameter to auto (i.e., [](auto x){ return x->getPos(); }) so verifySpacing_,
the lambda, raw_it and raw_end use the same style as the other calls for
consistency.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9512d468-3c98-4271-9607-621c5d056128

📥 Commits

Reviewing files that changed from the base of the PR and between 4f6d43c and cef0aa6.

📒 Files selected for processing (16)
  • AUTHORS
  • CHANGELOG
  • doc/code_examples/Tutorial_SavitzkyGolayFilter.cpp
  • doc/doxygen/parameters/DefaultParamHandlerDocumenter.cpp
  • src/openms/include/OpenMS/PROCESSING/RESAMPLING/LinearResampler.h
  • src/openms/include/OpenMS/PROCESSING/RESAMPLING/LinearResamplerAlign.h
  • src/openms/include/OpenMS/PROCESSING/RESAMPLING/sources.cmake
  • src/openms/source/PROCESSING/RESAMPLING/LinearResampler.cpp
  • src/openms/source/PROCESSING/RESAMPLING/sources.cmake
  • src/openms_gui/source/VISUAL/APPLICATIONS/GUITOOLS/ImageCreator.cpp
  • src/pyOpenMS/bindings/bind_misc.cpp
  • src/pyOpenMS/tests/unittests/test000.py
  • src/tests/class_tests/openms/executables.cmake
  • src/tests/class_tests/openms/source/LinearResamplerAlign_test.cpp
  • src/tests/class_tests/openms/source/LinearResampler_test.cpp
  • src/topp/Resampler.cpp
💤 Files with no reviewable changes (8)
  • src/tests/class_tests/openms/executables.cmake
  • src/openms_gui/source/VISUAL/APPLICATIONS/GUITOOLS/ImageCreator.cpp
  • doc/doxygen/parameters/DefaultParamHandlerDocumenter.cpp
  • src/openms/source/PROCESSING/RESAMPLING/sources.cmake
  • src/openms/include/OpenMS/PROCESSING/RESAMPLING/sources.cmake
  • src/openms/source/PROCESSING/RESAMPLING/LinearResampler.cpp
  • src/tests/class_tests/openms/source/LinearResampler_test.cpp
  • src/openms/include/OpenMS/PROCESSING/RESAMPLING/LinearResampler.h
✅ Files skipped from review due to trivial changes (4)
  • AUTHORS
  • src/topp/Resampler.cpp
  • doc/code_examples/Tutorial_SavitzkyGolayFilter.cpp
  • CHANGELOG

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants