Changeset 1840 for trunk/test
- Timestamp:
- 08/03/10 18:34:32 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/test_scantable.py
r1824 r1840 1 import unittest 1 import sys 2 import os 3 import shutil 2 4 import datetime 3 from asap import scantable, selector, rcParams, mask_not, asaplog 5 from asap import scantable, selector, mask_not 6 from asap.logging import asaplog 4 7 asaplog.disable() 5 8 6 class ScantableTest(unittest.TestCase): 7 def setUp(self): 9 from nose.tools import * 10 11 def tempdir_setup(): 12 os.makedirs("test_temp") 13 14 def tempdir_teardown(): 15 shutil.rmtree("test_temp", True) 16 17 class TestScantable(object): 18 def setup(self): 8 19 s = scantable("data/MOPS.rpf", average=True) 9 20 sel = selector() … … 17 28 def test_init(self): 18 29 st = scantable("data/MOPS.rpf", average=False) 19 self.assertEqual(st.ncycle(), 32)30 assert_equal(st.ncycle(), 32) 20 31 st = scantable("data/MOPS.rpf", average=True) 21 self.assertEqual(st.ncycle(), 2)32 assert_equal(st.ncycle(), 2) 22 33 st = scantable("data/MOPS.rpf", unit="Jy") 23 self.assertEqual(st.get_fluxunit(), "Jy")34 assert_equal(st.get_fluxunit(), "Jy") 24 35 st = scantable("data/MOPS.rpf", unit="K") 25 self.assertEqual(st.get_fluxunit(), "K")26 self.assertRaises(RuntimeError, scantable, "data/MOPS.rpf", unit="junk")36 assert_equal(st.get_fluxunit(), "K") 37 assert_raises(RuntimeError, scantable, "data/MOPS.rpf", unit="junk") 27 38 st = scantable(["data/MOPS.rpf","data/MOPS.rpf"], average=False) 28 self.assertEqual(st.nscan(), 4)39 assert_equal(st.nscan(), 4) 29 40 30 41 def test_copy(self): 31 42 st = self.st.copy() 32 self.assertNotEqual(id(st), id(self.st))43 assert_not_equal(id(st), id(self.st)) 33 44 34 45 def test_drop_scan(self): 35 46 st = self.st.drop_scan([1]) 36 self.assertEqual(st.nscan(), 1)47 assert_equal(st.nscan(), 1) 37 48 38 49 def test_get_scan(self): 39 50 st = self.st.get_scan([1]) 40 self.assertEqual(st.nscan(), 1)51 assert_equal(st.nscan(), 1) 41 52 st = self.st.get_scan("Orion_SiO_R") 42 self.assertEqual(st.get_sourcename()[-1], "Orion_SiO_R")43 self.assertEqual(st.nscan(), 1)53 assert_equal(st.get_sourcename()[-1], "Orion_SiO_R") 54 assert_equal(st.nscan(), 1) 44 55 45 56 def test_get_spectrum(self): 46 57 spec = self.st.get_spectrum(0) 47 self.assertAlmostEqual(max(spec), 215.279830933)58 assert_almost_equal(max(spec), 215.279830933) 48 59 49 60 def test_get_mask(self): 50 61 spec = self.st.get_mask(0) 51 self.assertEqual(len(spec), 4096)62 assert_equal(len(spec), 4096) 52 63 53 64 def test_set_spectrum(self): … … 55 66 self.st.set_spectrum(spec, 0) 56 67 spec1 = self.st.get_spectrum(0) 57 self.assertAlmostEqual(max(spec1), 1.0)68 assert_almost_equal(max(spec1), 1.0) 58 69 59 70 def test_selection(self): … … 61 72 sel.set_polarisations("YY") 62 73 self.st.set_selection(sel) 63 self.assertEqual(self.st.getpolnos(), (1,))74 assert_equal(self.st.getpolnos(), (1,)) 64 75 sel1 = self.st.get_selection() 65 self.assertEqual(sel1.get_pols(), [1])76 assert_equal(sel1.get_pols(), [1]) 66 77 self.st.set_selection(pols="XX") 67 self.assertEqual(self.st.getpolnos(), (0,))78 assert_equal(self.st.getpolnos(), (0,)) 68 79 69 80 def test_stats(self): … … 76 87 for k,v in stats.iteritems(): 77 88 sval = self.st.stats(stat=k) 78 self.assertAlmostEqual(sval[0], v)89 assert_almost_equal(sval[0], v) 79 90 msk = self.st.create_mask([0,100], [3900,4096]) 80 self.assertAlmostEqual(self.st.stats("sum", msk)[0], 35216.87890625)91 assert_almost_equal(self.st.stats("sum", msk)[0], 35216.87890625) 81 92 82 93 def test_get_column_names(self): … … 90 101 'SRCPROPERMOTION', 'SRCDIRECTION', 91 102 'SCANRATE'] 92 self.assertEqual(self.st.get_column_names(), cnames)103 assert_equal(self.st.get_column_names(), cnames) 93 104 94 105 def test_get_tsys(self): 95 self.assertAlmostEqual(self.st.get_tsys()[0], 175.830429077)106 assert_almost_equal(self.st.get_tsys()[0], 175.830429077) 96 107 97 108 def test_get_time(self): 98 self.assertEqual(self.st.get_time(0), '2008/03/12/09:32:50')109 assert_equal(self.st.get_time(0), '2008/03/12/09:32:50') 99 110 dt = datetime.datetime(2008,3,12,9,32,50) 100 self.assertEqual(self.st.get_time(0, True), dt)111 assert_equal(self.st.get_time(0, True), dt) 101 112 102 113 def test_get_inttime(self): 103 self.assertAlmostEqual(self.st.get_inttime()[0], 30.720016479)114 assert_almost_equal(self.st.get_inttime()[0], 30.720016479) 104 115 105 116 def test_get_sourcename(self): 106 self.assertEqual(self.st.get_sourcename(0), 'Orion_SiO_R')107 self.assertEqual(self.st.get_sourcename(),117 assert_equal(self.st.get_sourcename(0), 'Orion_SiO_R') 118 assert_equal(self.st.get_sourcename(), 108 119 ['Orion_SiO_R', 'Orion_SiO_R', 109 120 'Orion_SiO', 'Orion_SiO']) 110 121 111 122 def test_get_azimuth(self): 112 self.assertAlmostEqual(self.st.get_azimuth()[0], 5.628767013)123 assert_almost_equal(self.st.get_azimuth()[0], 5.628767013) 113 124 114 125 def test_get_elevation(self): 115 self.assertAlmostEqual(self.st.get_elevation()[0], 1.01711678504)126 assert_almost_equal(self.st.get_elevation()[0], 1.01711678504) 116 127 117 128 def test_get_parangle(self): 118 self.assertAlmostEqual(self.st.get_parangle()[0], 2.5921990871)129 assert_almost_equal(self.st.get_parangle()[0], 2.5921990871) 119 130 120 131 def test_get_direction(self): 121 self.assertEqual(self.st.get_direction()[0], '05:35:14.5 -04.52.29.5')132 assert_equal(self.st.get_direction()[0], '05:35:14.5 -04.52.29.5') 122 133 123 134 def test_get_directionval(self): 124 135 dv = self.st.get_directionval()[0] 125 self.assertAlmostEqual(dv[0], 1.4627692699)126 self.assertAlmostEqual(dv[1], -0.0850824415)136 assert_almost_equal(dv[0], 1.4627692699) 137 assert_almost_equal(dv[1], -0.0850824415) 127 138 128 139 def test_unit(self): … … 130 141 self.st.set_unit('GHz') 131 142 self.st.set_unit('km/s') 132 self.assertRaises(RuntimeError, self.st.set_unit, 'junk')133 self.assertEquals(self.st.get_unit(), 'km/s')143 assert_raises(RuntimeError, self.st.set_unit, 'junk') 144 assert_equals(self.st.get_unit(), 'km/s') 134 145 135 146 def test_average_pol(self): 136 147 ap = self.st.average_pol() 137 self.assertEqual(ap.npol(), 1)148 assert_equal(ap.npol(), 1) 138 149 139 150 def test_drop_scan(self): 140 151 s0 = self.st.drop_scan(1) 141 self.assertEqual(s0.getscannos(), (0,))152 assert_equal(s0.getscannos(), (0,)) 142 153 s1 = self.st.drop_scan([0]) 143 self.assertEqual(s1.getscannos(), (1,))154 assert_equal(s1.getscannos(), (1,)) 144 155 145 156 def test_flag(self): … … 151 162 q0.flag(mask=mask_not(msk)) 152 163 q1.flag(mask=msk) 153 self.assertAlmostEqual(q0.stats(stat='max')[0], 95.62171936)154 self.assertAlmostEqual(q1.stats(stat='max')[0], 2.66563416)164 assert_almost_equal(q0.stats(stat='max')[0], 95.62171936) 165 assert_almost_equal(q1.stats(stat='max')[0], 2.66563416) 155 166 156 if __name__ == '__main__': 157 unittest.main() 167 168 @with_setup(tempdir_setup, tempdir_teardown) 169 def test_save(self): 170 fname = os.path.join("test_temp", 'scantable_test.%s') 171 formats = [(fname % 'sdfits', 'SDFITS', True), 172 (fname % 'ms', 'MS2', True), 173 (fname % 'class.fits', 'CLASS', False), 174 (fname % 'fits', 'FITS', False), 175 (fname % 'txt', 'ASCII', False), 176 ] 177 for format in formats: 178 yield self.save, format 179 180 def save(self, args): 181 fname = args[0] 182 self.st.save(fname, args[1], True) 183 if args[-1]: 184 s = scantable(fname) 185 ds = self.st - s 186 assert_equals(self.st.getpolnos(), s.getpolnos()) 187 assert_equals(self.st.getscannos(), s.getscannos()) 188 assert_equals(self.st.getifnos(), s.getifnos()) 189 assert_equals(self.st.getbeamnos(), s.getbeamnos()) 190 for spec in ds: 191 assert_almost_equals(sum(spec)/len(spec), 0.0, 5)
Note:
See TracChangeset
for help on using the changeset viewer.