Skip to content

Commit 00dbd1a

Browse files
committed
Keep Telescope EarthLocation as single attribute.
1 parent 19315b2 commit 00dbd1a

2 files changed

Lines changed: 40 additions & 23 deletions

File tree

‎src/fastimgproto/telescope/base.py‎

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ class Telescope(object):
3434
)
3535
3636
Attributes:
37-
latitude (astropy.coordinates.Latitude): Latitude of array
38-
longitude (astropy.coordinates.Longitude): Longitude of array
37+
centre (astropy.coordinates.EarthLocation): Centre of the array
3938
ant_labels (list): Antennae labels
4039
ant_itrf_xyz (numpy.ndarray): Antennae xyz_positions in ITRF frame.
4140
[dtype: ``np.float_``, shape ``(n_antennae,3,)``.
@@ -46,8 +45,7 @@ class Telescope(object):
4645
baseline_labels (list): Baseline labels.
4746
(See also :func:`generate_baselines_and_labels`)
4847
"""
49-
latitude = attrib(validator=attr.validators.instance_of(Latitude))
50-
longitude = attrib(validator=attr.validators.instance_of(Longitude))
48+
centre = attrib(validator=attr.validators.instance_of(EarthLocation))
5149
ant_labels = attrib(default=None)
5250
ant_itrf_xyz = attrib(default=None, validator=_validator_optional_ndarray)
5351
ant_local_xyz = attrib(default=None, validator=_validator_optional_ndarray)
@@ -62,6 +60,21 @@ def __attrs_post_init__(self):
6260
self.ant_local_xyz, self.ant_labels
6361
)
6462

63+
@property
64+
def lat(self):
65+
lon, lat, height = self.centre.to_geodetic()
66+
return lat
67+
68+
@property
69+
def lon(self):
70+
lon, lat, height = self.centre.to_geodetic()
71+
return lon
72+
73+
@property
74+
def height(self):
75+
lon, lat, height = self.centre.to_geodetic()
76+
return height
77+
6578
@staticmethod
6679
def from_itrf(ant_itrf_xyz, ant_labels):
6780
"""
@@ -80,20 +93,20 @@ def from_itrf(ant_itrf_xyz, ant_labels):
8093
Telescope: A telescope class with the given array co-ords.
8194
"""
8295
mean_posn = np.mean(ant_itrf_xyz, axis=0)
83-
lon, lat, alt = EarthLocation.from_geocentric(mean_posn[0],
84-
mean_posn[1],
85-
mean_posn[2],
86-
unit=u.m,
87-
).to_geodetic()
96+
centre = EarthLocation.from_geocentric(mean_posn[0],
97+
mean_posn[1],
98+
mean_posn[2],
99+
unit=u.m,
100+
)
101+
lon, lat, height = centre.to_geodetic()
88102

89103
mean_subbed_itrf = ant_itrf_xyz - mean_posn
90104

91105
rotation = z_rotation_matrix(lon)
92106
ant_local_xyz = np.dot(rotation, mean_subbed_itrf.T).T
93107

94108
return Telescope(
95-
latitude=lat,
96-
longitude=lon,
109+
centre=centre,
97110
ant_labels=ant_labels,
98111
ant_itrf_xyz=ant_itrf_xyz,
99112
ant_local_xyz=ant_local_xyz,
@@ -124,7 +137,7 @@ def lst(self, time):
124137
an angle-Quantity.
125138
"""
126139
return time.sidereal_time('apparent',
127-
longitude=self.longitude)
140+
longitude=self.lon)
128141

129142
def next_transit(self, target_ra, start_time, ):
130143
"""
@@ -140,7 +153,7 @@ def next_transit(self, target_ra, start_time, ):
140153
astropy.time.Time: Approximate time of the next transit
141154
142155
"""
143-
return time_of_next_transit(observer_longitude=self.longitude,
156+
return time_of_next_transit(observer_longitude=self.lon,
144157
target_ra=target_ra,
145158
start_time=start_time)
146159

@@ -213,7 +226,7 @@ def uvw_tracking_skycoord(self, pointing_centre, obs_times,
213226
"""
214227
n_baselines = len(self.baseline_local_xyz)
215228
uvw_array = np.zeros((len(obs_times) * n_baselines, 3),
216-
dtype=np.float_)*self.baseline_local_xyz.unit
229+
dtype=np.float_) * self.baseline_local_xyz.unit
217230

218231
for idx, time in enumerate(obs_times):
219232
lha = self.lha(pointing_centre.ra, time)

‎tests/test_telescope/test_telescope.py‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from __future__ import print_function
22
import numpy as np
33
import astropy.units as u
4-
from astropy.coordinates import Latitude, Longitude, SkyCoord
4+
from astropy.coordinates import (
5+
EarthLocation, Latitude, Longitude, SkyCoord,
6+
)
57
from astropy.time import Time
68
from fastimgproto.telescope import Telescope
79
from fastimgproto.telescope.base import parse_itrf_ascii_to_xyz_and_labels
@@ -28,6 +30,9 @@ def test_xyz_antennae_to_uvw_baselines():
2830
Y (Local East) -> U (LHA - 6h)
2931
Z (Celestial North) -> V( declination of (pi/2 - source_dec) )
3032
"""
33+
centre = EarthLocation.from_geodetic(
34+
Longitude(0 * u.deg), Latitude(0 * u.deg))
35+
3136
ant_local_xyz = np.array([
3237
[0, 0, 0], # Origin
3338
[0, 1, 0], # 1-East
@@ -45,11 +50,11 @@ def test_xyz_antennae_to_uvw_baselines():
4550
[-1., 1., 0.]] # 1-east,1-north
4651
) * u.m
4752

48-
tel = Telescope(latitude=Latitude(0 * u.deg),
49-
longitude=Longitude(0 * u.deg),
50-
ant_labels=ant_labels,
51-
ant_local_xyz=ant_local_xyz
52-
)
53+
tel = Telescope(
54+
centre=centre,
55+
ant_labels=ant_labels,
56+
ant_local_xyz=ant_local_xyz
57+
)
5358
# print(tel.baseline_labels)
5459
# print(tel.baseline_local_xyz)
5560

@@ -67,7 +72,7 @@ def test_uvw_tracking_skyposn():
6772
Check UVW calculations for Time+RA+Dec vs LHA+Dec produce consistent results
6873
"""
6974
telescope = Meerkat()
70-
azimuth_target = SkyCoord(ra=0 * u.deg, dec=telescope.latitude)
75+
azimuth_target = SkyCoord(ra=0 * u.deg, dec=telescope.lat)
7176

7277
t0 = Time('2017-01-01 12:00:00', format='iso', scale='utc')
7378
tt = telescope.next_transit(azimuth_target.ra, t0)
@@ -91,10 +96,9 @@ def test_uvw_tracking_skyposn():
9196
assert flattened_uvw_array.to(u.m)
9297
assert len(flattened_uvw_array) == n_total_baselines
9398

94-
9599
concat_array = np.concatenate(list(uvw_by_tracking.values()))
96100
# Work around np.concat returning uninitialsed units:
97101
# http://docs.astropy.org/en/stable/known_issues.html#id6
98102
concat_array = concat_array.value * uvw_by_lha.unit
99103

100-
assert (flattened_uvw_array ==concat_array).all()
104+
assert (flattened_uvw_array == concat_array).all()

0 commit comments

Comments
 (0)