-
Notifications
You must be signed in to change notification settings - Fork 11
events to lightcurve #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JawadAhmadCS
wants to merge
18
commits into
StingraySoftware:main
Choose a base branch
from
JawadAhmadCS:events
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
fd634dc
add feature to convert events to lightcurve
JawadAhmadCS d9da604
warnings in lightcurve
JawadAhmadCS dffee11
lightcurve improvment according to seggested recipes
JawadAhmadCS c9a81a7
improvments after review
JawadAhmadCS 00bf409
relook on improvments
JawadAhmadCS 3ff73cd
remove remaining sqrtN & test on different bin sizes
JawadAhmadCS c4d65eb
remove unnecessary print from test
JawadAhmadCS e553a7a
histogram implementation
JawadAhmadCS c969cf9
add tests
JawadAhmadCS 1348f92
test to verify counts
JawadAhmadCS c04f6a1
error method
JawadAhmadCS ccdf3b3
manual expected count for bins test
JawadAhmadCS 5870a98
remove redundant checks
JawadAhmadCS 71eec71
replace min max with exreme
JawadAhmadCS 0c3c4b4
improvement
JawadAhmadCS 4c4ca96
remove reduntancy & more changes
JawadAhmadCS 6dc0225
revert to recent approved version
JawadAhmadCS 215217b
revert to recent approved version
JawadAhmadCS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
""" | ||
LightCurve{T} | ||
|
||
A structure representing a light curve, which is a time series of event counts. | ||
|
||
## Fields | ||
|
||
- `timebins::Vector{T}`: Time bins for the light curve. | ||
- `counts::Vector{T}`: Number of events in each time bin. | ||
- `count_error::Vector{T}`: Error estimate for each bin. | ||
- `err_method::Symbol`: Method used for error estimation (`:poisson`). | ||
""" | ||
struct LightCurve{T} | ||
timebins::Vector{T} | ||
counts::Vector{T} | ||
count_error::Vector{T} | ||
err_method::Symbol | ||
end | ||
|
||
""" | ||
create_lightcurve(eventlist::EventList{T}, bin_size::T; err_method::Symbol=:poisson) | ||
|
||
Generate a light curve from an EventList by binning event times. | ||
|
||
## Arguments | ||
|
||
- `eventlist::EventList{T}`: The input event list. | ||
- `bin_size::T`: The size of each time bin. | ||
- `err_method::Symbol`: The method for error estimation (`:poisson`). | ||
|
||
## Returns | ||
|
||
A LightCurve instance containing binned event counts. | ||
|
||
## Notes | ||
|
||
- The function bins event times into intervals of `bin_size`. | ||
- Errors are estimated using Poisson statistics. | ||
""" | ||
function create_lightcurve(eventlist::EventList{T}, bin_size::T; err_method::Symbol=:poisson) where T | ||
if err_method ∉ (:poisson,) | ||
throw(ArgumentError("Invalid error method: $err_method. Supported methods: :poisson")) | ||
end | ||
min_time,max_time = extrema(eventlist.times) | ||
bins = min_time:bin_size:max_time | ||
hist = fit(Histogram, eventlist.times, bins) | ||
counts = hist.weights | ||
errors = sqrt.(counts) | ||
return LightCurve{T}(bins, counts, errors, err_method) | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
@testset "LightCurve Tests" begin | ||
test_dir = mktempdir() | ||
sample_file = joinpath(test_dir, "sample_lightcurve.fits") | ||
|
||
# Sample Data | ||
times = [0.1, 0.5, 1.2, 2.4, 3.0, 4.1, 5.6, 6.8, 7.9, 9.2] | ||
energies = [100, 200, 150, 180, 250, 300, 275, 220, 190, 210] | ||
metadata = Dict("TELESCOP" => "TestScope", "MISSION" => "TestMission") | ||
|
||
# Create a sample FITS file for testing | ||
f = FITS(sample_file, "w") | ||
write(f, Int[]) # Empty primary array | ||
table = Dict("TIME" => times, "ENERGY" => energies) | ||
write(f, table) | ||
close(f) | ||
|
||
@test isfile(sample_file) | ||
|
||
# test reading the sample file | ||
eventlist = readevents(sample_file) | ||
@test eventlist.filename == sample_file | ||
@test length(eventlist.times) == length(times) | ||
@test length(eventlist.energies) == length(energies) | ||
|
||
# expected counts for different bin sizes | ||
bin_sizes = [1.0, 0.5, 2.0, 1.3] | ||
expected_counts = [ | ||
[2.0, 1.0, 2.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0], | ||
[2.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0], | ||
[3.0, 2.0, 2.0, 2.0], | ||
[3.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] | ||
] | ||
|
||
# Test different bin sizes | ||
fjebaker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for (bin_size, expected) in zip(bin_sizes, expected_counts) | ||
lightcurve = create_lightcurve(eventlist, bin_size, err_method=:poisson) | ||
|
||
@test lightcurve.err_method == :poisson | ||
@test length(lightcurve.timebins) == length(lightcurve.counts) + 1 #bin count fix | ||
@test lightcurve.counts == expected | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.