Skip to content

fix: xNoiseSanPlot refined negative noise read from wrong array - #386

Merged
jobo322 merged 5 commits into
mainfrom
fix-noise-san-plot
Jul 17, 2026
Merged

fix: xNoiseSanPlot refined negative noise read from wrong array#386
jobo322 merged 5 commits into
mainfrom
fix-noise-san-plot

Conversation

@lpatiny

@lpatiny lpatiny commented Jul 9, 2026

Copy link
Copy Markdown
Member

Bug

In the refine branch of xNoiseSanPlot, the refined negative noise level was read from cloneSignPositive (the positive signal) while indexing with cloneSignNegative.length — a copy-paste error from the positive branch just above. With refine: true (the default), the reported negative level did not reflect the negative signal at all.

The fix reads from cloneSignNegative and negates it, mirroring the initial negative-noise formula (-1 * signNegative[...]). Added a regression assertion: the refined negative level is now positive and of the same order as the positive one.

All 2230 tests pass.

For your review, @jobo322 — a second, separate issue I did not touch

determineCutOff accumulates averageValue as a plain sum and then uses it as a mean in (element[1] - averageValue)², so kiSqrt isn't the intended dispersion measure and the chosen cut-off is likely skewed. Dividing averageValue by elementsOfCutOff.length looks correct, but it changes the magnitude-mode SNR on the test spectrum from ~40.2 to ~63.5 — a real behavioral change to the published-method output. I left it as-is since that needs your domain judgment on what the reference value should be. Happy to open a follow-up if you confirm the intended behavior.

The refined negative noise level was indexed out of cloneSignPositive
(the positive signal) using the negative clone's length, a copy-paste
error. It now reads from cloneSignNegative and negates it, matching the
initial negative-noise formula, so with refine enabled the reported
negative level reflects the negative signal.
@lpatiny
lpatiny requested a review from jobo322 July 9, 2026 05:38
@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.63014% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 97.13%. Comparing base (9fed281) to head (6ac3757).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/x/xNoiseSanPlot.ts 98.55% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #386   +/-   ##
=======================================
  Coverage   97.13%   97.13%           
=======================================
  Files         207      209    +2     
  Lines        4147     4159   +12     
  Branches     1036     1037    +1     
=======================================
+ Hits         4028     4040   +12     
  Misses        115      115           
  Partials        4        4           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/x/xNoiseSanPlot.ts Outdated
@jobo322

jobo322 commented Jul 10, 2026

Copy link
Copy Markdown
Member

Correct sign handling for negative noise in xNoiseSanPlot and uses cutoff for negative using negative data

Experiment Refactored Current state
DEPT dept-using-negative dept-current
1H 1H-using-negative 1H-current

@jobo322

jobo322 commented Jul 10, 2026

Copy link
Copy Markdown
Member

@lpatiny could you have a look, I propose use negative data to find the negative noise level

@jobo322

jobo322 commented Jul 14, 2026

Copy link
Copy Markdown
Member

It is true than there is a bug in the determineCutOff function with the missing division for the number of elements in the window, but I would like to keep it out of this PR, to open a new one that would refactor the xFindClosestIndex to accept descending order arrays. @lpatiny what do you think?

@jobo322

jobo322 commented Jul 15, 2026

Copy link
Copy Markdown
Member

In the case of ibuprofen, the result of the strange sanplot line is due to NUS processing, where most of the points are zero, so there is not a real distribution of noise. When I deactivate the NUS reconstruction we got the expected sanplot line

image

with NUS activated the number of positive points are 9631 and negative 2144. it make sense because NUS by IST take only the signal points.

image

@jobo322

jobo322 commented Jul 15, 2026

Copy link
Copy Markdown
Member
image

@jobo322

jobo322 commented Jul 15, 2026

Copy link
Copy Markdown
Member
image

The value of negative noise is bigger in absolute value. Is not particularly symmetric, I try to fix the baseline and the phase of the spectrum

@jobo322

jobo322 commented Jul 17, 2026

Copy link
Copy Markdown
Member

by trying to calculate the noise level with positive a negative at the same time with the current implementation, by taking the absolute value of negative data, the noise level looks strange

The noise looks reduced (in the wrong place)

it is the same spectrum but separating the negative and positive series

Experiment All in one Separated series
Dept image image

comparing with the exampled of sanplot paper
image>

Not sure if Is it needed to make a further refactor to the determination of the cutOff

@jobo322
jobo322 merged commit 9ae3772 into main Jul 17, 2026
10 checks passed
@jobo322
jobo322 deleted the fix-noise-san-plot branch July 17, 2026 20:49
This was referenced Jul 17, 2026
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.

2 participants