forked from zvanderbosch/phot2lc
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaddstar
More file actions
executable file
·97 lines (82 loc) · 2.31 KB
/
addstar
File metadata and controls
executable file
·97 lines (82 loc) · 2.31 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env python
import os
import argparse
import pandas as pd
import astropy.units as u
from astropy.coordinates import SkyCoord
import phot2lc.teledat as teledat
"""
Script which adds a new object entry
into the stars.dat file. Checks first
whether an entry already exists.
Author:
Zach Vanderbosch
For a description of updates, see the
version_history.txt file.
"""
parser = argparse.ArgumentParser()
parser.add_argument('objectName',type=str,
help="Name of object to add into stars.dat")
parser.add_argument('ra',type=str,
help="Object Right Ascension.")
parser.add_argument('dec',type=str,
help="Object Declination.")
args = parser.parse_args()
# Parse inputs
objectname = args.objectName
ra = args.ra
dec = args.dec
# Input coordinates to Astropy
try:
ra_deg = float(ra)
dec_deg = float(dec)
coord = SkyCoord(
ra_deg,
dec_deg,
unit="deg",
frame="icrs"
)
except:
try:
coord = SkyCoord(
ra, dec,
frame='icrs',
unit=(
u.hourangle,
u.degree
)
)
except:
print('Could not produce SkyCoord object from provided coordinates:')
print(f' RA = {ra}')
print(f' Dec = {dec}')
exit(1)
# Oopen stars.dat file
config_path = os.path.dirname(os.path.realpath(teledat.__file__))
config_dat = []
with open(config_path + "/config.dat") as f:
for l in f.readlines():
config_dat.append(l.strip("\n").split("=")[-1].strip())
star_dat_file = config_dat[4]
star_dat = pd.read_csv(
star_dat_file,
header=None,
delim_whitespace=True,
dtype=str
)
# Check that object isn't already in stars.dat
match_idx = star_dat.index[star_dat.iloc[:,0] == objectname]
if len(match_idx) > 0:
match_dat = star_dat.loc[match_idx].values[0]
print('Object already in stars.dat file:')
print(' ',*match_dat)
exit()
# If no match, add to file
ra_string = coord.to_string('hmsdms',sep=" ",precision=2)[0:11]
de_string = coord.to_string('hmsdms',sep=" ",precision=2)[12:]
new_line = "{} {} {}\n".format(objectname,ra_string, de_string)
with open(star_dat_file, 'a') as file:
file.write(new_line)
print('\nAdded "{:s}" entry to stars.dat file.\n'.format(
new_line.strip("\n"))
)