Skip to content

Commit 419cbf9

Browse files
committed
Read telescope configuration from Oskar as well
Somehow missed this before, but this should fill in the remaining blanks. Also added a basic test case while we're at it.
1 parent 0ef5ddc commit 419cbf9

4 files changed

Lines changed: 58 additions & 15 deletions

File tree

‎arl/data_models.py‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,36 @@
55
#
66

77
from astropy.table import Table
8+
import numpy
89

910
class Configuration:
1011
""" Describe a Configuration
1112
1213
"""
1314

14-
def __init__(self):
15-
self.name = ''
16-
self.data = None
17-
self.location = None
15+
def __init__(self, name='', data=None, location=None,
16+
names="%s", xyz=None, mount="alt-az"):
17+
18+
# Defaults
19+
if data is None and not xyz is None:
20+
nants = xyz.shape[0]
21+
if isinstance(names, str):
22+
names = [names % ant for ant in range(nants)]
23+
if isinstance(mount, str):
24+
mount = numpy.repeat(mount, nants)
25+
data = Table( [ names, xyz, mount],
26+
names=['names', 'xyz', 'mount'])
27+
28+
self.name = name
29+
self.data = data
30+
self.location = location
1831

32+
@property
33+
def names(self): return self.data['names']
34+
@property
35+
def xyz(self): return self.data['xyz']
36+
@property
37+
def mount(self): return self.data['mount']
1938

2039
class GainTable:
2140
""" Gain table with data: time, antenna, gain[:,chan,pol] columns

‎arl/test_support.py‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,24 @@ def import_visibility_from_oskar(oskar_file: str, params={}) -> Visibility:
192192
ra,dec = oskar_vis.phase_centre()
193193
a1,a2 = oskar_vis.stations(flatten=True)
194194

195+
# Make configuration
196+
location = EarthLocation(lon = oskar_vis.telescope_lon,
197+
lat = oskar_vis.telescope_lat,
198+
height = oskar_vis.telescope_alt)
199+
antxyz = numpy.transpose([oskar_vis.station_x,
200+
oskar_vis.station_y,
201+
oskar_vis.station_z])
202+
config = Configuration(
203+
name = oskar_vis.telescope_path,
204+
location = location,
205+
xyz = antxyz
206+
)
207+
195208
# Construct visibilities
196209
return Visibility(
197210
frequency = [oskar_vis.frequency(i) for i in range(oskar_vis.num_channels)],
198-
phasecentre = SkyCoord(ICRS, ra=ra, dec=dec, unit=units.deg),
199-
configuration = None, # ?
211+
phasecentre = SkyCoord(frame=ICRS, ra=ra, dec=dec, unit=units.deg),
212+
configuration = config,
200213
uvw = numpy.transpose(oskar_vis.uvw(flatten=True)),
201214
time = oskar_vis.times(flatten=True),
202215
a1 = a1,

‎tests/test_datamodels.py‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from numpy.testing import assert_allclose
55

66
from arl.skymodel_operations import SkyComponent, create_skycomponent
7-
from arl.test_support import create_named_configuration
7+
from arl.test_support import create_named_configuration, import_visibility_from_oskar
88
from arl.image_operations import add_image, create_image_from_array, import_image_from_fits
99
from arl.skymodel_operations import create_skymodel_from_image, add_component_to_skymodel
1010
from arl.visibility_operations import Visibility, create_visibility, create_gaintable_from_array
@@ -62,12 +62,17 @@ def test_visibility(self):
6262
times = numpy.arange(-3.0, +3.0, 3.0 / 60.0) * numpy.pi / 12.0
6363
freq = numpy.arange(5e6, 150.0e6, 1e7)
6464
direction = SkyCoord('00h42m30s', '-41d12m00s', frame='icrs')
65-
vis = Visibility()
6665
vis = create_visibility(config, times, freq, weight=1.0, phasecentre=direction)
6766
print(vis.data)
6867
print(vis.frequency)
69-
assert len(numpy.unique(vis.data['time'])) == len(times)
68+
self.assertEqual(len(numpy.unique(vis.data['time'])), len(times))
7069

70+
def test_visibility_from_oskar(self):
71+
for oskar_file in ["./data/vis/vla_1src_6h/test_vla.vis",
72+
"./data/vis/vla_grid_6h/test_vla.vis"]:
73+
vis = import_visibility_from_oskar(oskar_file)
74+
self.assertEqual(len(numpy.unique(vis.a1))+1, len(vis.configuration.xyz))
75+
self.assertEqual(len(numpy.unique(vis.a2))+1, len(vis.configuration.xyz))
7176

7277
if __name__ == '__main__':
7378
unittest.main()

‎util/read_oskar_vis.py‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,15 @@ def __init__(self, file_name):
335335
self._phase_centre = vis_header[self.VisHeader.PhaseCentre][0]['data']
336336
self._cross_correlation = vis_header[self.VisHeader.FlagCrossCorrelation][0]['data']
337337
self._auto_correlation = vis_header[self.VisHeader.FlagAutoCorrelation][0]['data']
338+
339+
self.telescope_path = vis_header[self.VisHeader.TelescopePath][0]['data'].tostring().decode()[:-1]
340+
self.telescope_lon = vis_header[self.VisHeader.TelescopeLon][0]['data']
341+
self.telescope_lat = vis_header[self.VisHeader.TelescopeLat][0]['data']
342+
self.telescope_alt = vis_header[self.VisHeader.TelescopeAlt][0]['data']
343+
self.station_x = vis_header[self.VisHeader.StationX][0]['data']
344+
self.station_y = vis_header[self.VisHeader.StationY][0]['data']
345+
self.station_z = vis_header[self.VisHeader.StationZ][0]['data']
346+
338347
#
339348
# block_dims = self.data[self.Group.VisBlock][self.VisBlock.Dims]
340349
# for index in block_dims:
@@ -447,13 +456,10 @@ def stations(self, flatten=False):
447456
assert self._cross_correlation, \
448457
"Reading non-cross-correlation data not fully supported yet!"
449458

450-
# Order according to documentation is 0-1, 0-2, 0-3... 1-2,
451-
# 1-3... Auto-correlation isn't specified, but I guess we
452-
# simply add 0-0, 1-1 etc in the appropriate place.
453-
ac = 1-int(self._auto_correlation)
459+
# Order according to documentation is 0-1, 0-2, 0-3... 1-2, ...
454460
station1 = numpy.repeat(numpy.arange(self.num_stations),
455-
self.num_stations - ac - numpy.arange(self.num_stations))
456-
station2 = numpy.hstack([numpy.arange(start+ac, self.num_stations)
461+
self.num_stations-1 - numpy.arange(self.num_stations))
462+
station2 = numpy.hstack([numpy.arange(start+1, self.num_stations)
457463
for start in numpy.arange(self.num_stations)])
458464
# Tile in one or two dimensions depending on whether we want a
459465
# flat result

0 commit comments

Comments
 (0)