Skip to content

Commit c97a026

Browse files
authored
Merge pull request #557 from AAVSO/88-jd-to-hjd-converter-plugin-is-consistently-different-from-other-tools-by-a-small-amount
88 jd to hjd converter plugin is consistently different from other tools by a small amount
2 parents 548269f + 299b582 commit c97a026

File tree

5 files changed

+117
-50
lines changed

5 files changed

+117
-50
lines changed

script/hjd-diff.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Diff between two candidate HJD values and analysis
2+
# see https://github.com/AAVSO/VStar/issues/88
3+
4+
import numpy as np
5+
6+
def hjd_diff(hjd1, hjd2, verbose=True):
7+
abs_delta = abs(hjd1-hjd2)
8+
delta_secs = abs_delta*24*60*60
9+
if verbose:
10+
print(hjd1, hjd2, abs_delta, delta_secs)
11+
return abs_delta, delta_secs
12+
13+
14+
def analysis(hjd_pairs, title):
15+
print(title)
16+
17+
results = [hjd_diff(*pair) for pair in hjd_pairs]
18+
19+
deltas = np.array([result[0] for result in results])
20+
print(deltas.mean(), deltas.std())
21+
22+
23+
def test():
24+
old = [[2448908.497815484, 2448908.4978207937], [2457501.8694125116, 2457501.869426729], [2448908.497780874, 2448908.4977766555], [2457501.870747149, 2457501.8707473096], [2448908.499268005, 2448908.4992657346], [2457501.868574388, 2457501.8685732614]]
25+
26+
new_eccentricity_fix = [[2448908.4978205077, 2448908.4978207937], [2457501.869423921, 2457501.869426729], [2448908.4977859845, 2448908.4977766555], [2457501.870765871, 2457501.8707473096], [2448908.499269691, 2448908.4992657346], [2457501.8685812056, 2457501.8685732614]]
27+
28+
new_long2000_fix = [[2448908.497820837, 2448908.4978207937], [2457501.869426577, 2457501.869426729], [2448908.4977756487, 2448908.4977766555], [2457501.8707476617, 2457501.8707473096], [2448908.4992653183, 2448908.4992657346], [2457501.8685733136, 2457501.8685732614]]
29+
30+
analysis(old, "old")
31+
analysis(new_eccentricity_fix, "new eccentricity fix")
32+
analysis(new_long2000_fix, "new longitude 2000 fix")
33+
34+
35+
if __name__ == "__main__":
36+
test()

script/jd2hjd.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from astropy.time import Time
2+
from astropy.coordinates import SkyCoord, EarthLocation
3+
import astropy.units as u
4+
5+
import sys
6+
7+
8+
def jd2hjd(jd: float, ra: float, dec: float) -> float:
9+
# 1. Define input time, location (, and target
10+
jd_time = Time(jd, format='jd', scale='utc')
11+
# Klemzig (how much difference does location make for our purposes?)
12+
location = EarthLocation(lat=34.88*u.deg, lon=138.64*u.deg, height=60*u.m)
13+
target = SkyCoord(ra=ra*u.deg, dec=dec*u.deg)
14+
15+
# 2. Calculate light travel time to heliocenter (or barycenter)
16+
ltt_hjd = jd_time.light_travel_time(target, 'heliocentric', location=location)
17+
18+
# 3. Apply correction
19+
hjd_time = jd_time + ltt_hjd
20+
21+
return hjd_time
22+
23+
24+
if __name__ == "__main__":
25+
if len(sys.argv) == 4:
26+
jd = float(sys.argv[1])
27+
ra = float(sys.argv[2])
28+
dec = float(sys.argv[3])
29+
hjd = jd2hjd(jd, ra, dec)
30+
print(f"{jd} => {hjd}")

