uvd.antnums_to_baseline(j, i, attempt256=True) for i in range(0, len(aa))
    for j in range(i, len(aa)) if not j in ant_exclude and not i in ant_exclude
])

uvd.baseline_array.value = n.tile(bls, uvd.Ntimes.value)

#number of baselines
nbl = len(bls)
uvd.Nbls.value = nbl

#Antennas
uvd.antenna_indices.value = n.arange(1, Nants + 1, 1)  #1 indexed, not 0
uvd.antenna_names.value = ["ANT" + str(i) for i in uvd.antenna_indices.value]
uvd.antenna_positions.value = n.array([ant.pos for ant in aa])
uvd.ant_1_array.value, uvd.ant_2_array.value = \
          uvd.baseline_to_antnums(uvd.baseline_array.value)

#Time array:
## Format -- Repeat times for each baseline number.
tims = n.arange(uvd.Ntimes.value, dtype=n.float) * dt + tzero
uvd.time_array.value = n.sort(n.tile(
    tims, nbl))  #Should be of length Nblts, baseline fast time slow

uvd.Nblts.value = len(uvd.time_array.value)  #nbls * Ntimes

#Data array
uvd.data_array.value = n.zeros((nbl * uvd.Ntimes.value, uvd.Nspws.value,
                                uvd.Nfreqs.value, uvd.Npols.value),
                               dtype=n.complex)

t = tzero
Ejemplo n.º 2
0
bls = n.array([uvd.antnums_to_baseline(j,i,attempt256=True) 
       for i in range(0,len(aa)) 
       for j in range(i,len(aa)) if not j in ant_exclude and not i in ant_exclude ])

uvd.baseline_array.value = n.tile(bls, uvd.Ntimes.value)

#number of baselines
nbl = len(bls)
uvd.Nbls.value = nbl

#Antennas
uvd.antenna_indices.value = n.arange(1,Nants+1,1)       #1 indexed, not 0
uvd.antenna_names.value = ["ANT"+str(i) for i in uvd.antenna_indices.value]
uvd.antenna_positions.value = n.array([ant.pos for ant in aa])
uvd.ant_1_array.value, uvd.ant_2_array.value = \
          uvd.baseline_to_antnums(uvd.baseline_array.value)

#Delays
if uvd.instrument.value == 'MWA':
        uvd.extra_keywords.value['delays'] = '0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0'

t0 = tzero
#Data array
uvd.data_array.value = n.zeros((nbl * uvd.Ntimes.value, uvd.Nspws.value, uvd.Nfreqs.value,uvd.Npols.value), dtype=n.complex)

for m in range(int(nout)):
     #Time array:
     ## Format -- Repeat times for each baseline number.

     tims = n.arange(uvd.Ntimes.value, dtype=n.float) * dt + t0
     uvd.time_array.value = n.sort(n.tile(tims, nbl))    #Should be of length Nblts, baseline fast time slow
