Skip to content
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

Dat #31

Merged
merged 5 commits into from Jun 10, 2018
Merged

Dat #31

merged 5 commits into from Jun 10, 2018

Conversation

prakharcode
Copy link
Contributor

@prakharcode prakharcode commented Jun 7, 2018

Ported dat into leapseconds

@giordano
Copy link
Member

giordano commented Jun 8, 2018

A couple of general comments: do not parenthesize conditions; also errors should be covered by the tests.

@helgee
Copy link
Member

helgee commented Jun 8, 2018

Sorry @prakharcode for not raising this issue beforehand but a straight port from C won't cut it here. Most of the things that ERFA.dat does are already avaiable in the leapseconds method, see here: https://github.com/JuliaAstro/AstroTime.jl/blob/master/src/LeapSeconds.jl#L38

The best approach would thus be to replace the call to ERFA.dat in the branch at line 42 with ported code.

@coveralls
Copy link

coveralls commented Jun 8, 2018

Pull Request Test Coverage Report for Build 188

  • 6 of 6 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 87.532%

Totals Coverage Status
Change from base Build 181: 0.1%
Covered Lines: 344
Relevant Lines: 393

💛 - Coveralls

Copy link
Member

@helgee helgee left a comment

Choose a reason for hiding this comment

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

Still not there, yet. But we are making progress. Please see my comments in the code.

src/constants.jl Outdated
@@ -42,4 +43,40 @@ const ELB = 1.550519768e-8
const JD_MIN = -68569.5
const JD_MAX = 1e9

export DRIFT, LS_1972
Copy link
Member

Choose a reason for hiding this comment

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

These constants are specific to the LeapSeconds module and thus should also live there.

Copy link
Member

Choose a reason for hiding this comment

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

They also should not be exported because they are not generally useful.

@@ -3,9 +3,31 @@ module LeapSeconds
using ERFA
using OptionalData
using RemoteFiles
include("Periods.jl")
Copy link
Member

Choose a reason for hiding this comment

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

Including the same file in multiple places is an antipattern and a clear indication that you are increasing the coupling of the code and fighting against its structure, i.e. you are doing something wrong. See my comment below about where to put the constants.

The LeapSeconds module uses no functionality of the Periods module and therefore should not import it.

export leapseconds, LSK, LSK_FILE, LSK_DATA, fractionofday


struct changes
Copy link
Member

Choose a reason for hiding this comment

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

This whole structure seems unnecessary to me.

changes(t,leapseconds,drift)
end

CHANGE = changes(LS_1972, DRIFT)
Copy link
Member

Choose a reason for hiding this comment

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

It does not really make sense to define a function and then only call it once from the top (module) level. If it is top-level code that only runs on import then just put it on the module level. I do not think this is needed at all though.

src/Periods.jl Outdated
@@ -1,7 +1,6 @@
module Periods

import Base: *, /, get, isapprox, show

Copy link
Member

Choose a reason for hiding this comment

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

Accidental change?

@@ -561,7 +562,7 @@ end

end

function cal2jd(iy, im, id)
@inline function cal2jd(iy, im, id)
Copy link
Member

Choose a reason for hiding this comment

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

Please do not slap @inline on every function. This function for example is far too large to be force-inlined. See more information here https://en.wikipedia.org/wiki/Inline_expansion

src/constants.jl Outdated
( 39126.0, 0.0025920 ),
( 39126.0, 0.0025920 )]

LS_1972 = [
Copy link
Member

Choose a reason for hiding this comment

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

This should also be const.

Copy link
Member

Choose a reason for hiding this comment

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

Use the same pattern here as I have outlined above for drift.

While it is nice that the orginal code used human-readable dates, i.e. Gregorian calendar dates, from a maintenance perspective, it is more efficient to use Julian Day numbers directly and we will not edit this code a lot in the future. The leap seconds has replaced this scheme of keeping UTC in sync with the rotation of the Earth after all.

src/constants.jl Outdated
@@ -42,4 +43,40 @@ const ELB = 1.550519768e-8
const JD_MIN = -68569.5
const JD_MAX = 1e9

export DRIFT, LS_1972

const DRIFT = [
Copy link
Member

Choose a reason for hiding this comment

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

While I know that this is the structure from the C code, I do not think that it makes sense to adopt it here. You are doing a lot of work to get the data into a consumable state above. Why not have it in a usable form directly?

The formula for drift is drift = days_since_ref_epoch * drift_rate or drift = (jd - ref_epoch) * drift_rate. I would propose two have two tuples: DRIFT_EPOCHS and DRIFT_RATES. We also do not need to duplicate values like the C code.

# Use unmodified Julian Day number since this will also be the input
const DRIFT_EPOCHS = (
    2.4373005e6,
    2.4376655e6,
    2.4387615e6,
    2.4391265e6,
)

const DRIFT_RATES = (
    0.0012960,
    0.0011232,
    0.0012960,
    0.0025920,
)

We can then calculate the drift like this:

idx = findlast(jd .>= DRIFT_EPOCHS)
drift = (jd - DRIFT_EPOCHS[idx]) * DRIFT_RATES[idx]

Far simpler, isn't it?

@codecov-io
Copy link

codecov-io commented Jun 9, 2018

Codecov Report

Merging #31 into master will increase coverage by 0.12%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #31      +/-   ##
==========================================
+ Coverage    87.4%   87.53%   +0.12%     
==========================================
  Files           7        7              
  Lines         389      393       +4     
==========================================
+ Hits          340      344       +4     
  Misses         49       49
Impacted Files Coverage Δ
src/Epochs.jl 97.14% <ø> (ø) ⬆️
src/conversions.jl 99.17% <ø> (ø) ⬆️
src/LeapSeconds.jl 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3799fae...ac3bc8c. Read the comment docs.

@helgee
Copy link
Member

helgee commented Jun 10, 2018

I will merge this as it is and propose a few improvements in a new PR. Thanks @prakharcode 👍

@helgee helgee merged commit eb3f525 into JuliaAstro:master Jun 10, 2018
@prakharcode
Copy link
Contributor Author

Thank you 😄

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.

None yet

5 participants