Skip to content

feat: Implementing frequency rebinning for PowerSpectrum and LightCurve#71

Open
Omiii-215 wants to merge 141 commits intoStingraySoftware:unstablefrom
Omiii-215:feat/freq-rebinning
Open

feat: Implementing frequency rebinning for PowerSpectrum and LightCurve#71
Omiii-215 wants to merge 141 commits intoStingraySoftware:unstablefrom
Omiii-215:feat/freq-rebinning

Conversation

@Omiii-215
Copy link
Copy Markdown

Summary

Adds frequency rebinning support for power spectra.

What’s included

  • Linear rebinning via rebin(ps, factor)
  • Logarithmic rebinning via logrebin(ps, f)
  • Integer-factor rebin overload for LightCurve
  • Tests for linear/log rebinning and error scaling

Notes

  • Keeps implementation minimal and focused on core functionality.
  • Designed to be extendable for future improvements.

matteobachetti and others added 30 commits March 14, 2022 10:16
It seems entirely overkill to run on 3 different operating systems and
for two different Julia versions for a package that is still in heavy
development. Currently we just need the CI to be rapid and automate code
checking. There is nothing in this package that is specific to a given
OS, and we can worry about compat with Julia versions once we approach a
first stable version.
@Omiii-215 Omiii-215 marked this pull request as draft February 15, 2026 21:40
- Restore GTI filtering in
- Harden
- Rename  to
- Update docstrings and plotting recipes
- Verify rebinning logic with tests
@Omiii-215 Omiii-215 marked this pull request as ready for review February 16, 2026 09:56
Copy link
Copy Markdown
Member

@kashish2210 kashish2210 left a comment

Choose a reason for hiding this comment

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

Hey @Omiii-215, thanks for ur sub PR you have really done a great work {u can once review my comments. specially this one try testing via some datas} :)

Comment thread docs/Project.toml
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Stingray = "2045e982-6adb-4e09-8364-0d2cc8a3fe4f"

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.

While running the project, we can't include Stingray in the project.toml {this is the document config}
So I know what happened here, you may tried to make docs you can just use

using Stingray
Stingray.someFuncunction()

avoid this scope

for (band_name, events) in events_dict
ps = AveragedPowerspectrum(events, segment_size; norm = norm)
ps = AveragedPowerSpectrum(events, segment_size; norm = norm)
power_vec = freq_mult ? ps.power .* ps.freq : ps.power
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.

Thanks for noticing this :)

Comment thread src/lightcurve.jl Outdated
counts::Vector{Int},
method::Symbol;
gaussian_errors::Union{Nothing,Vector{<:Real}} = nothing,
gaussian_errors::Union{Nothing,Vector{<:Real}} = nothing
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 thread src/lightcurve.jl
# Throws
- `ArgumentError`: If custom errors length doesn't match bin count
"""
function set_errors!(lc::LightCurve{T}) where {T}
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 revert to

function set_errors!(lc::LightCurve{T}) where {T}

since"Curly braces become necessary when you have multiple type parameters." Otherwise, it is the same

Comment thread src/lightcurve.jl Outdated
- [`set_errors!`](@ref): Set error method and calculate errors
"""
function calculate_errors!(lc::LightCurve{T}) where {T}
function calculate_errors!(lc::LightCurve{T}) where T
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.

same here for {T}

Comment thread src/lightcurve.jl Outdated
merge!(extra_metadata, eventlist.meta.extra)
if !isnothing(eventlist.meta.gti)
extra_metadata["gti"] = eventlist.meta.gti
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.

This may hinder review it once since merging the gtis is crucial

Comment thread src/lightcurve.jl Outdated
throw(ArgumentError("No events remain after GTI filtering"))
end
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.

i didnt get what the use of this?

Comment thread src/powerspectrum.jl Outdated
new_powers,
new_errs,
ps.norm,
0.0, # df is variable
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.

beware of df

Comment thread test/test_rebinning.jl
using Test
using Stingray
using Statistics

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.

u can include these files in the runtest.jl {it is already there}

Comment thread src/powerspectrum.jl
ps.metadata
)
end
end
Copy link
Copy Markdown
Member

@kashish2210 kashish2210 Feb 17, 2026

Choose a reason for hiding this comment

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

You need to test these new functions via data present here
Use clean data "ni1200120104_0mpu7_cl.evt" from "ni1200120104_0mpu7_cl.evt.gz" so u can run the test easily via setting up a Jupyter notebook and include powespectrum and plotting.jl and lightcurve and event.jl files in ur dirs and start testing, use your function via first using readevents function u may refer to:

Image

and start making Plots : )

- LightCurve: Restore apply_filters, safe metadata merge, correct GTI logic
- PowerSpectrum: Fix logrebin df calculation to avoid 0.0
- Docs: Fix Pkg.develop pattern and deps in docs/make.jl
- Tests: Add robust invariant checks to test_rebinning.jl
@Omiii-215
Copy link
Copy Markdown
Author

Omiii-215 commented Feb 18, 2026

@kashish2210 Verification with Real Data:

I have verified these changes locally using a clean event file (ni1200120104_0mpu7_cl.evt). The apply_filters, rebin (linear), and logrebin (logarithmic) functions were tested.

