Skip to content
Snippets Groups Projects
Commit d047593f authored by Taya Snijder's avatar Taya Snijder
Browse files

added constants to several tests

parent 2aefcd37
No related branches found
No related tags found
1 merge request!470Resolve L2SS-1032 "Use constants in tests"
...@@ -7,6 +7,8 @@ import numpy ...@@ -7,6 +7,8 @@ import numpy
import numpy.testing import numpy.testing
import casacore import casacore
from tangostationcontrol.common.constants import MAX_ANTENNA, N_beamlets_ctrl
from tangostationcontrol.beam.delays import Delays from tangostationcontrol.beam.delays import Delays
from tangostationcontrol.test import base from tangostationcontrol.test import base
...@@ -179,8 +181,8 @@ class TestDelays(base.TestCase): ...@@ -179,8 +181,8 @@ class TestDelays(base.TestCase):
timestamp = datetime.datetime(2022, 3, 1, 0, 0, 0) # timestamp does not actually matter, but casacore doesn't know that. timestamp = datetime.datetime(2022, 3, 1, 0, 0, 0) # timestamp does not actually matter, but casacore doesn't know that.
d.set_measure_time(timestamp) d.set_measure_time(timestamp)
positions = numpy.array([[1,2,3]] * 96) positions = numpy.array([[1,2,3]] * MAX_ANTENNA)
directions = numpy.array([["J2000", "0deg", "0deg"]] * 488) directions = numpy.array([["J2000", "0deg", "0deg"]] * N_beamlets_ctrl)
count = 10 count = 10
before = time.monotonic_ns() before = time.monotonic_ns()
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
# See LICENSE.txt for more info. # See LICENSE.txt for more info.
from tangostationcontrol.common import baselines from tangostationcontrol.common import baselines
from tangostationcontrol.common.constants import MAX_INPUTS
from tangostationcontrol.test import base from tangostationcontrol.test import base
...@@ -24,7 +25,7 @@ class TestBaselines(base.TestCase): ...@@ -24,7 +25,7 @@ class TestBaselines(base.TestCase):
def test_baseline_indices(self): def test_baseline_indices(self):
""" Test whether baseline_from_index and baseline_index line up. """ """ Test whether baseline_from_index and baseline_index line up. """
for major in range(192): for major in range(MAX_INPUTS):
for minor in range(major + 1): for minor in range(major + 1):
idx = baselines.baseline_index(major, minor) idx = baselines.baseline_index(major, minor)
self.assertEqual((major, minor), baselines.baseline_from_index(idx), msg=f'baseline_index({major},{minor}) resulted in {idx}, and should match baseline_from_index({idx})') self.assertEqual((major, minor), baselines.baseline_from_index(idx), msg=f'baseline_index({major},{minor}) resulted in {idx}, and should match baseline_from_index({idx})')
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
# See LICENSE.txt for more info. # See LICENSE.txt for more info.
from tangostationcontrol.devices.sdp.beamlet import Beamlet from tangostationcontrol.devices.sdp.beamlet import Beamlet
from tangostationcontrol.common.constants import CLK_200_MHZ, CLK_160_MHZ, DEFAULT_SUBBAND
import numpy import numpy
import numpy.testing import numpy.testing
...@@ -79,7 +80,7 @@ class TestBeamletDevice(base.TestCase): ...@@ -79,7 +80,7 @@ class TestBeamletDevice(base.TestCase):
]) ])
beamlet_frequencies = numpy.array([ beamlet_frequencies = numpy.array([
[200e6, 200e6, 200e6, 200e6, 200e6] [CLK_200_MHZ, CLK_200_MHZ, CLK_200_MHZ, CLK_200_MHZ, CLK_200_MHZ]
]) ])
bf_weights = Beamlet._calculate_bf_weights(delays, beamlet_frequencies) bf_weights = Beamlet._calculate_bf_weights(delays, beamlet_frequencies)
...@@ -94,7 +95,7 @@ class TestBeamletDevice(base.TestCase): ...@@ -94,7 +95,7 @@ class TestBeamletDevice(base.TestCase):
def test_subband_frequencies(self): def test_subband_frequencies(self):
subbands = numpy.array([ subbands = numpy.array([
[0, 1, 102], [0, 1, DEFAULT_SUBBAND],
]) ])
nyquist_zones_0 = numpy.zeros(subbands.shape) nyquist_zones_0 = numpy.zeros(subbands.shape)
...@@ -103,29 +104,29 @@ class TestBeamletDevice(base.TestCase): ...@@ -103,29 +104,29 @@ class TestBeamletDevice(base.TestCase):
# for reference values, see https://proxy.lofar.eu/rtsm/tests/ # for reference values, see https://proxy.lofar.eu/rtsm/tests/
lba_frequencies = Beamlet._subband_frequencies(subbands, 160 * 1000000, nyquist_zones_0) lba_frequencies = Beamlet._subband_frequencies(subbands, CLK_160_MHZ, nyquist_zones_0)
self.assertAlmostEqual(lba_frequencies[0][0], 0.0000000e6) self.assertAlmostEqual(lba_frequencies[0][0], 0.0000000e6)
self.assertAlmostEqual(lba_frequencies[0][1], 0.1562500e6) self.assertAlmostEqual(lba_frequencies[0][1], 0.1562500e6)
self.assertAlmostEqual(lba_frequencies[0][2], 15.9375000e6) self.assertAlmostEqual(lba_frequencies[0][2], 15.9375000e6)
lba_frequencies = Beamlet._subband_frequencies(subbands, 200 * 1000000, nyquist_zones_0) lba_frequencies = Beamlet._subband_frequencies(subbands, CLK_200_MHZ, nyquist_zones_0)
self.assertAlmostEqual(lba_frequencies[0][0], 0.0000000e6) self.assertAlmostEqual(lba_frequencies[0][0], 0.0000000e6)
self.assertAlmostEqual(lba_frequencies[0][1], 0.1953125e6) self.assertAlmostEqual(lba_frequencies[0][1], 0.1953125e6)
self.assertAlmostEqual(lba_frequencies[0][2], 19.9218750e6) self.assertAlmostEqual(lba_frequencies[0][2], 19.9218750e6)
# Nyquist zone 1 is not used in 160 MHz # Nyquist zone 1 is not used in 160 MHz
hba_low_frequencies = Beamlet._subband_frequencies(subbands, 200 * 1000000, nyquist_zones_1) hba_low_frequencies = Beamlet._subband_frequencies(subbands, CLK_200_MHZ, nyquist_zones_1)
self.assertAlmostEqual(hba_low_frequencies[0][0], 100.0000000e6) self.assertAlmostEqual(hba_low_frequencies[0][0], 100.0000000e6)
self.assertAlmostEqual(hba_low_frequencies[0][1], 100.1953125e6) self.assertAlmostEqual(hba_low_frequencies[0][1], 100.1953125e6)
self.assertAlmostEqual(hba_low_frequencies[0][2], 119.9218750e6) self.assertAlmostEqual(hba_low_frequencies[0][2], 119.9218750e6)
hba_high_frequencies = Beamlet._subband_frequencies(subbands, 160 * 1000000, nyquist_zones_2) hba_high_frequencies = Beamlet._subband_frequencies(subbands, CLK_160_MHZ, nyquist_zones_2)
self.assertAlmostEqual(hba_high_frequencies[0][0], 160.0000000e6) self.assertAlmostEqual(hba_high_frequencies[0][0], 160.0000000e6)
self.assertAlmostEqual(hba_high_frequencies[0][1], 160.1562500e6) self.assertAlmostEqual(hba_high_frequencies[0][1], 160.1562500e6)
self.assertAlmostEqual(hba_high_frequencies[0][2], 175.9375000e6) self.assertAlmostEqual(hba_high_frequencies[0][2], 175.9375000e6)
hba_high_frequencies = Beamlet._subband_frequencies(subbands, 200 * 1000000, nyquist_zones_2) hba_high_frequencies = Beamlet._subband_frequencies(subbands, CLK_200_MHZ, nyquist_zones_2)
self.assertAlmostEqual(hba_high_frequencies[0][0], 200.0000000e6) self.assertAlmostEqual(hba_high_frequencies[0][0], 200.0000000e6)
self.assertAlmostEqual(hba_high_frequencies[0][1], 200.1953125e6) self.assertAlmostEqual(hba_high_frequencies[0][1], 200.1953125e6)
self.assertAlmostEqual(hba_high_frequencies[0][2], 219.9218750e6) self.assertAlmostEqual(hba_high_frequencies[0][2], 219.9218750e6)
......
...@@ -15,6 +15,7 @@ import numpy ...@@ -15,6 +15,7 @@ import numpy
# Internal regular imports # Internal regular imports
from tangostationcontrol.devices.sdp import digitalbeam from tangostationcontrol.devices.sdp import digitalbeam
from tangostationcontrol.common.constants import MAX_ANTENNA, N_beamlets_ctrl, N_xyz, N_pn
# Builtin test libraries # Builtin test libraries
from unittest import mock from unittest import mock
...@@ -40,20 +41,20 @@ class TestDigitalBeamDevice(device_base.DeviceTestCase): ...@@ -40,20 +41,20 @@ class TestDigitalBeamDevice(device_base.DeviceTestCase):
def test_apply_weights_disabled(self, m_proxy, m_compute, m_wait): def test_apply_weights_disabled(self, m_proxy, m_compute, m_wait):
"""Verify won't overwrite digitalbeam data if no input_selected""" """Verify won't overwrite digitalbeam data if no input_selected"""
input_data = numpy.array([["AZELGEO", "0deg", "90deg"]] * 488).flatten() input_data = numpy.array([["AZELGEO", "0deg", "90deg"]] * N_beamlets_ctrl).flatten()
current_data = numpy.array([[16384] * 5856] * 16) current_data = numpy.array([[16384] * 5856] * N_pn)
m_proxy.return_value = mock.Mock( m_proxy.return_value = mock.Mock(
read_attribute=mock.Mock( read_attribute=mock.Mock(
return_value=mock.Mock(value=copy.copy(current_data)) return_value=mock.Mock(value=copy.copy(current_data))
), ),
Antenna_Usage_Mask_R=numpy.array([0] * 96), Antenna_Usage_Mask_R=numpy.array([0] * MAX_ANTENNA),
Antenna_Field_Reference_ITRF_R=mock.MagicMock(), Antenna_Field_Reference_ITRF_R=mock.MagicMock(),
HBAT_reference_ITRF_R=numpy.array([[0] * 3] * 96) HBAT_reference_ITRF_R=numpy.array([[0] * N_xyz] * MAX_ANTENNA)
) )
new_data = numpy.array( new_data = numpy.array(
[[16384] * 2928 + [0] * 2928] * 16 [[16384] * 2928 + [0] * 2928] * N_pn
) )
m_compute.return_value = copy.copy(new_data) m_compute.return_value = copy.copy(new_data)
...@@ -62,7 +63,7 @@ class TestDigitalBeamDevice(device_base.DeviceTestCase): ...@@ -62,7 +63,7 @@ class TestDigitalBeamDevice(device_base.DeviceTestCase):
) as proxy: ) as proxy:
proxy.initialise() proxy.initialise()
proxy.Tracking_enabled_RW = False proxy.Tracking_enabled_RW = False
proxy.input_select_RW = numpy.array([[False] * 488] * 96) proxy.input_select_RW = numpy.array([[False] * N_beamlets_ctrl] * MAX_ANTENNA)
proxy.set_pointing(input_data) proxy.set_pointing(input_data)
...@@ -78,20 +79,20 @@ class TestDigitalBeamDevice(device_base.DeviceTestCase): ...@@ -78,20 +79,20 @@ class TestDigitalBeamDevice(device_base.DeviceTestCase):
def test_apply_weights_enabled(self, m_proxy, m_compute, m_wait): def test_apply_weights_enabled(self, m_proxy, m_compute, m_wait):
"""Verify can overwrite digitalbeam data if input_selected""" """Verify can overwrite digitalbeam data if input_selected"""
input_data = numpy.array([["AZELGEO", "0deg", "90deg"]] * 488).flatten() input_data = numpy.array([["AZELGEO", "0deg", "90deg"]] * N_beamlets_ctrl).flatten()
current_data = numpy.array([[16384] * 5856] * 16) current_data = numpy.array([[16384] * 5856] * N_pn)
m_proxy.return_value = mock.Mock( m_proxy.return_value = mock.Mock(
read_attribute=mock.Mock( read_attribute=mock.Mock(
return_value=mock.Mock(value=current_data) return_value=mock.Mock(value=current_data)
), ),
Antenna_Usage_Mask_R=numpy.array([0] * 96), Antenna_Usage_Mask_R=numpy.array([0] * MAX_ANTENNA),
Antenna_Field_Reference_ITRF_R=mock.MagicMock(), Antenna_Field_Reference_ITRF_R=mock.MagicMock(),
HBAT_reference_ITRF_R=numpy.array([[0] * 3] * 96) HBAT_reference_ITRF_R=numpy.array([[0] * N_xyz] * MAX_ANTENNA)
) )
new_data = numpy.array( new_data = numpy.array(
[[16384] * 2928 + [0] * 2928] * 16 [[16384] * 2928 + [0] * 2928] * N_pn
) )
m_compute.return_value = copy.copy(new_data) m_compute.return_value = copy.copy(new_data)
...@@ -100,7 +101,7 @@ class TestDigitalBeamDevice(device_base.DeviceTestCase): ...@@ -100,7 +101,7 @@ class TestDigitalBeamDevice(device_base.DeviceTestCase):
) as proxy: ) as proxy:
proxy.initialise() proxy.initialise()
proxy.Tracking_enabled_RW = False proxy.Tracking_enabled_RW = False
proxy.input_select_RW = numpy.array([[True] * 488] * 96) proxy.input_select_RW = numpy.array([[True] * N_beamlets_ctrl] * MAX_ANTENNA)
proxy.set_pointing(input_data) proxy.set_pointing(input_data)
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
from tango.test_context import DeviceTestContext from tango.test_context import DeviceTestContext
from tangostationcontrol.devices import recv from tangostationcontrol.devices import recv
from tangostationcontrol.common.constants import MAX_ANTENNA, N_elements
import numpy import numpy
...@@ -28,7 +29,7 @@ class TestRecvDevice(device_base.DeviceTestCase): ...@@ -28,7 +29,7 @@ class TestRecvDevice(device_base.DeviceTestCase):
def test_calculate_HBAT_bf_delay_steps(self): def test_calculate_HBAT_bf_delay_steps(self):
"""Verify HBAT beamforming calculations are correctly executed""" """Verify HBAT beamforming calculations are correctly executed"""
with DeviceTestContext(recv.RECV, properties=self.RECV_PROPERTIES, process=True) as proxy: with DeviceTestContext(recv.RECV, properties=self.RECV_PROPERTIES, process=True) as proxy:
delays = numpy.random.rand(96,16).flatten() delays = numpy.random.rand(MAX_ANTENNA,N_elements).flatten()
HBAT_bf_delay_steps = proxy.calculate_HBAT_bf_delay_steps(delays) HBAT_bf_delay_steps = proxy.calculate_HBAT_bf_delay_steps(delays)
self.assertEqual(3072, len(HBAT_bf_delay_steps)) # 96x32=3072 self.assertEqual(3072, len(HBAT_bf_delay_steps)) # 96x32=3072
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment