RECIPES RECIPES WHAT KIND OF RECIPES? :)

 

Exploring Light Curve Plotting in Stingray.jl: Recipes and Examples:

In my continued work with Stingray.jl, so hello everyone, let's learns about plotting my favorite topic:)

Light curves are essential in high-energy astrophysics, as they represent the brightness of an astronomical object as a function of time. Precise visualization and filtering of these curves help astronomers perform accurate timing analysis, detect variability, and identify astrophysical phenomena.

This post demonstrates how to generate and customize light curve plots using Stingray.jl, leveraging real NICER datasets.


Dataset and Setup:

For this demonstration, I used a dataset from NICER-HESRAC-CL.EVT. The first step is to load the event data into an EventList object:

julia
using Plots events = readevents("ni1200120104_0mpu7_cl.evt", load_gti=true, sort=true)

Output:

pgsql
Found GTI data: 16 intervals GTI time range: 1.3253976595089495e8 to 1.3261337476368216e8 EventList with 21244574 times and energies

Basic Light Curve Plotting

The simplest way to visualize the event list is:

julia
plot(events)

Output:



Energy Filtering

To restrict the light curve to specific energy ranges, use energy_filter:

julia
plot(events, energy_filter=(0, 5e3))

Output:



Time Range Filtering

For a specific time interval, provide tstart and tstop:

julia
plot(events, tstart=1.32540e8, tstop=1.32546e8)

Output:



Axis Limits and GTI/BTI Visualization

You can highlight Good Time Intervals (GTIs) and Bad Time Intervals (BTIs):

julia
plot(events, 5, axis_limits=[1.32540e8, 1.32546e8, 5e3, 2e4], show_gtis=true, show_btis=true)

Adjust transparency with gti_alpha and bti_alpha:

julia
plot(events, show_btis=true, bti_alpha=0.4, show_gtis=true, gti_alpha=0.3)

Output:




You can also plot using a custom GTI matrix or file:

julia
gti1 = [1.32540e8 1.32580e8] plot(events, gtis=gti1, show_gtis=true, gap_threshold=100) # Or use a GTI file: # plot(events, gti_file="gti.fits", show_gtis=true)

Output:



Rebinning Light Curves

Rebinning improves visualization and helps in reducing noise:

julia
eventlist = readevents("ni1200120104_0mpu7_cl.evt") lc = create_lightcurve(eventlist, 800) plot(lc, 1000, show_original=true, original_alpha=1)

Output:



Adding Poisson Errors

julia
lc = create_lightcurve(events, 10) plot(lc, show_errors=true)

Output:

Now with monal_testA :





Gaussian Confidence Bands:[this one is just for testing, like what we can do next, I will work on bayesian_block]

(hehe, u got next blog hint)

For smoother visualization with statistical confidence intervals:[focus "smoothed_counts" a small function to smoothing the lightcurve:)]

julia
using StatsBase lc = create_lightcurve(events, 1) lc_times = lc.time lc_counts = lc.counts # Apply smoothing (moving average) window_size = 1000 smoothed_counts = [mean(lc_counts[max(1, i-window_size):min(end, i+window_size)]) for i in 1:length(lc_counts)] # Compute confidence intervals σ = sqrt.(max.(smoothed_counts, 1)) upper_1σ = smoothed_counts .+ σ lower_1σ = smoothed_counts .- σ upper_2σ = smoothed_counts .+ 2 .* σ lower_2σ = smoothed_counts .- 2 .* σ upper_3σ = smoothed_counts .+ 3 .* σ lower_3σ = smoothed_counts .- 3 .* σ # Plot with confidence bands p = plot(lc_times, smoothed_counts, seriestype=:line, linewidth=2, color=:blue, label="Data", xlabel="Time (s)", ylabel="Counts", title="Gaussian Confidence Bands") plot!(lc_times, [upper_3σ lower_3σ], fillrange=[lower_3σ upper_3σ], fillalpha=0.2, fillcolor=:gray, label="3σ") plot!(lc_times, [upper_2σ lower_2σ], fillrange=[lower_2σ upper_2σ], fillalpha=0.3, fillcolor=:orange, label="2σ") plot!(lc_times, [upper_1σ lower_1σ], fillrange=[lower_1σ upper_1σ], fillalpha=0.4, fillcolor=:lightblue, label="1σ") display(p)

Output:


Segmenting Light Curves

For dividing data into segments:

julia
segments = create_segments(events, 10000.0)
plot(segments, show_errors=false, show_segment_boundaries=true, segment_colors=[:blue, :red, :green, :orange, :purple])

Output:





GitHub Reference

For detailed code and implementation, check out my PR:
GitHub PR #54 – Stingray.jl


These plotting recipes make it easier to visualize event lists and light curves with GTIs, BTIs, and advanced error handling in Stingray.jl. They serve as a foundation for advanced timing analysis techniques, such as power spectral density, periodograms, and others.

Stay tuned for my next post:) find hint for my next post ::}

Comments

Popular posts from this blog

Beginning of GSoC 2025

Black Holes: Nature's Most Mysterious Phenomena

🌟 Things Are Getting Interesting!!