-
Notifications
You must be signed in to change notification settings - Fork 2
/
getTargetInfo.py
76 lines (70 loc) · 2.79 KB
/
getTargetInfo.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import argparse
from genericpath import isfile
import os
import logging
from astropy.time import Time
from datetime import datetime
from math import log10, floor
import astropy.units as u
from astropy.coordinates import SkyCoord, EarthLocation, AltAz
try:
from .libs.unistellar import unistellarBestGainAndExp, unstellarExoplanetURL
except ImportError: # package import
from libs.unistellar import unistellarBestGainAndExp, unstellarExoplanetURL
try:
from .libs.exofop import exofop_getcompositeinfo, exofop_getticid, exofop_getparameters
except ImportError:
from libs.exofop import exofop_getcompositeinfo, exofop_getticid, exofop_getparameters
# create logger
logger = logging.getLogger('getTargetInfo')
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
# Initialize parser
parser = argparse.ArgumentParser()
parser.add_argument("-t", "--target", help = "Target Name")
parser.add_argument("-d", "--duration", type=float)
parser.add_argument("--ra", help = "Target RA")
parser.add_argument("--dec", help = "Target Dec")
parser.add_argument("--mag", help = "Magnitude (V)")
# Read arguments from command line
try:
args = parser.parse_args()
except argparse.ArgumentError:
os.exit(1)
duration = 1.0
if (args.duration):
duration = float(args.duration)
logger.info("args=%s" % args)
if args.target:
tic = exofop_getticid(args.target)
logger.info(f"TIC={tic}")
if tic:
skypos, vmag = exofop_getcompositeinfo(tic)
# Adjust for proper motion (milliarcsec to degrees)
curpos = skypos.apply_space_motion(new_obstime = Time(datetime.utcnow(), scale='utc'))
else:
logger.error("Tsrget not found")
exit(1)
exofop_getparameters(tic)
elif args.dec and args.ra and args.mag:
skypos = SkyCoord(args.ra, args.dec, frame='icrs', unit=(u.hourangle, u.deg))
vmag = float(args.mag)
curpos = skypos
else:
logger.error("Either --target or --ra, --dec and --mag required")
exit(1)
logger.info(f"J2000, epoch J2015.5: RA/Dec={skypos.to_string('hmsdms')}")
logger.info(f"Current RA/Dec={curpos.to_string('hmsdms')}")
logger.info(f"V (mag) = {vmag}")
bestgain, exptime = unistellarBestGainAndExp(vmag)
logger.info(f"Unistellar: best gain = {bestgain} db, exposure time = {exptime} ms")
if bestgain is None:
exit(1)
url = f"unistellar://science/transit?ra={curpos.ra.deg:.5f}&dec={curpos.dec.deg:.5f}&c=3970&et={exptime}&g={bestgain}&d={int(10)}"
logger.info(f"Unistellar URL (for 10 seconds): {url}")
url = f"unistellar://science/transit?ra={curpos.ra.deg:.5f}&dec={curpos.dec.deg:.5f}&c=3970&et={exptime}&g={bestgain}&d={int(duration * 3600)}"
logger.info(f"Unistellar URL (for {duration} hours): {url}")