src/org/aavso/tools/vstar/util/Tolerance.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class Tolerance {
3535
*/
3636
public static boolean areClose(double a, double b, double epsilon, boolean absolute) {
3737
double diff = Math.abs(a - b);
38-
if(absolute){
38+
if (absolute) {
3939
return diff < epsilon;
4040
}
4141

src/org/aavso/tools/vstar/util/date/J2000HJDConverter.java

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -162,45 +162,37 @@ protected SolarCoords solarCoords(double T, int year) {
162162
// Meeus (p 152)
163163
// True solar longitude.
164164
double trueSolarLong = Lo + C;
165-
double trueSolarLongDegs = Math.toDegrees(trueSolarLong);
165+
166+
// Meeus (p 152)
167+
// Sun's longitude with respect to J2000.0 epoch.
168+
double trueSolarLong2000 = trueSolarLong - Math.toRadians(0.01397)
169+
* (year - 2000.0);
166170

167171
// double omegaDegs = 125.04 - 1934.136 * T;
168172
double omega = longitudeOfAscendingNode(T);
169173

170174
// Meeus (p152)
171175
// Apparent longitude of Sun.
172176
// Note: not strictly needed.
173-
double lambda = trueSolarLong - Math.toRadians(0.00569)
177+
double lambda = trueSolarLong2000 - Math.toRadians(0.00569)
174178
- Math.toRadians(0.00478) * Math.sin(omega);
175179

176-
// Meeus (p 152)
177-
// Sun's longitude with respect to J2000.0 epoch.
178-
double trueSolarLong2000 = trueSolarLong - Math.toRadians(0.01397)
179-
* (year - 2000.0);
180-
double trueSolarLong2000Degs = Math.toDegrees(trueSolarLong2000);
181-
182180
// Obliquity of the ecliptic.
183181
double obliq = obliquity(T);
184182
double apparentObliq = obliq + Math.toRadians(0.00256)
185183
* Math.cos(omega);
186184

187-
// Note: we can use trueSolarLong or trueSolarLong2000 for
188-
// RA and Dec calculations below; which is most appropriate? The delta
189-
// for HJD correction purposes appears to be is sub-second.
190-
// trueSolarLong2000 is, according to Meeus, used for meteor work, but
191-
// it's not clear that it should be used for variable star work.
192-
193185
// Meeus 24.6
194186
// Right ascension of the Sun.
195-
double solarRA = Math.atan2(Math.cos(obliq) * Math.sin(trueSolarLong),
196-
Math.cos(trueSolarLong));
187+
double solarRA = Math.atan2(Math.cos(obliq) * Math.sin(trueSolarLong2000),
188+
Math.cos(trueSolarLong2000));
197189

198190
double apparentSolarRA = Math.atan2(
199191
Math.cos(apparentObliq) * Math.sin(lambda), Math.cos(lambda));
200192

201193
// Meeus (24.7)
202194
// Declination of the Sun.
203-
double solarDec = Math.asin(Math.sin(obliq) * Math.sin(trueSolarLong));
195+
double solarDec = Math.asin(Math.sin(obliq) * Math.sin(trueSolarLong2000));
204196

205197
double apparentSolarDec = Math.asin(Math.sin(apparentObliq)
206198
* Math.sin(lambda));
@@ -260,17 +252,19 @@ protected double radiusVector(double T, double M, double C) {
260252

261253
/**
262254
* Given the time in Julian centuries, return eccentricity of Earth's orbit.
263-
*
255+
* Eccentricity is dimensionless (unitless); it must not be converted to
256+
* radians, as it is used in the radius-vector formula (24.5) as a pure
257+
* number.
258+
*
264259
* @param T
265260
* The time in Julian centuries.
266-
* @return The eccentricity in radians.
261+
* @return The eccentricity (dimensionless).
267262
*/
268263
protected double eccentricity(double T) {
269264

270265
// Meeus 24.4
271266
// Eccentricity of Earth's orbit.
272-
double eDegs = 0.016708617 - 0.000042037 * T - 0.0000001236 * (T * T);
273-
return Math.toRadians(eDegs);
267+
return 0.016708617 - 0.000042037 * T - 0.0000001236 * (T * T);
274268
}
275269

276270
/**

test/org/aavso/tools/vstar/util/date/J2000EpochHJDConverterTest.java

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
*/
1818
package org.aavso.tools.vstar.util.date;
1919

20-
import junit.framework.TestCase;
21-
20+
import org.aavso.tools.vstar.util.Tolerance;
2221
import org.aavso.tools.vstar.util.coords.DecInfo;
2322
import org.aavso.tools.vstar.util.coords.EpochType;
2423
import org.aavso.tools.vstar.util.coords.RAInfo;
2524

25+
import junit.framework.TestCase;
26+
2627
/**
2728
* J2000HJDConverter unit tests.
2829
*/
@@ -154,8 +155,9 @@ public void testJulianCenturiesEx24a() {
154155

155156
public void testEccentricityEx24a() {
156157
double T = julianCenturiesEx24a();
157-
double eDegs = Math.toDegrees(converter.eccentricity(T));
158-
assertEquals("0.016711651", getNumToPrecision(eDegs, 9));
158+
// Eccentricity is dimensionless (Meeus 24.4).
159+
double e = converter.eccentricity(T);
160+
assertEquals("0.016711651", getNumToPrecision(e, 9));
159161
}
160162

161163
public void testSolarCoordsEx24a() {
@@ -174,25 +176,27 @@ public void testSolarCoordsEx24a() {
174176
double CDegs = Math.toDegrees(coords.getEquationOfCenter());
175177
assertEquals("-1.89732", getNumToPrecision(CDegs, 5));
176178

177-
// Meeus gives 198.38082, so we differ by 0.00001
178-
assertEquals("198.38083", getNumToPrecision(coords.getApparentRA(), 5));
179-
180-
// Meeus gives -7.78507, so we differ by 0.00003
181-
assertEquals("-7.78504", getNumToPrecision(coords.getApparentDec(), 5));
179+
// Meeus gives 198.38082, and when previously using true solar longitude
180+
// instead of J2000-corrected true solar longitude, we differed from Meeus
181+
// by 0.00001 (198.38083). With J2000 correction, the apparent RA is
182+
// 198.48529 instead. Example 24.a in Meeus does not show the result with
183+
// J2000 correction. These values are consistent with subsequent improved
184+
// HJD conversion accuracy.
185+
assertEquals("198.48529", getNumToPrecision(coords.getApparentRA(), 5));
186+
187+
// Meeus gives -7.78507, and when previously using true solar longitude
188+
// instead of J2000-corrected true solar longitude, we differed from Meeus
189+
// by by 0.00003 (-7.78504). With J2000 correction, the apparent Dec is
190+
// -7.82721 instead. Example 24.a in Meeus does not show the result with
191+
// J2000 correction. These values are consistent with subsequent improved
192+
// HJD conversion accuracy.
193+
assertEquals("-7.82721", getNumToPrecision(coords.getApparentDec(), 5));
182194

183-
// Not provided in Meeus, but not wildly at odds with apparent RA.
184195
double ra = coords.getRA();
185-
assertEquals("198.38167", getNumToPrecision(ra, 5));
186-
// When Sun's longitude is referred to standard equinox of J2000.0
187-
// (trueSolarLong2000).
188-
// assertEquals("198.48617", getNumToPrecision(ra, 5));
196+
assertEquals("198.48613", getNumToPrecision(ra, 5));
189197

190-
// Not provided in Meeus, but not wildly at odds with apparent Dec.
191198
double dec = coords.getDec();
192-
assertEquals("-7.78546", getNumToPrecision(dec, 5));
193-
// When Sun's longitude is referred to standard equinox of J2000.0
194-
// (trueSolarLong2000).
195-
// assertEquals("-7.82756", getNumToPrecision(dec, 5));
199+
assertEquals("-7.82764", getNumToPrecision(dec, 5));
196200
}
197201

198202
public void testRadiusVectorEx24a() {
@@ -204,9 +208,8 @@ public void testRadiusVectorEx24a() {
204208

205209
double R = converter.radiusVector(T, coords.getTrueAnomaly(),
206210
coords.getEquationOfCenter());
207-
// Meeus Ex 24.a gives R = 0.99766, whereas we have R = 0.99996.
208-
// Is this an error in Meeus or in our computation?
209-
assertEquals("0.99996", getNumToPrecision(R, 5));
211+
// Meeus Ex 24.a, p 153: R = 0.99766 AU (requires eccentricity as dimensionless).
212+
assertEquals("0.99766", getNumToPrecision(R, 5));
210213
}
211214

212215
private double julianCenturiesEx24a() {
@@ -233,7 +236,7 @@ public void testHJDRCar1() {
233236
// to 2448908.49782, whereas the convert() method gives
234237
// 2448908.497815484, the same to 5 decimal places (~1/100th of a
235238
// second).
236-
assertEquals("2448908.49782", getNumToPrecision(hjd, 5));
239+
assertTrue(Tolerance.areClose(2448908.4978207937, hjd, 1e-5, true));
237240
}
238241

239242
// R Car with JD2
@@ -251,7 +254,8 @@ public void testHJDRCar2() {
251254
// to 2457501.86943, whereas the convert() method gives
252255
// 2457501.8694125116, the same to 4 decimal places (~1/10th of a
253256
// second).
254-
assertEquals("2457501.86941", getNumToPrecision(hjd, 5));
257+
// Corrected radius vector (eccentricity dimensionless) matches BAA to ~0.01 day.
258+
assertTrue(Tolerance.areClose(2457501.869426729, hjd, 1e-5, true));
255259
}
256260

257261
// X Sgr with Meeus's Ex24.a JD
@@ -268,7 +272,8 @@ public void testHJDXSgr1() {
268272
// entry for R Car. That gave the result 2448908.4977766555, shortened
269273
// to 2448908.49778, whereas the convert() method gives
270274
// 2448908.497780874.
271-
assertEquals("2448908.49778", getNumToPrecision(hjd, 5));
275+
// Corrected radius vector; result within ~1 s of BAA.
276+
assertTrue(Tolerance.areClose(2448908.4977766555, hjd, 1e-5, true));
272277
}
273278

274279
// X Sgr with JD2
@@ -285,7 +290,8 @@ public void testHJDXSgr2() {
285290
// entry for R Car. That gave the result 2457501.8707473096, shortened
286291
// to 2457501.87075, whereas the convert() method gives
287292
// 2457501.870747149.
288-
assertEquals("2457501.87075", getNumToPrecision(hjd, 5));
293+
// Corrected radius vector; result within ~1 s of BAA.
294+
Tolerance.areClose(2457501.8707473096, hjd, 1e-5, true);
289295
}
290296

291297
// Sig Oct with Meeus's Ex24.a JD
@@ -302,7 +308,7 @@ public void testHJDSigOct1() {
302308
// entry for R Car. That gave the result 2448908.4992657346, shortened
303309
// to 2448908.49927, whereas the convert() method gives
304310
// 2448908.499268005.
305-
assertEquals("2448908.49927", getNumToPrecision(hjd, 5));
311+
assertTrue(Tolerance.areClose(2448908.4992657346, hjd, 1e-5, true));
306312
}
307313

308314
// Sig Oct with JD2
@@ -319,7 +325,8 @@ public void testHJDSigOct2() {
319325
// entry for R Car. That gave the result 2457501.8685732614, shortened
320326
// to 2457501.86857, whereas the convert() method gives
321327
// 2457501.868574388.
322-
assertEquals("2457501.86857", getNumToPrecision(hjd, 5));
328+
// Corrected radius vector; result within ~1 s of BAA.
329+
assertTrue(Tolerance.areClose(2457501.8685732614, hjd, 1e-5, true));
323330
}
324331

325332
// Helpers

0 commit comments

Comments
 (0)