-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDFN_to_GFE_conversion.py
93 lines (68 loc) · 2.57 KB
/
DFN_to_GFE_conversion.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
# imports
# system packages
import os
# science packages
#import numpy as np
from astropy.table import Table
from astropy.time import Time
from astropy.coordinates import EarthLocation, AltAz, ICRS
import astropy.units as u
def RA_Dec_to_Alt_Az():
# TODO
pass
def Alt_Az_to_RA_Dec(az_array,
alt_array,
datetime_list,
obs_latitude,
obs_longitude,
obs_elevation):
station = EarthLocation(lat=obs_latitude*u.deg,
lon=obs_longitude*u.deg,
height=obs_elevation*u.meter)
# Datetime is ISO 8601 UTC format
datetime_array = Time(datetime_list)
# Convert horizontal to equatorial coordinates
horizontal_data = AltAz(az_array*u.deg,alt_array*u.deg,
obstime=datetime_array,location=station)
icrs_instance = ICRS()
equatorial_data = horizontal_data.transform_to(icrs_instance)
ra = equatorial_data.ra.value
dec = equatorial_data.dec.value
return ra, dec
def main(ifile):
t = Table.read(ifile)
ra, dec = Alt_Az_to_RA_Dec(t['azimuth'],
t['altitude'],
t['datetime'],
t.meta['obs_latitude'],
t.meta['obs_longitude'],
t.meta['obs_elevation'])
t['ra'] = ra
t['dec'] = dec
for c in ['JD']:
if c in t.colnames:
t.remove_column(c)
# Fix METADATA
t.meta['camera_id'] = t.meta['dfn_camera_codename']
t.meta['cx'] = t.meta['NAXIS1']
t.meta['cy'] = t.meta['NAXIS2']
t.meta['obs_az'] = 0.
t.meta['obs_ev'] = 90.
t.meta['fov_vert'] = 90.
t.meta['fov_horiz'] = 360.
t.meta['file_standard'] = 'GFE_1.2'
for k in ['NAXIS1', 'NAXIS2', 'dfn_camera_codename']:
if k in t.meta:
t.meta.pop(k)
o_fname = '_'.join([(t['datetime'][0][:19]).replace(':','_'),'DFN', t.meta['location'].replace('_','')]) + '.ecsv'
o_fname = os.path.join(os.path.dirname(ifile), o_fname)
# write the file to disk
t.write(o_fname, format='ascii.ecsv', delimiter=',', overwrite=False)
print(f'table has been written to {o_fname}')
if __name__ == "__main__":
import argparse
# parse arguments
parser = argparse.ArgumentParser(description='Convert DFN astrometry ECSV to GFE ECSV standard')
parser.add_argument("-i", "--ifile", type=str, required=True, help="input filename")
args = parser.parse_args()
main(args.ifile)