Julian dates at R chron vs US Naval Observatory

Several previous posts have asked how to get Julian dates in R. One post, in particular, really needed ordinal dates, and I sent an answer:

Convert Julian day date vector to R

I indicated that my answer did indeed give ordinal dates, not Julian dates. Today I tried to modify my answer to show how to get the true Julian dates, and I got confused when using the package R chron.

Below is the code Rthat generates a set of random dates and then tries to get the corresponding Julian dates. I initially tried using the package R chronto create Julian dates and the US Naval Observatory website to check my answers:

http://aa.usno.navy.mil/data/docs/JulianDate.php

My answers did not match.

In the end, I was able to get Julian dates that match dates from the US Naval Observatory (after rounding the decimal point) using the equation from Wikipedia:

http://en.wikipedia.org/wiki/Julian_day

My question is: what am I doing wrong in chron? How do I get Julian dates in chronthat match the data obtained from the US Naval Observatory, or that match those obtained using the equation from Wikipedia?

Thanks for any advice.

Here is my R code:

set.seed(1234)
n.dates <- 10

day   <- sample(        25, n.dates, replace = TRUE)
month <- sample(        11, n.dates, replace = TRUE) 
year  <- sample(c(-4714:-1, 1:2014), n.dates, replace = TRUE)
year.b <- ifelse(year < 1, year+1, year)

a <- floor((14 - month) / 12)
y <- year.b + 4800 - a
m <- month + 12 * a - 3

#
# from Wikipedia:
# http://en.wikipedia.org/wiki/Julian_day
#

julian1 <- day + floor((153*m + 2)/5) + 365*y + floor(y/4) - floor(y/100) + floor(y/400) - 32045
julian2 <- day + floor((153*m + 2)/5) + 365*y + floor(y/4) - 32083

my.data <- data.frame(month, day, year, year.b, a, y, m, julian1, julian2, stringsAsFactors = F)

library(chron)
options(chron.origin = c(month=1, day=1, year= -4713))

my.data$my.julian <- julian(my.data$month, my.data$day, my.data$year)
my.data

#
# Note that julian2 matches the US Naval Observatory rounding off the decimal place.
#
#   month day  year year.b a    y m julian1 julian2 my.julian
#1      8   3 -2584  -2583 0 2217 5  777853  777832    777815
#2      6  16 -2678  -2677 0 2123 3  743472  743450    743434
#3      4  16 -3644  -3643 0 1157 1  390587  390558    390549
#4     11  16 -4445  -4444 0  356 8   98242   98207     98203
#5      4  22 -3242  -3241 0 1559 1  537420  537394    537382
#6     10  17   740    740 0 5540 7 1991629 1991633   1991956
#7      4   1 -1178  -1177 0 3623 1 1291260 1291249   1291222
#8      3   6  1440   1440 0 6240 0 2247074 2247083   2247401
#9      3  17   880    880 0 5680 0 2042550 2042554   2042877
#10     3  13 -4407  -4406 0  394 0  111873  111838    111835
#
# According to the US Naval Observatory website, the julian dates are:
#
# The Julian date for BCE  2584 August    3 00:00:00.0 UT is JD  777831.500000
# The Julian date for BCE  2678 June     16 00:00:00.0 UT is JD  743449.500000
# The Julian date for BCE  3644 April    16 00:00:00.0 UT is JD  390557.500000
# The Julian date for BCE  4445 November 16 00:00:00.0 UT is JD   98206.500000
# The Julian date for BCE  3242 April    22 00:00:00.0 UT is JD  537393.500000
# The Julian date for CE    740 October  17 00:00:00.0 UT is JD 1991632.500000
# The Julian date for BCE  1177 April     1 00:00:00.0 UT is JD 1291614.500000
# The Julian date for CE   1440 March     6 00:00:00.0 UT is JD 2247082.500000
# The Julian date for CE    880 March    17 00:00:00.0 UT is JD 2042553.500000
# The Julian date for BCE  4407 March    13 00:00:00.0 UT is JD  111837.500000
#
+4
source share

Source: https://habr.com/ru/post/1569829/


All Articles