[1544] | 1 | import unittest
|
---|
| 2 | from asap import scantable, selector, rcParams
|
---|
| 3 | rcParams["verbose"] = False
|
---|
| 4 |
|
---|
| 5 | class ScantableTest(unittest.TestCase):
|
---|
| 6 | def setUp(self):
|
---|
| 7 |
|
---|
| 8 | self.st = scantable("data/MOPS.rpf", average=True)
|
---|
| 9 |
|
---|
| 10 | def test_init(self):
|
---|
| 11 | st = scantable("data/MOPS.rpf", average=False)
|
---|
| 12 | self.assertEqual(st.ncycle(), 32)
|
---|
| 13 | st = scantable("data/MOPS.rpf", average=True)
|
---|
| 14 | self.assertEqual(st.ncycle(), 2)
|
---|
| 15 | st = scantable("data/MOPS.rpf", unit="Jy")
|
---|
| 16 | self.assertEqual(st.get_fluxunit(), "Jy")
|
---|
| 17 | st = scantable("data/MOPS.rpf", unit="K")
|
---|
| 18 | self.assertEqual(st.get_fluxunit(), "K")
|
---|
| 19 | self.assertRaises(RuntimeError, scantable, "data/MOPS.rpf", unit="junk")
|
---|
| 20 | st = scantable(["data/MOPS.rpf","data/MOPS.rpf"], average=False)
|
---|
| 21 | self.assertEqual(st.nscan(), 4)
|
---|
| 22 |
|
---|
| 23 | def test_copy(self):
|
---|
| 24 | st = self.st.copy()
|
---|
| 25 | self.assertNotEqual(id(st), id(self.st))
|
---|
| 26 |
|
---|
| 27 | def test_drop_scan(self):
|
---|
| 28 | st = self.st.drop_scan([1])
|
---|
| 29 | self.assertEqual(st.nscan(), 1)
|
---|
| 30 |
|
---|
| 31 | def test_get_scan(self):
|
---|
| 32 | st = self.st.get_scan([1])
|
---|
| 33 | self.assertEqual(st.nscan(), 1)
|
---|
| 34 | st = self.st.get_scan("Orion_SiO_R")
|
---|
| 35 | self.assertEqual(st.get_sourcename()[-1], "Orion_SiO_R")
|
---|
| 36 | self.assertEqual(st.nscan(), 1)
|
---|
| 37 |
|
---|
| 38 | def test_get_spectrum(self):
|
---|
| 39 | spec = self.st.get_spectrum(0)
|
---|
| 40 | self.assertAlmostEqual(max(spec), 215.279830933)
|
---|
| 41 |
|
---|
| 42 | def test_get_mask(self):
|
---|
| 43 | spec = self.st.get_mask(0)
|
---|
| 44 | self.assertEqual(len(spec), 4096)
|
---|
| 45 |
|
---|
| 46 | def test_set_spectrum(self):
|
---|
| 47 | spec = [ 1.0 for i in range(self.st.nchan()) ]
|
---|
| 48 | self.st.set_spectrum(spec, 0)
|
---|
| 49 | spec1 = self.st.get_spectrum(0)
|
---|
| 50 | self.assertAlmostEqual(max(spec1), 1.0)
|
---|
| 51 |
|
---|
| 52 | def test_selection(self):
|
---|
| 53 | sel = selector()
|
---|
| 54 | sel.set_polarisations("YY")
|
---|
| 55 | self.st.set_selection(sel)
|
---|
| 56 | self.assertEqual(self.st.getpolnos(), (1,))
|
---|
| 57 | sel1 = self.st.get_selection()
|
---|
| 58 | self.assertEqual(sel1.get_pols(), [1])
|
---|
| 59 |
|
---|
| 60 | def test_stats(self):
|
---|
| 61 | stats = { 'min': 113.767166138,
|
---|
| 62 | 'max':215.279830933, 'sumsq':128759200.0,
|
---|
| 63 | 'sum':720262.375, 'mean':175.845306396,
|
---|
| 64 | 'var':513.95324707, 'stddev':22.6705360413,
|
---|
| 65 | 'avdev':16.3966751099, 'rms':177.300170898,
|
---|
| 66 | 'median':182.891845703}
|
---|
| 67 | for k,v in stats.iteritems():
|
---|
| 68 | sval = self.st.stats(stat=k)
|
---|
| 69 | self.assertAlmostEqual(sval[0], v)
|
---|
| 70 | msk = self.st.create_mask([0,100], [3900,4096])
|
---|
| 71 | self.assertAlmostEqual(self.st.stats("sum", msk)[0], 35216.87890625)
|
---|
| 72 |
|
---|
| 73 | def test_get_column_names(self):
|
---|
| 74 | cnames = ['SCANNO', 'CYCLENO', 'BEAMNO', 'IFNO',
|
---|
| 75 | 'POLNO', 'FREQ_ID', 'MOLECULE_ID', 'REFBEAMNO',
|
---|
| 76 | 'TIME', 'INTERVAL', 'SRCNAME', 'SRCTYPE',
|
---|
| 77 | 'FIELDNAME', 'SPECTRA', 'FLAGTRA', 'TSYS',
|
---|
| 78 | 'DIRECTION', 'AZIMUTH', 'ELEVATION',
|
---|
| 79 | 'PARANGLE', 'OPACITY', 'TCAL_ID', 'FIT_ID',
|
---|
| 80 | 'FOCUS_ID', 'WEATHER_ID', 'SRCVELOCITY',
|
---|
| 81 | 'SRCPROPERMOTION', 'SRCDIRECTION',
|
---|
| 82 | 'SCANRATE']
|
---|
| 83 | self.assertEqual(self.st.get_column_names(), cnames)
|
---|
| 84 |
|
---|
| 85 |
|
---|
| 86 | if __name__ == '__main__':
|
---|
| 87 | unittest.main()
|
---|
| 88 |
|
---|