Incorrectly reconstructed Fourier frequency array

Open
#856 5 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

Nobody has claimed this yet.

  • #881 by @Sauravroy34 — closed without merging

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
data

Research direction

Trace VarEnergyspectrum through avg_pds_from_timeseries and _get_good_frequency_bins, comparing their use of fftfreq and the two bin-count calculations. Reproduce the seg_size=5 and time_res=0.03 example, then verify that both paths produce compatible frequency arrays and that frequency masking no longer fails.

Written by the indexing model from the issue text.

Description

bug help wanted
Description of the Bug

We typically have two ways to construct arrays of Fourier frequency. One is to take the size of a segment to calculate the number of bins (e.g. flux.size), another is to calculate the number of bins in a segment of given size with numpy.rint by hand. The bug is these two methods round non-integers differently, and as a result the two arrays are not necessarily the same.

Steps/Code to Replicate the Bug

seg_size = 5
time_res = 0.03
freq_int = fftfreq(int(seg_size/time_res),time_res)
freq_rint = ftfreq(int(np.rint(seg_size/time_res))),time_res)

Expected Results

These two should be the same the parts of the code that use either method to be consistent.

Actual Results

int(5/0.03) = 166 and np.rint(5/0.03) = 167.

The result is that parts of the code that call the two methods, one can get an error due to the array masking not working correctly. For example, VarEnergyspectrum uses the first method in the initialization when calling avg_pds_from_timeseries, and the second in _get_good_frequency_bins().

Dominant language
Python
Stars
229
Forks
196
Avg merge
4d 12h
Merged PRs (30d)
20

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from StingraySoftware/stingray

All issues in StingraySoftware/stingray

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.