-
Notifications
You must be signed in to change notification settings - Fork 0
/
metadata.py
46 lines (40 loc) · 1.43 KB
/
metadata.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
from astropy.io import fits
from astropy.coordinates import SkyCoord
class ObservingMetadata:
def __init__(self, src_name, telescope, frontend, backend, observer, location):
self.src_name = src_name
self.telescope = telescope
self.frontend = frontend
self.backend = backend
self.observer = observer
self.location = location
@classmethod
def default(cls):
return cls(
src_name="simulated-pulsar",
telescope="fake-telescope",
frontend="fake-receiver",
backend="BOGUS",
observer="cycspec-simulator",
location=SkyCoord(0, 0, unit="degree"),
)
@classmethod
def from_file(cls, filename):
hdul = fits.open(filename)
header = hdul['PRIMARY'].header
src_name = header['SRC_NAME']
telescope = header['TELESCOP']
frontend = header['FRONTEND']
backend = header['BACKEND']
observer = header['OBSERVER']
ra = header['RA']
dec = header['DEC']
hdul.close()
location = SkyCoord(ra, dec, unit=("hourangle", "degree"))
return cls(src_name, telescope, frontend, backend, observer, location)
@property
def ra_str(self):
return self.location.ra.to_string(unit="hourangle", sep=':', precision=4)
@property
def dec_str(self):
return self.location.dec.to_string(unit="degree", sep=':', precision=4)