/
test_fov_coord_transform.py
58 lines (46 loc) · 1.78 KB
/
test_fov_coord_transform.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
"""Coordinate transformation methods using PyEphem
http://rhodesmill.org/pyephem/
"""
import numpy as np
import ephem
from kapteyn.wcs import Projection
def approximate_nominal_to_altaz(nominal, horizon_center=(0, 0)):
"""Transform nominal coordinates to horizon coordinates.
nominal = (x, y) in meter
horizon_center = (az_center, alt_center) in deg
Returns: horizon = (az, alt) in deg
TODO: The following method of computing Alt / Az is only
an approximation. Implement and use a utility function
using the TAN FITS projection.
"""
x, y = np.asarray(nominal, dtype='float64')
az_center, alt_center = np.asarray(horizon_center, dtype='float64')
# Note: alt increases where x increases, az increases where y increases
az = az_center + np.degrees(np.tan(y)) / np.cos(np.radians(alt_center))
alt = alt_center + np.degrees(np.tan(x))
return az, alt
def nominal_to_altaz(nominal, horizon_center=(0, 0)):
"""Transform nominal coordinates to horizon coordinates.
nominal = (x, y) in meter
horizon_center = (az_center, alt_center) in deg
Returns: horizon = (az, alt) in deg
"""
x, y = np.asarray(nominal, dtype='float64')
az_center, alt_center = np.asarray(horizon_center, dtype='float64')
header = {'NAXIS': 2,
'NAXIS1': 100,
'NAXIS2': 100,
'CTYPE1': 'RA---TAN',
'CRVAL1': az_center,
'CRPIX1': 0,
'CUNIT1': 'deg',
'CDELT1': np.degrees(1),
'CTYPE2': 'DEC--TAN',
'CRVAL2': alt_center,
'CRPIX2': 0,
'CUNIT2': 'deg',
'CDELT2': np.degrees(1),
}
projection = Projection(header)
altaz = projection.toworld((y, x))
return altaz[0], altaz[1]