Skip to content

Added a new peak-finding algorithm, fixed saving of filtered frequenc…#997

Merged
alisanozdrina merged 3 commits intodevelopfrom
channelSinewaveSubtraction_test
Mar 23, 2026
Merged

Added a new peak-finding algorithm, fixed saving of filtered frequenc…#997
alisanozdrina merged 3 commits intodevelopfrom
channelSinewaveSubtraction_test

Conversation

@alisanozdrina
Copy link
Copy Markdown
Collaborator

…ies for diagnostics.

Issue being addressed:

Added an optional peak-selection algorithm to prevent choosing non-CW peaks in the frequency spectrum. New algo is searching for peaks in sliding 100 MHz window instead of the whole spectrum. Tested on Deep CR search dataset burn sample.

Copy link
Copy Markdown
Member

@fschlueter fschlueter left a comment

Choose a reason for hiding this comment

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

Seems like a useful addition! I made some comments in-line.

I also have a general question. I am a bit concerned that with a peak_prominance of 4, we are cutting into the thermal noise distribution (the rayleigh distribution has a long tail). Could you make histograms of the amplitudes in a couple of frequency bins, plotted in log and maybe with a rayleigh curve fitted to it (for the raw and the sine subtracted waveforms)? I think with those plots we can clearly see whether that happens. The other question of course if than if that is bad - maybe it is not but at least we should do it internally

Comment on lines +41 to +43
0.1 to 0.7 GHz is the default for RNO-G, based on bandpass.
removed_freqs: dict (default: None)
Dictionary to store filtered noise frequencies for each channel for diagnostics.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

that is not actually an argument of the function

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

now removed

Comment on lines +54 to +56
Parameters
----------
----------
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

would you mind removing these whitespaces again?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

across the entire file

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

removed trailing whitespaces


Returns
-------
--------
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

wasnt it okay before?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed..

algorithm to search for peaks:
'simple' search for narrow < 10 MHz peaks which > peak_prominence * RMS withing freq band
'sliding' search for narrow < 10 MHz peaks which > peak_prominence * RMS withing 100 MHz sliding window

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  • new line

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed


spec_roi = spec[band_mask]

peak_width_limit = int(10 * 1e-3 / delta_f) #10 MHz
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

you can use 10 * units.MHz instead of 1e-3

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed here and one instance later

spec_roi = spec[band_mask]
freq_roi = freqs[band_mask]
# Compute RMS in a sliding window
window_size = int(50 * 1e-3 / delta_f) #100 MHz
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

comment is wrong, see unit comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed

all_peaks = []
for i in range(len(rms_values)):
start, end = i, i + window_size
local_spectrum = spec_roi[start:end]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can't you use windowed_spectrum here too?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

oh my bad. now fixed

@alisanozdrina
Copy link
Copy Markdown
Collaborator Author

I ran sine sub (with new sliding peak searching algo) on ~85K of nuradiomc simulated thermal noise events. Here is the plot. It doesn't cut the tail much, although some bins look a bit different. not sure why though.
Screenshot 2025-10-08 at 6 19 19 PM

@fschlueter
Copy link
Copy Markdown
Member

Thanks @alisanozdrina those plots are exactly what I head in mind. One question, does the simulation include a realistic bandpass filter, i.e., the channel response?

This is with the new peak finder right? Can you also show the old default/way of finding peaks as reference?

I would also love to see it on data but I understand if that is to much asked right now.

@fschlueter fschlueter added NuRadioReco NuRadioReco related changes New Feature Changes implementing a new feature/functionality labels Oct 21, 2025
@fschlueter
Copy link
Copy Markdown
Member

For context #885

@alisanozdrina
Copy link
Copy Markdown
Collaborator Author

Hi @fschlueter, I used NuRadioReco.utilities.noise.thermalNoiseGeneratorPhasedArray class to generate noise. It has bandpass filter NuRadioReco.modules.channelBandPassFilter.channelBandPassFilter(). Here are plots for different peak prominencies, and two algos: sliding and simple.

Overall, both look good for prominence >= 4; If I set lower prominencies it start cutting the tail and sliding works slightly better. I think it is safe to merge into develop, I'll work on your comments. I didn't have time to run it of forced triggers. If you want test on forced triggers, I would prob do it after new release.

