-
Notifications
You must be signed in to change notification settings - Fork 12
Example: Simple EventList implementation #50
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
base: main
Are you sure you want to change the base?
Conversation
Simplified the logic for reading in data and let the libraries throw their errors back to the user to handle. Implemented a very basic `filter!` function as demonstration for how this structure can be used, and to add a simple API for when GTIs are tied together with the event list.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #50 +/- ##
==========================================
- Coverage 95.24% 89.37% -5.88%
==========================================
Files 3 4 +1
Lines 505 574 +69
==========================================
+ Hits 481 513 +32
- Misses 24 61 +37 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
I will start working like this for this week @fjebaker thanks for your reference :) |
| # modified from the Base.filter! implementation | ||
| j = firstindex(ev.times) | ||
|
|
||
| for i in eachindex(ev.times) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eachindex gives you a lazy iterator that goes over all of the indices of an array. If your array has unusual indexing (e.g. starts at 0 or something else, or maybe uses IndexCartesian), it gives you something that will hit every element.
In this case, it's equivalent to firstindex(ev.times):lastindex(ev.times), or equivalently 1:length(ev.times), but would work with other array types just fine.
Somewhere in the Julia docs it says to prefer eachindex over 1:length so that code is more portable. In this case it really doesn't make a difference. So many ways to skin a cat!
@kashish2210 I've implemented a small EventList in this PR that can read all of the standard stringray test files.
I'm not suggesting we use this implementation, but I'd encourage you to look at it as an example for how you could simplify some of the logic in your implementation in #47.
Some things to note:
EventList(times, energies)constructor directly.read_energy_columnfunction simplifies the logic of reading the energy column dramatically. The same thing is happening, but the code doesn't need to define variables ahead of time, and theread_energy_columnfunction can be tested independently if needed.::Vector{T}or::FITSIO.FITSHeaderannotations means that this code is also completely type stable when reading in data (you can check that with@code_warntype).filter_time!function to illustrate how you could write a composable small function that modifies the event list in-place, which can later be used to filter events in a set of GTIs. You could do similar for afilter_timeor such function that would return a new event lists with events that match the predicate. The benefit of writing these like so is now someone else could e.g. filter events after some given time by just doingfilter_time!(>(min_time), event_list).With Unitful.jl, this could even be more expressive:
Regarding tests:
@testsetoutside ofruntests.jl. This means you can interactively run the test within your IDE of choice and fix things simply.More on GTIs:
STARTandSTOP, which ought to be read at the same time. That means we should augmentEventListwith the GTI information somehow, for example, adding agti_startandgti_stopfield of vectors. But that should be a seperate PR.