Skip to content

Conversation

@yashbhargava1992
Copy link
Contributor

Relevant Issue(s)/PR(s)

Fixes #945 and #942

Provide an overview of the implemented solution or the fix and elaborate on the modifications.

Updated the method used in minimize function to Nelder-Mead to ensure convergence in test cases.
Added a flag to switch between summed and average power for determining upper limit in different cases.

Changed the minimising method  called in scipy.optimize.minimize to "Nelder-Mead"
Additionally, updated the bounds to exclude 0 from the non-central chi2 distribution.

Included a flag in the function to potentially solve issue StingraySoftware#942
from black stingray
@yashbhargava1992 yashbhargava1992 marked this pull request as ready for review October 2, 2025 15:37
@matteobachetti
Copy link
Member

@yashbhargava1992 Please discard all changes that are not strictly related to this PR, or it will break all other open PRs 😅

Copy link
Member

@matteobachetti matteobachetti left a comment

Choose a reason for hiding this comment

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

Hi @yashbhargava1992 , good job, almost done! Please add a new test in test_stats.py to verify that this is working as expected. Also, please check that other functions calling this one are using the correct keyword (e.g. amplitude upper limit)

@matteobachetti
Copy link
Member

@yashbhargava1992 please also update your branch, I fixed one of the issues with testing

@yashbhargava1992
Copy link
Contributor Author

@yashbhargava1992 please also update your branch, I fixed one of the issues with testing

Do I pull from the upstream main?

@matteobachetti
Copy link
Member

Do I pull from the upstream main?

Yes, rebase would be better but pull is ok too

@codecov
Copy link

codecov bot commented Oct 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.96%. Comparing base (6a28a86) to head (f6f7fea).

❗ There is a different number of reports uploaded between BASE (6a28a86) and HEAD (f6f7fea). Click for more details.

HEAD has 12 uploads less than BASE
Flag BASE (6a28a86) HEAD (f6f7fea)
16 4
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #946       +/-   ##
===========================================
- Coverage   96.06%   79.96%   -16.10%     
===========================================
  Files          48       48               
  Lines        9890     9895        +5     
===========================================
- Hits         9501     7913     -1588     
- Misses        389     1982     +1593     

☔ View full report in Codecov by Sentry.
📢 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.

Copy link
Member

@matteobachetti matteobachetti left a comment

Choose a reason for hiding this comment

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

Thanks @yashbhargava1992 ! A couple remaining nitpicks

power in a QPO, the n in Z^2_n or the number of averaged PDS
c: float
The confidence value for the probability (e.g. 0.95 = 95%)
summed_flag: bool
Copy link
Member

Choose a reason for hiding this comment

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

I think we should be explicit in examples here, stating that, typically, Z^2_n will have summed_flag=True and powers will have summed_flag=False

Ratio of the frequency of this feature with respect to the Nyquist
frequency. Important to know when dealing with FFTs, because the FFT
response decays between 0 and f_Nyq similarly to the response inside
a frequency bin: from 1 at 0 Hz to ~2/pi at f_Nyq
Copy link
Member

Choose a reason for hiding this comment

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

The new flag should also be documented here

assert np.isclose(power_upper_limit(40, 1, 0.99), 75, rtol=0.1)

def test_power_upper_limit_averaging(self):
assert np.isclose(power_upper_limit(100, 10, 0.997, summed_flag=False), 115, rtol=0.1)
Copy link
Member

Choose a reason for hiding this comment

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

There should be a new line after the function

def test_power_upper_limit(self):
# Use example from Vaughan+94
assert np.isclose(power_upper_limit(40, 1, 0.99), 75, rtol=0.1)

Copy link
Member

Choose a reason for hiding this comment

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

Please add a test also for amplitude_upper_limit

@matteobachetti matteobachetti added this pull request to the merge queue Oct 25, 2025
Merged via the queue into StingraySoftware:main with commit 991e488 Oct 25, 2025
14 of 15 checks passed
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.

Convergence failure of minimize function in power upper limit

2 participants