LightCurve Rebinning: Validated that total counts are preserved exactly (sum(lc_binned.counts) == sum(lc.counts)).
PowerSpectrum Log Rebinning: Confirmed that logrebin now produces a positive effective df (fixing the df=0.0 issue) and strictly monotonic frequencies.
Plots: Visually inspected the rebinned light curves and power spectra to ensure they match the expected behavior of the original data.

Screenshot 2026-02-18 at 9 48 20 PM Screenshot 2026-02-18 at 9 48 10 PM Screenshot 2026-02-18 at 9 47 57 PM Screenshot 2026-02-18 at 9 47 20 PM Screenshot 2026-02-18 at 9 44 54 PM
Loading events from ni1200120104_0mpu7_cl.evt...
Event file loaded successfully.
  Telescope: NICER
  Instrument: XTI
  Object: MAXI_J1820+070
  Events: 21244574

--- Testing LightCurve Rebinning ---
Original LC: 731950 bins, dt=0.1 s
Rebinned LC: 73195 bins, dt=1.0 s
Total Counts Check: Original=21244574, Rebinned=21244574
SUCCESS: Total counts preserved.

--- Testing PowerSpectrum Linear Rebinning ---
Original PDS: 365974 bins, df=1.3662135391761732e-5 Hz
Linearly Rebinned PDS: 91493 bins, df=5.464854156704693e-5 Hz

--- Testing PowerSpectrum Logarithmic Rebinning ---
Log Rebinned PDS: 127 bins
  Effective df: 0.0012056834483229716 Hz (should not be 0.0)
SUCCESS: Effective df is positive.
Monotonicity Check: Passed

Verification complete. Plots saved as PNG files.

@kashish2210
Copy link
Copy Markdown
Member

@kashish2210 Verification with Real Data:

I have verified these changes locally using a clean event file (ni1200120104_0mpu7_cl.evt). The apply_filters, rebin (linear), and logrebin (logarithmic) functions were tested.

LightCurve Rebinning: Validated that total counts are preserved exactly (sum(lc_binned.counts) == sum(lc.counts)).
PowerSpectrum Log Rebinning: Confirmed that logrebin now produces a positive effective df (fixing the df=0.0 issue) and strictly monotonic frequencies.
Plots: Visually inspected the rebinned light curves and power spectra to ensure they match the expected behavior of the original data.

Screenshot 2026-02-18 at 9 48 20 PM Screenshot 2026-02-18 at 9 48 10 PM Screenshot 2026-02-18 at 9 47 57 PM Screenshot 2026-02-18 at 9 47 20 PM Screenshot 2026-02-18 at 9 44 54 PM
Loading events from ni1200120104_0mpu7_cl.evt...
Event file loaded successfully.
  Telescope: NICER
  Instrument: XTI
  Object: MAXI_J1820+070
  Events: 21244574

--- Testing LightCurve Rebinning ---
Original LC: 731950 bins, dt=0.1 s
Rebinned LC: 73195 bins, dt=1.0 s
Total Counts Check: Original=21244574, Rebinned=21244574
SUCCESS: Total counts preserved.

--- Testing PowerSpectrum Linear Rebinning ---
Original PDS: 365974 bins, df=1.3662135391761732e-5 Hz
Linearly Rebinned PDS: 91493 bins, df=5.464854156704693e-5 Hz

--- Testing PowerSpectrum Logarithmic Rebinning ---
Log Rebinned PDS: 127 bins
  Effective df: 0.0012056834483229716 Hz (should not be 0.0)
SUCCESS: Effective df is positive.
Monotonicity Check: Passed

Verification complete. Plots saved as PNG files.

This looks good to me nice work @Omiii-215

@kashish2210
Copy link
Copy Markdown
Member

Just one more thing we should not focus on docs since, for this scope it is not needed so u can revert changes in that

@Omiii-215
Copy link
Copy Markdown
Author

Just one more thing we should not focus on docs since, for this scope it is not needed so u can revert changes in that

Done

Copy link
Copy Markdown
Member

@kashish2210 kashish2210 left a comment

Choose a reason for hiding this comment

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

Thank you @Omiii-215

@kashish2210
Copy link
Copy Markdown
Member

@matteobachetti and @fjebaker, we can start testing this branch, waiting for your review

@matteobachetti
Copy link
Copy Markdown
Member

@Omiii-215 in the current state, the PR is full of formatting changes that really make review difficult. Also, it seems that you removed at least one function. Please clean up the PR, only maintain the actual important changes.

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.70093% with 26 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (unstable@5d2763d). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/powerspectrum.jl 73.07% 21 Missing ⚠️
src/plotting/plots_recipes_powerspectrum.jl 0.00% 3 Missing ⚠️
src/lightcurve.jl 92.30% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             unstable      #71   +/-   ##
===========================================
  Coverage            ?   66.97%           
===========================================
  Files               ?       12           
  Lines               ?     3770           
  Branches            ?        0           
===========================================
  Hits                ?     2525           
  Misses              ?     1245           
  Partials            ?        0           

☔ 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.

@Omiii-215
Copy link
Copy Markdown
Author

@matteobachetti I've completely cleaned up the PR, reverted all unrelated formatting/naming changes (like PowerSpectrum) and restored the accidentally removed functions. The branch now only cleanly introduces the new rebin and logrebin implementations, and all tests are passing. :)

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.

7 participants