Skip to content

Conversation

kashish2210
Copy link
Member

In this PR, I have updated the specra function to match our event list and light curve ones

so now we can do :

events = readevents("ni1200120104_0mpu7_cl.evt", load_gti=true, sort=true)
lc = create_lightcurve(events, 0.01)
# Calculate PDS from events with 100-second segments
segment_size = 100.0  # seconds
dt = 0.01  # time resolution
pds_result = avg_pds_from_eventlist(events, segment_size, dt; 
                                   norm="frac", 
                                   use_common_mean=true, 
                                   silent=false)

Output:
image

pds_result = avg_pds_from_lightcurve(lc, 100.0;  # 100-second segments
                                    norm="frac", 
                                    use_common_mean=true, 
                                    silent=false)

output
image

events2 = readevents("xmm_test.fits", load_gti=true, sort=true)
cs_result = avg_cs_from_eventlists(events, events2, segment_size, dt;
                                  norm="frac",
                                  use_common_mean=true,
                                  power_type="all")
lc2 = create_lightcurve(events2, 0.01)
cs_result = avg_cs_from_lightcurves(lc, lc2, 100.0;
                                   norm="frac",
                                   use_common_mean=true,
                                   power_type="all")

Output:
image

# some plotting examples, later I will put this in recipes
plot(pds_result.freq[subsample], pds_result.power[subsample],
      xscale=:log10, yscale=:log10,
      xlabel="Frequency (Hz)", ylabel="Power",
      title="Full PDS (Log-Log)", linewidth=1,
      label="PDS")
plot(histogram(log10.(pds_result.power), bins=100,
                      xlabel="log10(Power)", ylabel="Count",
                      title="Power Distribution", alpha=0.7,
                      label="Power Hist"))

Outputs:
image

image

For a complete analysis, you may visit this notebook

tagging @matteobachetti @fjebaker @stefanocovino for reviews

@kashish2210
Copy link
Member Author

#33

@codecov-commenter
Copy link

codecov-commenter commented Jul 28, 2025

Codecov Report

❌ Patch coverage is 82.97872% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.92%. Comparing base (98935ce) to head (2902dee).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/fourier.jl 82.97% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #58      +/-   ##
==========================================
- Coverage   89.26%   88.92%   -0.35%     
==========================================
  Files           5        5              
  Lines        1025     1065      +40     
==========================================
+ Hits          915      947      +32     
- Misses        110      118       +8     

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

At the very least, there should be a test for every new function.

I suggest a test that verifies that the new spectra function from event lists give the exact same result as the corresponding functions that get the times instead.

In practice we should get something like
spectrum_fun(events) .== spectrum_fun(events.time)

end

# Original functions (kept for backward compatibility)
function avg_pds_from_events(times::AbstractVector{<:Real}, gti::AbstractMatrix{<:Real},
Copy link
Member Author

Choose a reason for hiding this comment

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

this functions

@kashish2210
Copy link
Member Author

I have added test cases @matteobachetti :)
I upgraded the format to make it simpler and compatible with Julia, as I have seen this type of format in @fjebaker repo
One more thing, I want to ask, I have kept these previous functions, shall I remove or just keep them? I thought it may help in vector time

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.

3 participants