event2_ch0_ftsliding_4 spectral_amplitudesimple_3_150MHz_histogram_rayleigh_fit spectral_amplitudesliding_3_150MHz_histogram_rayleigh_fit spectral_amplitudesimple_3 5_150MHz_histogram_rayleigh_fit spectral_amplitudesliding_3 5_150MHz_histogram_rayleigh_fit spectral_amplitudesimple_4_150MHz_histogram_rayleigh_fit spectral_amplitudesliding_4_150MHz_histogram_rayleigh_fit

@sjoerd-bouma sjoerd-bouma marked this pull request as draft January 13, 2026 14:18
@sjoerd-bouma
Copy link
Copy Markdown
Collaborator

@alisanozdrina I've marked this PR as draft for now, once you've addressed Felix' comments you can mark it as "Ready for review" again and/or ping me.

@fschlueter
Copy link
Copy Markdown
Member

Would be great if we can merge this soon!

@alisanozdrina let me elaborate on what I meant with that:

Thanks @alisanozdrina those plots are exactly what I head in mind. One question, does the simulation include a realistic bandpass filter, i.e., the channel response?

My understanding is that in the simple algorithm you are using a the mean (or median) over a certain frequency range to calculate the threshold for subtracting a sine wave (taking as thresholds a multiple peak_prominance of this mean/median). When you simulate flat noise (with a constant vrms per frequency) and do not apply a realistic gain pattern / channel response (that is what I meant with bandpass filter - an analtic bandpass filter is still mostly with values being either 1 or 0), the mean/median is a good estimator. However, when you have a realistic response filter which e.g., has a higher gain at lower frequencies and a lower gain at higher frequencies, taking the mean over all frequencies gives a effectively a lower threshold to lower frequencies. I agree that with a sliding window this issue is mostly resolved! Hence I am happy to merge it as it but maybe resolve my minor comments? @CamphynR might be able to provide the corresponding plots from data.

@alisanozdrina alisanozdrina force-pushed the channelSinewaveSubtraction_test branch from 0777c55 to 2ecfb03 Compare March 2, 2026 22:56
@alisanozdrina
Copy link
Copy Markdown
Collaborator Author

@fschlueter I believe I addressed the comments above. let me know if that's not the case.

I agree that with a sliding window this issue is mostly resolved! Hence I am happy to merge it as it but maybe resolve my minor comments?

Sorry, Do I take it as a green light to merge? Or we still want validation with realistic gain pattern / channel response.

@fschlueter
Copy link
Copy Markdown
Member

@CamphynR do you think you have the plots in a timely manner? Otherwise I would suggest to merge it asap.

@CamphynR
Copy link
Copy Markdown
Collaborator

CamphynR commented Mar 3, 2026

Seeing as the Brussel cluster's storage is completely down at the moment I wouldn't count on it. Merging is ok for me

@CamphynR
Copy link
Copy Markdown
Collaborator

CamphynR commented Mar 3, 2026

Give me until this evening hopefully it is resolved by then

@CamphynR
Copy link
Copy Markdown
Collaborator

CamphynR commented Mar 3, 2026

I ran with the same settings as Alisa for a limited set of 3 runs of channel 0, station 11, season 2023. These are the results. I might have time later to run it for more forced trigger data but to me these plots do not give a reason to not merge this. The sliding algorithm even brings the distribution closer to a Rayleigh but not sure how relevant that is.

simple_4 simple_3 sliding_4 sliding_3

@fschlueter
Copy link
Copy Markdown
Member

@CamphynR, thanks for doing that! yes if it does not take much of your time please run with more data. We try to see whether the tail of the distribution is affected - so more statistics is necessary

@fschlueter fschlueter marked this pull request as ready for review March 4, 2026 07:57
@CamphynR
Copy link
Copy Markdown
Collaborator

CamphynR commented Mar 23, 2026

Sorry for the delay, these contain a lot more data. You see that only the simple algorithm with peak_promince=3 cuts into the tail (ignore the before in the subtitle that's a typo)
simple_4
simple_3
sliding_4
sliding_3

Copy link
Copy Markdown
Member

@fschlueter fschlueter left a comment

Choose a reason for hiding this comment

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

@alisanozdrina and @CamphynR I changed the default method to sliding. Thank you for all your work on this!

@alisanozdrina alisanozdrina merged commit 1448656 into develop Mar 23, 2026
11 checks passed
@alisanozdrina alisanozdrina deleted the channelSinewaveSubtraction_test branch March 23, 2026 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

New Feature Changes implementing a new feature/functionality NuRadioReco NuRadioReco related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants