Skip to content

Conversation

@Aman-Pandey-afk
Copy link
Collaborator

This is a basic implementation of EventList with essential APIs and tests
Things remaining:

  • Implement EventList Writing
  • LightCurve Methods
  • Plot Testing
  • Optimizing/Refactoring the Code

Cross-spectra/Periodograms APIs and documentation will be implemented soon in next PRs

@codecov-commenter
Copy link

codecov-commenter commented Sep 2, 2022

Codecov Report

Merging #7 (96db379) into main (cddac34) will decrease coverage by 73.80%.
The diff coverage is 73.68%.

@@             Coverage Diff             @@
##             main       #7       +/-   ##
===========================================
- Coverage   95.24%   21.43%   -73.81%     
===========================================
  Files           3        6        +3     
  Lines         505      667      +162     
===========================================
- Hits          481      143      -338     
- Misses         24      524      +500     
Impacted Files Coverage Δ
src/lightcurve.jl 0.00% <0.00%> (ø)
src/gti.jl 22.59% <47.36%> (-70.49%) ⬇️
src/events.jl 85.29% <85.29%> (ø)
src/io.jl 97.82% <97.82%> (ø)
src/fourier.jl 0.00% <0.00%> (-96.40%) ⬇️
src/utils.jl 0.00% <0.00%> (-92.31%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@Aman-Pandey-afk
Copy link
Collaborator Author

These were minor mistakes (like not uncommenting some codes, mostly 1-2 lines) so force pushed in the same commit.

@Aman-Pandey-afk Aman-Pandey-afk marked this pull request as ready for review September 6, 2022 20:14
timesys::String=""
end

function read(::Type{EventList},filename::String, format::String)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I presume the first argument is to indicate the output type, right? Most read methods have it as last argument, not first one

end

function from_lc(lc::LightCurve)
times = [lc.time[i] for i in 1:length(lc.time) for _ in 1:lc.counts[i]]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's preferable to iterate over the actual indices of an array with eachindex

Suggested change
times = [lc.time[i] for i in 1:length(lc.time) for _ in 1:lc.counts[i]]
times = [lc.time[i] for i in eachindex(lc.time, lc.counts) for _ in 1:lc.counts[i]]

In this way you also avoid the assumption that arrays are 1-based indexed, which is not necessarily the case.

Comment on lines +45 to +46
tstart=0
tseg=0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ev.git has typically Float64 values?

gti::T3=reshape(Float64[],0,2)
For example you could use zero(eltype(ev.gti)).

Comment on lines +48 to +49
tstart = ev.gti[begin][begin]
tseg = ev.gti[end][end]-tstart
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I look closer to this, I'm a bit confused by the ev.gti[index][index] notation: what do you want to do? That's not how indexing of multi-dimensional arrays (like matrices) work.

n = 1384132
mean_counts = 2.0
times = range(dt/2, dt/2 + n*dt, step = dt)
counts = zero(times) .+ mean_counts
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not performance-critical in the tests, but I think it makes more sense to just create a vector with all mean_counts instead of creating a vector of zeros and adding mean_counts to it?

Suggested change
counts = zero(times) .+ mean_counts
counts = fill(mean_counts, size(times))

This also saves the allocation of one array.

dt_new = 1.5
lc_binned = rebin(lc, dt_new)
@test lc_binned.dt == dt_new
counts_test = zero(lc_binned.time) .+ lc.counts[1]*dt_new/lc.dt
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
counts_test = zero(lc_binned.time) .+ lc.counts[1]*dt_new/lc.dt
counts_test = fill(lc.counts[begin] * dt_new / lc.dt, size(lc_binned.time))

FITS(filename) do hduList
eventHDU = hduList["EVENTS"]
cols = FITSIO.colnames(eventHDU)
df = DataFrame(eventHDU)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why going through a dataframe? That looks unnecessary? For example, you can get the "TIME" column with read(eventHDU, "TIME").

Comment on lines +32 to +37
y_err::AbstractVector{<:Real}=Float64[], method::String = "sum", dx::Real=0)
if isempty(y_err)
y_err = zero(y)
end

if dx isa AbstractVector
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can dx be an AbstractVector if it's annotated as Real?


if method in ["mean", "avg", "average", "arithmetic mean"]
ybin = output / step_size
ybinerr = sqrt.(outputerr) / step_size
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fuse dot operations

Suggested change
ybinerr = sqrt.(outputerr) / step_size
ybinerr = sqrt.(outputerr) /. step_size

end

new_x0 = (x[1] - (0.5 * dx_old[1])) + (0.5 * dx_new)
xbin = 1:length(ybin) * dx_new .+ new_x0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just double checking: are you entirely sure this is parsed as you expect?

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.

3 participants