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
Implement GTI Reading and Handling #3
Conversation
Codecov Report
@@ Coverage Diff @@
## aman-fourier #3 +/- ##
================================================
+ Coverage 94.55% 95.25% +0.69%
================================================
Files 3 3
Lines 386 506 +120
================================================
+ Hits 365 482 +117
- Misses 21 24 +3
Continue to review full report at Codecov.
|
src/utils.jl
Outdated
function contiguous_regions(condition::AbstractVector{Bool}) | ||
# Find the indicies of changes in "condition" | ||
d = diff(condition) | ||
idx = findall(x->x != 0, d) |
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.
idx = findall(x->x != 0, d) | |
idx = findall(!iszero, d) |
src/utils.jl
Outdated
|
||
if condition[1] | ||
# If the start of condition is True prepend a 0 | ||
idx = append!([1],idx) |
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.
I think you wanted to use pushfirst!
idx = append!([1],idx) | |
pushfirst!(idx, 1) |
src/utils.jl
Outdated
|
||
if condition[end] | ||
# If the end of condition is True, append the length of the array | ||
idx = append!(idx,[condition.size+1]) # Edit |
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.
idx = append!(idx,[condition.size+1]) # Edit | |
push!(idx, condition.size + 1) # Edit |
What does "edit" mean?
src/gti.jl
Outdated
)) | ||
end | ||
|
||
if any(@view(gti_start[2:end]) < @view(gti_end[1:end-1])) |
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.
if any(@view(gti_start[2:end]) < @view(gti_end[1:end-1])) | |
if any(@view(gti_start[begin+1:end]) < @view(gti_end[begin:end-1])) |
src/gti.jl
Outdated
new_gtis[ig][:] .= limmin, limmax | ||
for (i,t) in enumerate(times) | ||
if t >= (limmin + dt / 2 - epsilon_times_dt) && t <= (limmax - dt / 2 + epsilon_times_dt) | ||
mask[i] = true |
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.
Indentation is off
src/gti.jl
Outdated
safe_interval::AbstractVector{<:Real}=[0,0], min_length::Real=0, | ||
dt::Real = -1, epsilon::Real = 0.001) | ||
|
||
if length(times) == 0 |
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.
if length(times) == 0 | |
if isempty(times) |
should be the same, right?
src/gti.jl
Outdated
end | ||
|
||
function get_btis(gtis::AbstractMatrix{<:Real}) | ||
if length(gtis) == 0 |
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.
if length(gtis) == 0 | |
if isempty(gtis) |
src/gti.jl
Outdated
end | ||
|
||
function get_btis(gtis::AbstractMatrix{T}, start_time, stop_time) where {T<:Real} | ||
if length(gtis) == 0 |
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.
if length(gtis) == 0 | |
if isempty(gtis) |
|
||
function get_btis(gtis::AbstractMatrix{T}, start_time, stop_time) where {T<:Real} | ||
if length(gtis) == 0 | ||
return T[start_time stop_time] |
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.
Did you return a matrix instead of a vector on purpose?
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.
Yeah to return same types
src/gti.jl
Outdated
lchdulist = FITS(fits_file) | ||
gtihdu = lchdulist[gtistring] | ||
gti = get_gti_from_hdu(gtihdu) | ||
close(lchdulist) |
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.
I think you can do
lchdulist = FITS(fits_file) | |
gtihdu = lchdulist[gtistring] | |
gti = get_gti_from_hdu(gtihdu) | |
close(lchdulist) | |
gti = FITS(fits_file) do lchdulist | |
gtihdu = lchdulist[gtistring] | |
get_gti_from_hdu(gtihdu) | |
end |
Codecov Report
@@ Coverage Diff @@
## aman-fourier #3 +/- ##
===============================================
Coverage ? 95.24%
===============================================
Files ? 3
Lines ? 505
Branches ? 0
===============================================
Hits ? 481
Misses ? 24
Partials ? 0 📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more |
GTI machinery and reading from file is implemented here, tests are passing and garbage collection is near to 0. Some points I would like to mention:
eachrow
sometimes which makes traversal in row order possible, which is inefficient as Julia matrices are stored in column-major order)operations_on_gti
function) as it seemed convenient and efficient to me instead of assigning therequired_interval
anIntervalSet
using the first element ofgti_list
.setdiff(IntervalSet1, IntervalSet2)
. I looked ways to remove it but can't, it outputs anIntervalSet
ofAbstractIntervals
.throw(ArgumentError)
is showing Any Typemapreduce
can give error if empty vectors are passed. Should I create appropriate Error throws for them?