Ejemplo n.º 3
0
class TestUVmethods(unittest.TestCase):
    def setUp(self):
        self.uv_object = UVData()
        self.uv_object.Nants_telescope.value = 128
        self.testfile = '../data/day2_TDEM0003_10s_norx_1src_1spw.uvfits'

    def tearDown(self):
        del(self.uv_object)

    def test_bl2ij(self):
        self.assertEqual(self.uv_object.baseline_to_antnums(67585),
                         (0, 0))
        Nants = self.uv_object.Nants_telescope.value
        self.uv_object.Nants_telescope.value = 2049
        self.assertRaises(StandardError, self.uv_object.baseline_to_antnums, 67585)
        self.uv_object.Nants_telescope.value = Nants  # reset

    def test_ij2bl(self):
        self.assertEqual(self.uv_object.antnums_to_baseline(0, 0),
                         67585)
        self.assertEqual(self.uv_object.antnums_to_baseline(257, 256),
                         592130)
        # Check attempt256
        self.assertEqual(self.uv_object.antnums_to_baseline(0, 0, attempt256=True),
                         257)
        self.assertEqual(self.uv_object.antnums_to_baseline(257, 256,
                         attempt256=True), 592130)
        Nants = self.uv_object.Nants_telescope.value
        self.uv_object.Nants_telescope.value = 2049
        self.assertRaises(StandardError, self.uv_object.antnums_to_baseline, 0, 0)
        self.uv_object.Nants_telescope.value = Nants  # reset

    def test_data_equality(self):
        try:
            self.uv_object.check()
        except ValueError:
            self.uv_object.read(self.testfile, 'uvfits')
        self.assertEqual(self.uv_object, self.uv_object)
        self.uv_object2 = copy.deepcopy(self.uv_object)
        self.uv_object2.data_array.value[0, 0, 0, 0] += 1  # Force data to be not equal
        self.assertNotEqual(self.uv_object, self.uv_object2)
        # check class equality test
        self.assertNotEqual(self.uv_object, self.uv_object.data_array)

    def test_setXYZ_from_LatLon(self):
        self.uv_object.latitude.set_degrees(-26.7)
        self.uv_object.longitude.set_degrees(116.7)
        self.uv_object.altitude.value = None
        # Test that exception is raised.
        self.assertRaises(ValueError, self.uv_object.setXYZ_from_LatLon)
        self.uv_object.altitude.value = 377.8
        status = self.uv_object.setXYZ_from_LatLon()
        # Got reference by forcing http://www.oc.nps.edu/oc2902w/coord/llhxyz.htm
        # to give additional precision.
        ref_xyz = (-2562123.42683, 5094215.40141, -2848728.58869)
        out_xyz = (self.uv_object.x_telescope.value, self.uv_object.y_telescope.value,
                   self.uv_object.z_telescope.value)
        self.assertTrue(np.allclose(ref_xyz, out_xyz, rtol=0, atol=1e-3))

    def test_check(self):
        try:
            self.uv_object.check()
        except ValueError:
            self.uv_object.read(self.testfile, 'uvfits')
        self.assertTrue(self.uv_object.check())
        # Now break it in every way I can.
        # String cases
        units = self.uv_object.vis_units.value
        self.uv_object.vis_units.value = 1
        self.assertRaises(ValueError, self.uv_object.check)
        self.uv_object.vis_units.value = units  # reset it
        # Single value cases
        Nblts = self.uv_object.Nblts.value
        self.uv_object.Nblts.value = 4
        self.assertRaises(ValueError, self.uv_object.check)
        self.uv_object.Nblts.value = np.float(Nblts)
        self.assertRaises(ValueError, self.uv_object.check)
        self.uv_object.Nblts.value = Nblts  # reset
        # Array cases
        data = self.uv_object.data_array.value
        self.uv_object.data_array.value = np.array([4, 5, 6], dtype=np.complex64)
        self.assertRaises(ValueError, self.uv_object.check)
        self.uv_object.data_array.value = np.real(data)
        self.assertRaises(ValueError, self.uv_object.check)
        self.uv_object.data_array.value = data  # reset
        # List cases
        antenna_names = self.uv_object.antenna_names.value
        self.uv_object.antenna_names.value = [1] * self.uv_object.antenna_names.expected_size(self.uv_object)[0]
        self.assertRaises(ValueError, self.uv_object.check)
        self.uv_object.antenna_names.value = antenna_names  # reset
        # Sanity check
        uvws = self.uv_object.uvw_array.value
        self.uv_object.uvw_array.value = 1e-4 * np.ones_like(self.uv_object.uvw_array.value)
        self.assertRaises(ValueError, self.uv_object.check)
        self.uv_object.uvw_array.value = uvws
        self.assertTrue(self.uv_object.check())
