forked from saltastro/timDIMM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hrstar.py
executable file
·162 lines (122 loc) · 4.32 KB
/
hrstar.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/env python
"""Functions for loading a catalog of stars, determining the RA/DEC for a given
star, and choosing the best star to observe.
"""
import math
from astropy.coordinates import Angle
salt_lat = Angle("-32:22:32 degree")
def load_catalog(catalog='star.lst'):
"""Load a catalog of stars
Parameters
----------
catalog: string
Name of catalog with stars in it. The catalog should have the format of
id, name (2 columns), rah, ram, ras, ded, dem, des, Vmag, B-V color, and
Spectral type.
Returns
-------
star_dict: dict
Dictionary with id as key, and containing name, ra, dec, vmag. ra/dec are
astropy.coordinate.angle objects
"""
#set up the deictionary
star_dict={}
#read in the catalog
lines = open(catalog).readlines()
for l in lines:
if not l.startswith('#'):
sid = l[0:4].strip()
name = l[5:12]
ra = Angle('%s hour' % (l[13:21]))
dec = Angle('%s%s degree' % (l[22], l[24:32]))
vmag = float(l[34:38])
star_dict[sid] = [name, ra, dec, vmag]
return star_dict
def calculate_airmass(ha, dec, lat=salt_lat):
"""Calculate the airmass given an hour angle and declination
Parameters
----------
ha: astropy.coordinates.Angle
Hour angle for an object
dec: astropy.coordinates.Angle
declination for an object
lat: astropy.coordinates.Angle
Latitude of the observatory
Returns
-------
az: astropy.coordinates.Angle
Azimuth of source
alt: astropy.coordinates.Angle
Altitude of source
airmass: float
Airmass of source
"""
#calculate the altitude
alt = math.sin(dec.radian)*math.sin(lat.radian) + \
math.cos(dec.radian)*math.cos(lat.radian)*math.cos(ha.radian)
alt = math.asin(alt)
alt = Angle(alt, unit='radian')
if lat.degree == 0 or alt.degree == 0:
az = 0
else:
n = -1.0*math.sin(ha.radian)
d = -1.0*math.cos(ha.radian) * math.sin(lat.radian) + \
math.sin(dec.radian) * math.cos(lat.radian) / math.cos(dec.radian)
az = math.atan2(n,d)
if az < 0: az += 2*math.pi
az = Angle(az, unit='radian')
ang = Angle(90, unit='degree') - alt
airmass = 1.0 / math.cos(ang.radian)
return az, alt, airmass
def best_star(lst, star_dict=None, catalog=None, lat=salt_lat):
"""Given an lst and a catalog of stars, determine the best star in the list.
The best star is determined to have an airmass less than 1.6, a
magnitude below 2.3, and an hour angle greater than 0.5.
This is specific to the current position of the timdimm in the ox-wagon
and should be updated if the telescope is moved
Parameters
----------
lst: string
The local sideral time
star_dict: dict
Dictionary with id as key, and containing name, ra, dec, vmag. ra/dec are
astropy.coordinate.angle objects
catalog: string
Name of catalog with stars in it. The catalog should have the format of
id, name (2 columns), rah, ram, ras, ded, dem, des, Vmag, B-V color, and
Spectral type. Only uses catalog if star_dict is None
Returns
-------
sid: string
key for object in star_dict
ra: astropy.coordinates.Angle
RA for best star
dec: astropy.coordinates.Angle
Declination for best star
Exceptions
----------
Raises ValueError if no star acceptable star exists
"""
if star_dict is None:
star_dict = load_catalog(catalog)
best_sid = None
best_vmag = 99
for k in star_dict.keys():
ra = star_dict[k][1]
dec = star_dict[k][2]
vmag = star_dict[k][3]
ha = Angle('%s hour' % lst) - ra
az, alt, airmass = calculate_airmass(ha, dec, lat=lat)
if ha.degree < 0.5 and 0 < airmass < 1.6 and vmag < 2.3 and vmag < best_vmag:
if not (alt.degree < 75.0 and 285.0 < az.degree < 300.0):
best_sid = k
best_vmag = vmag
if best_sid is None:
raise ValueError('No acceptable stars found')
return best_sid, star_dict[best_sid][1], star_dict[best_sid][2]
#lst = '12:30:30'
#print best_star(lst, catalog='star.lst')
if __name__=='__main__':
import sys
sid,ra,dec=best_star(sys.argv[1], catalog='star.lst')
print sid, ra, dec