def test_jones_num_funcs_x_orientation(): """ Test utility functions to convert between jones polarization strings and numbers with x_orientation""" jnums = [-8, -7, -6, -5, -4, -3, -2, -1] x_orient1 = 'east' jstr = ['Jne', 'Jen', 'Jnn', 'Jee', 'Jlr', 'Jrl', 'Jll', 'Jrr'] assert jnums == uvutils.jstr2num(jstr, x_orientation=x_orient1) assert jstr == uvutils.jnum2str(jnums, x_orientation=x_orient1) # Check shorthands jstr = ['ne', 'en', 'nn', 'n', 'ee', 'e', 'lr', 'rl', 'll', 'l', 'rr', 'r'] jnums = [-8, -7, -6, -6, -5, -5, -4, -3, -2, -2, -1, -1] assert jnums == uvutils.jstr2num(jstr, x_orientation=x_orient1) # Check individuals assert -6 == uvutils.jstr2num('jnn', x_orientation=x_orient1) assert 'Jen' == uvutils.jnum2str(-7, x_orientation=x_orient1) # Check errors pytest.raises(KeyError, uvutils.jstr2num, 'foo', x_orientation=x_orient1) pytest.raises(ValueError, uvutils.jstr2num, 1, x_orientation=x_orient1) pytest.raises(ValueError, uvutils.jnum2str, 7.3, x_orientation=x_orient1) # check parse method assert uvutils.parse_jpolstr('e', x_orientation=x_orient1) == 'Jee' assert uvutils.parse_jpolstr('x', x_orientation=x_orient1) == 'Jee' assert uvutils.parse_jpolstr('y', x_orientation=x_orient1) == 'Jnn' assert uvutils.parse_jpolstr('en', x_orientation=x_orient1) == 'Jen' assert uvutils.parse_jpolstr('NE', x_orientation=x_orient1) == 'Jne' jnums = [-8, -7, -6, -5, -4, -3, -2, -1] x_orient2 = 'north' jstr = ['Jen', 'Jne', 'Jee', 'Jnn', 'Jlr', 'Jrl', 'Jll', 'Jrr'] assert jnums == uvutils.jstr2num(jstr, x_orientation=x_orient2) assert jstr == uvutils.jnum2str(jnums, x_orientation=x_orient2) # Check shorthands jstr = ['en', 'ne', 'ee', 'e', 'nn', 'n', 'lr', 'rl', 'll', 'l', 'rr', 'r'] jnums = [-8, -7, -6, -6, -5, -5, -4, -3, -2, -2, -1, -1] assert jnums == uvutils.jstr2num(jstr, x_orientation=x_orient2) # Check individuals assert -6 == uvutils.jstr2num('jee', x_orientation=x_orient2) assert 'Jne' == uvutils.jnum2str(-7, x_orientation=x_orient2) # Check errors pytest.raises(KeyError, uvutils.jstr2num, 'foo', x_orientation=x_orient2) pytest.raises(ValueError, uvutils.jstr2num, 1, x_orientation=x_orient2) pytest.raises(ValueError, uvutils.jnum2str, 7.3, x_orientation=x_orient2) # check parse method assert uvutils.parse_jpolstr('e', x_orientation=x_orient2) == 'Jee' assert uvutils.parse_jpolstr('x', x_orientation=x_orient2) == 'Jnn' assert uvutils.parse_jpolstr('y', x_orientation=x_orient2) == 'Jee' assert uvutils.parse_jpolstr('en', x_orientation=x_orient2) == 'Jen' assert uvutils.parse_jpolstr('NE', x_orientation=x_orient2) == 'Jne' # check warnings for non-recognized x_orientation assert uvtest.checkWarnings(uvutils.jstr2num, ['x'], {'x_orientation': 'foo'}, message='x_orientation not recognized') == -5 assert uvtest.checkWarnings( uvutils.jnum2str, [-6], {'x_orientation': 'foo'}, message='x_orientation not recognized') == 'Jyy'
def test_load_cal(self): with pytest.raises(TypeError): io.load_cal(1.0) fname = os.path.join(DATA_PATH, "test_input/zen.2457698.40355.xx.HH.uvc.omni.calfits") gains, flags = io.load_cal(fname) assert len(gains.keys()) == 18 assert len(flags.keys()) == 18 cal = UVCal() cal.read_calfits(fname) gains, flags = io.load_cal(cal) assert len(gains.keys()) == 18 assert len(flags.keys()) == 18 with pytest.raises(TypeError): io.load_cal([fname, cal]) fname_xx = os.path.join(DATA_PATH, "test_input/zen.2457698.40355.xx.HH.uvc.omni.calfits") fname_yy = os.path.join(DATA_PATH, "test_input/zen.2457698.40355.yy.HH.uvc.omni.calfits") gains, flags, quals, total_qual, ants, freqs, times, pols = io.load_cal([fname_xx, fname_yy], return_meta=True) assert len(gains.keys()) == 36 assert len(flags.keys()) == 36 assert len(quals.keys()) == 36 assert freqs.shape == (1024,) assert times.shape == (3,) assert sorted(pols) == [parse_jpolstr('jxx', x_orientation=cal.x_orientation), parse_jpolstr('jyy', x_orientation=cal.x_orientation)] cal_xx, cal_yy = UVCal(), UVCal() cal_xx.read_calfits(fname_xx) cal_yy.read_calfits(fname_yy) gains, flags, quals, total_qual, ants, freqs, times, pols = io.load_cal([cal_xx, cal_yy], return_meta=True) assert len(gains.keys()) == 36 assert len(flags.keys()) == 36 assert len(quals.keys()) == 36 assert freqs.shape == (1024,) assert times.shape == (3,) assert sorted(pols) == [parse_jpolstr('jxx', x_orientation=cal_xx.x_orientation), parse_jpolstr('jyy', x_orientation=cal_yy.x_orientation)]
def test_pol_funcs(): """ Test utility functions to convert between polarization strings and numbers """ pol_nums = [-8, -7, -6, -5, -4, -3, -2, -1, 1, 2, 3, 4] pol_str = [ 'yx', 'xy', 'yy', 'xx', 'lr', 'rl', 'll', 'rr', 'pI', 'pQ', 'pU', 'pV' ] nt.assert_equal(pol_nums, uvutils.polstr2num(pol_str)) nt.assert_equal(pol_str, uvutils.polnum2str(pol_nums)) # Check individuals nt.assert_equal(-6, uvutils.polstr2num('YY')) nt.assert_equal('pV', uvutils.polnum2str(4)) # Check errors nt.assert_raises(KeyError, uvutils.polstr2num, 'foo') nt.assert_raises(ValueError, uvutils.polstr2num, 1) nt.assert_raises(ValueError, uvutils.polnum2str, 7.3) # Check parse nt.assert_equal(uvutils.parse_polstr("xX"), 'xx') nt.assert_equal(uvutils.parse_polstr("XX"), 'xx') nt.assert_equal(uvutils.parse_polstr('i'), 'pI') nt.assert_equal(uvutils.parse_jpolstr('x'), 'Jxx') nt.assert_equal(uvutils.parse_jpolstr('xy'), 'Jxy') nt.assert_equal(uvutils.parse_jpolstr('XY'), 'Jxy')
def test_jones_num_funcs(): """ Test utility functions to convert between jones polarization strings and numbers """ jnums = [-8, -7, -6, -5, -4, -3, -2, -1] jstr = ['Jyx', 'Jxy', 'Jyy', 'Jxx', 'Jlr', 'Jrl', 'Jll', 'Jrr'] assert jnums == uvutils.jstr2num(jstr) assert jstr, uvutils.jnum2str(jnums) # Check shorthands jstr = ['yx', 'xy', 'yy', 'y', 'xx', 'x', 'lr', 'rl', 'll', 'l', 'rr', 'r'] jnums = [-8, -7, -6, -6, -5, -5, -4, -3, -2, -2, -1, -1] assert jnums == uvutils.jstr2num(jstr) # Check individuals assert -6 == uvutils.jstr2num('jyy') assert 'Jxy' == uvutils.jnum2str(-7) # Check errors pytest.raises(KeyError, uvutils.jstr2num, 'foo') pytest.raises(ValueError, uvutils.jstr2num, 1) pytest.raises(ValueError, uvutils.jnum2str, 7.3) # check parse method assert uvutils.parse_jpolstr('x') == 'Jxx' assert uvutils.parse_jpolstr('xy') == 'Jxy' assert uvutils.parse_jpolstr('XY') == 'Jxy'
def test_read(self): # test one file with both polarizations and a non-None total quality array hc = HERACal(self.fname_both) gains, flags, quals, total_qual = hc.read() uvc = UVCal() uvc.read_calfits(self.fname_both) np.testing.assert_array_equal(uvc.gain_array[0, 0, :, :, 0].T, gains[9, parse_jpolstr('jxx', x_orientation=hc.x_orientation)]) np.testing.assert_array_equal(uvc.flag_array[0, 0, :, :, 0].T, flags[9, parse_jpolstr('jxx', x_orientation=hc.x_orientation)]) np.testing.assert_array_equal(uvc.quality_array[0, 0, :, :, 0].T, quals[9, parse_jpolstr('jxx', x_orientation=hc.x_orientation)]) np.testing.assert_array_equal(uvc.total_quality_array[0, :, :, 0].T, total_qual[parse_jpolstr('jxx', x_orientation=hc.x_orientation)]) np.testing.assert_array_equal(np.unique(uvc.freq_array), hc.freqs) np.testing.assert_array_equal(np.unique(uvc.time_array), hc.times) assert hc.pols == [parse_jpolstr('jxx', x_orientation=hc.x_orientation), parse_jpolstr('jyy', x_orientation=hc.x_orientation)] assert set([ant[0] for ant in hc.ants]) == set(uvc.ant_array) # test list loading hc = HERACal([self.fname_xx, self.fname_yy]) gains, flags, quals, total_qual = hc.read() assert len(gains.keys()) == 36 assert len(flags.keys()) == 36 assert len(quals.keys()) == 36 assert hc.freqs.shape == (1024,) assert hc.times.shape == (3,) assert sorted(hc.pols) == [parse_jpolstr('jxx', x_orientation=hc.x_orientation), parse_jpolstr('jyy', x_orientation=hc.x_orientation)]