-
Notifications
You must be signed in to change notification settings - Fork 7
/
corrections.py
37 lines (30 loc) · 1.26 KB
/
corrections.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import logging
from datetime import timedelta
from astropy.time import Time
import callhorizons
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def get_uncorrected_jd(analysis):
return Time(analysis.image_datetime).jd
def get_lighttime_correction(analysis):
jd = get_jd_for_analysis(analysis)
q = callhorizons.query(analysis.lightcurve.target_name)
q.set_discreteepochs(jd)
# TODO(ian): Allow user to set observatory code, or choose the one closest
# to them. https://www.minorplanetcenter.net/iau/lists/ObsCodesF.html
# Currently defaulting to Greenwich.
q.get_ephemerides(0)
if 'lighttime' not in q.fields:
logger.warn('Could not look up lighttime for target %s. Got %s' % \
(analysis.lightcurve.target_name, q.fields))
return None
sec = q['lighttime'][0]
adjusted_dt = analysis.image_datetime - timedelta(seconds=sec)
ret = Time(adjusted_dt).jd
logger.info('Applied lighttime correction of %f sec to target %s: %f -> %f' % \
(sec, analysis.lightcurve.target_name, jd, ret))
return ret
def get_jd_for_analysis(analysis):
if analysis.image_jd_corrected:
return analysis.image_jd_corrected
return Time(analysis.image_datetime).jd