Ejemplo n.º 4
0
class TestUVmethods(unittest.TestCase):
    def setUp(self):
        self.uv_object = UVData()
        self.uv_object.Nants_telescope.value = 128
        self.testfile = '../data/day2_TDEM0003_10s_norx_1src_1spw.uvfits'

    def tearDown(self):
        del (self.uv_object)

    def test_bl2ij(self):
        self.assertEqual(self.uv_object.baseline_to_antnums(67585), (0, 0))
        Nants = self.uv_object.Nants_telescope.value
        self.uv_object.Nants_telescope.value = 2049
        self.assertRaises(StandardError, self.uv_object.baseline_to_antnums,
                          67585)
        self.uv_object.Nants_telescope.value = Nants  # reset

    def test_ij2bl(self):
        self.assertEqual(self.uv_object.antnums_to_baseline(0, 0), 67585)
        self.assertEqual(self.uv_object.antnums_to_baseline(257, 256), 592130)
        # Check attempt256
        self.assertEqual(
            self.uv_object.antnums_to_baseline(0, 0, attempt256=True), 257)
        self.assertEqual(
            self.uv_object.antnums_to_baseline(257, 256, attempt256=True),
            592130)
        Nants = self.uv_object.Nants_telescope.value
        self.uv_object.Nants_telescope.value = 2049
        self.assertRaises(StandardError, self.uv_object.antnums_to_baseline, 0,
                          0)
        self.uv_object.Nants_telescope.value = Nants  # reset

    def test_data_equality(self):
        try:
            self.uv_object.check()
        except ValueError:
            self.uv_object.read(self.testfile, 'uvfits')
        self.assertEqual(self.uv_object, self.uv_object)
        self.uv_object2 = copy.deepcopy(self.uv_object)
        self.uv_object2.data_array.value[0, 0, 0,
                                         0] += 1  # Force data to be not equal
        self.assertNotEqual(self.uv_object, self.uv_object2)
        # check class equality test
        self.assertNotEqual(self.uv_object, self.uv_object.data_array)

    def test_setXYZ_from_LatLon(self):
        self.uv_object.latitude.set_degrees(-26.7)
        self.uv_object.longitude.set_degrees(116.7)
        self.uv_object.altitude.value = None
        # Test that exception is raised.
        self.assertRaises(ValueError, self.uv_object.setXYZ_from_LatLon)
        self.uv_object.altitude.value = 377.8
        status = self.uv_object.setXYZ_from_LatLon()
        # Got reference by forcing http://www.oc.nps.edu/oc2902w/coord/llhxyz.htm
        # to give additional precision.
        ref_xyz = (-2562123.42683, 5094215.40141, -2848728.58869)
        out_xyz = (self.uv_object.x_telescope.value,
                   self.uv_object.y_telescope.value,
                   self.uv_object.z_telescope.value)
        self.assertTrue(np.allclose(ref_xyz, out_xyz, rtol=0, atol=1e-3))

    def test_check(self):
        try:
            self.uv_object.check()
        except ValueError:
            self.uv_object.read(self.testfile, 'uvfits')
        self.assertTrue(self.uv_object.check())
        # Now break it in every way I can.
        # String cases
        units = self.uv_object.vis_units.value
        self.uv_object.vis_units.value = 1
        self.assertRaises(ValueError, self.uv_object.check)
        self.uv_object.vis_units.value = units  # reset it
        # Single value cases
        Nblts = self.uv_object.Nblts.value
        self.uv_object.Nblts.value = 4
        self.assertRaises(ValueError, self.uv_object.check)
        self.uv_object.Nblts.value = np.float(Nblts)
        self.assertRaises(ValueError, self.uv_object.check)
        self.uv_object.Nblts.value = Nblts  # reset
        # Array cases
        data = self.uv_object.data_array.value
        self.uv_object.data_array.value = np.array([4, 5, 6],
                                                   dtype=np.complex64)
        self.assertRaises(ValueError, self.uv_object.check)
        self.uv_object.data_array.value = np.real(data)
        self.assertRaises(ValueError, self.uv_object.check)
        self.uv_object.data_array.value = data  # reset
        # List cases
        antenna_names = self.uv_object.antenna_names.value
        self.uv_object.antenna_names.value = [
            1
        ] * self.uv_object.antenna_names.expected_size(self.uv_object)[0]
        self.assertRaises(ValueError, self.uv_object.check)
        self.uv_object.antenna_names.value = antenna_names  # reset
        # Sanity check
        uvws = self.uv_object.uvw_array.value
        self.uv_object.uvw_array.value = 1e-4 * np.ones_like(
            self.uv_object.uvw_array.value)
        self.assertRaises(ValueError, self.uv_object.check)
        self.uv_object.uvw_array.value = uvws
        self.assertTrue(self.uv_object.check())