Skip to content

Commit 7bb80b8

Browse files
committed
Add function to search IAU observatory codes
1 parent 4380bc4 commit 7bb80b8

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

astroquery/imcce/core.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
import warnings
55
from io import BytesIO
6+
import re
67

7-
from astropy.table import QTable, MaskedColumn
8+
from astropy.table import QTable, MaskedColumn, vstack
89
from astropy.io import ascii
910
from astropy.time import Time
1011
from astropy.io.votable import parse
@@ -41,6 +42,51 @@ def uri(self):
4142
"""
4243
return self._query_uri
4344

45+
def get_observatory_codes(self, restr=None):
46+
"""
47+
Get a dictionary of IAU observatory codes
48+
49+
Parameters
50+
----------
51+
restr : str
52+
String to compile into an re, if specified. Searches
53+
table for observatories whose names match
54+
55+
Examples
56+
--------
57+
>>> from astroquery.imcce import Miriade
58+
>>> obs = Miriade.get_observatory_codes('Green') # doctest: +REMOTE_DATA
59+
>>> print(obs) # doctest: +REMOTE_DATA
60+
<Table length=8>
61+
Code Long. cos sin Name
62+
str3 float64 float64 float64 str48
63+
---- --------- -------- --------- -------------------------------------------
64+
000 0.0 0.62411 0.77873 Greenwich
65+
256 280.16017 0.784451 0.61832 Green Bank
66+
912 288.2342 0.74769 0.66186 Carbuncle Hill Observatory, Greene
67+
967 358.9778 0.61508 0.78585 Greens Norton
68+
B34 33.7258 0.81748 0.57405 Green Island Observatory, Gecitkale
69+
H48 265.0139 0.79424 0.60565 PSU Greenbush Observatory, Pittsburg
70+
Q54 147.28772 0.73929 -0.671278 Harlingten Telescope, Greenhill Observatory
71+
Z54 358.92214 0.623422 0.779306 Greenmoor Observatory, Woodcote
72+
"""
73+
obs_codes_url = 'http://www.minorplanetcenter.net/iau/lists/ObsCodes.html'
74+
if not hasattr(self, '_observatory_codes'):
75+
self._observatory_codes = ascii.read(obs_codes_url,
76+
format='fixed_width',
77+
header_start=1,
78+
data_start=2,
79+
data_end=-1,
80+
col_starts=[0, 4, 13, 21, 30],
81+
col_ends=[3, 12, 20, 29, 100])
82+
83+
if restr is not None:
84+
R = re.compile(restr)
85+
return vstack([t for t in self._observatory_codes
86+
if R.search(t["Name"])])
87+
else:
88+
return self._observatory_codes
89+
4490
def get_ephemerides_async(self, targetname, objtype='asteroid',
4591
epoch=None, epoch_step='1d', epoch_nsteps=1,
4692
location='500', coordtype=1,

0 commit comments

Comments
 (0)