Skip to content

Conversation

kashish2210
Copy link
Member

lightcurve :: recpies

So here I have used the datasets from_here [NICER-HESRAC-CL.EVT] .

USING PLOTS [PLOTING EXAMPLES FOR LIGHTCURVE]

using Plots
events = readevents("ni1200120104_0mpu7_cl.evt", load_gti=true, sort=true) #here load_gti will be default true

output

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

simple plot

plot(events)

output
image

Light curve with energy filtering

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

output
image

Light curve with time range filtering

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

output
image

lightcurve with axis limits and show_gtis and show_btis

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

output:
image

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

output:
image

gti1 = [1.32540e8 1.32580e8]
plot(events, gtis=gti1, show_gtis=true,gap_threshold=100)
#or u can use `plot(events, gti_file="gti.fits", show_gtis=true)`

output:
image

rebining

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

output :
image

with Poission errors

suggestion when looking for errors, first create a lightcurve

lc = create_lightcurve(events, 10)
plot(lc, show_errors=true,)#u can apply axis_lmit

output
image

Now with monal_testA :

image

with Gaussian errors

# Create light curve from events with smaller bins for smoother appearance
lc = create_lightcurve(events, 1)  # Much smaller bins (0.1 seconds instead of 1.0)
lc_times = lc.time
lc_counts = lc.counts

# Apply smoothing to get continuous-looking data
using StatsBase
# Option 1: Moving average smoothing
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)]

# Option 2: Alternative - use a simple running mean
# smoothed_counts = running_mean(lc_counts, window_size)

# Create more realistic errors based on smoothed data
σ = sqrt.(max.(smoothed_counts, 1))  # Poisson-like errors, avoid sqrt of 0

# Create confidence bands
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")

# Add confidence bands (from outer to inner)
plot!(lc_times, [upper_3σ lower_3σ], fillrange=[lower_3σ upper_3σ], 
      fillalpha=0.2, fillcolor=:gray, label="", linewidth=0)
plot!(lc_times, [upper_2σ lower_2σ], fillrange=[lower_2σ upper_2σ], 
      fillalpha=0.3, fillcolor=:orange, label="", linewidth=0)
plot!(lc_times, [upper_1σ lower_1σ], fillrange=[lower_1σ upper_1σ], 
      fillalpha=0.4, fillcolor=:lightblue, label="", linewidth=0)

# Replot the main line on top
plot!(lc_times, smoothed_counts, seriestype=:line, linewidth=2, color=:blue, label="")

# Display the plot
display(p)

output
image

segmentation

using Plots
events = readevents("ni1200120104_0mpu7_cl.evt", load_gti=true, sort=true)
segments = create_segments(events, 10000.0)
plot(segments, 
     show_errors=false,
     show_segment_boundaries=true,
     segment_colors=[:blue, :red, :green, :orange, :purple])

output:
image

tagging @fjebaker @matteobachetti @stefanocovino

@kashish2210
Copy link
Member Author

I have added a new plotting recipe gti_length_distribution

using Plots
bti=BTIAnalysisPlot(events)
plot(bti,bti_analysis=true)

output:

image

plot(BTIAnalysisPlot(events), bins=1400,min_length=1e-5,max_length=10000000)
plot(BTIAnalysisPlot(events), bins=10000)

output

image image

Tagging @matteobachetti [this new recpies with max_length , min_length works nearly like using geom scale]

@kashish2210 kashish2210 reopened this Aug 10, 2025
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.

1 participant