fix: correct fftfreq sampling rate and histogram bin edges#80
fix: correct fftfreq sampling rate and histogram bin edges#80Omiii-215 wants to merge 2 commits into
Conversation
Fix two bugs in the fourier module: 1. fftfreq(n_bin, dt) → fftfreq(n_bin, 1/dt): Julia's FFTW.fftfreq expects the sampling rate (1/dt), not the sample spacing (dt). The Python convention (numpy.fft.fftfreq) is the opposite, which caused incorrect frequency arrays when porting. 2. fit(Histogram, ...; nbins=n_bin) → fit(Histogram, ..., edges): Using nbins does not guarantee bin edges align with segment boundaries. Explicit edges via range(0, stop=e-s, length=n_bin+1) ensure deterministic, gap-free binning of unbinned event data.
|
This looks great! Could you add a test that checks the output of these two things, so that if they were ever regressed the tests fail. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #80 +/- ##
==========================================
+ Coverage 88.06% 88.08% +0.02%
==========================================
Files 5 5
Lines 1081 1083 +2
==========================================
+ Hits 952 954 +2
Misses 129 129 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Committed the tests @fjebaker 👍🏻 |
| @testset "test_fftfreq_uses_sampling_rate" begin | ||
| n = 100 | ||
| dt = 0.5 | ||
| freq = fftfreq(n, 1/dt) |
There was a problem hiding this comment.
Okay, but this test is not testing the Stingray.jl code, only the FFTW library. We could undo your fix commit and this test would still pass. Make sure you're testing the Stringray.jl library and not one of the dependencies (~;
There was a problem hiding this comment.
Thank you! Will be Doing that !
|
Now both tests properly exercise Stingray.jl code
|
f260402 to
36efe9c
Compare
Fix two bugs in the fourier module:
fftfreq(n_bin, dt) → fftfreq(n_bin, 1/dt): Julia's FFTW.fftfreq expects the sampling rate (1/dt), not the sample spacing (dt). The Python convention (numpy.fft.fftfreq) is the opposite, which caused incorrect frequency arrays when porting.
fit(Histogram, ...; nbins=n_bin) → fit(Histogram, ..., edges): Using nbins does not guarantee bin edges align with segment boundaries. Explicit edges via range(0, stop=e-s, length=n_bin+1) ensure deterministic, gap-free binning of unbinned event data.