source: trunk/test/test_scantable.py@ 1772

Last change on this file since 1772 was 1725, checked in by Malte Marquarding, 15 years ago

Finishing touches to opacity calculations, docs, plotting and model

File size: 5.5 KB
Line 
1import unittest
2import datetime
3from asap import scantable, selector, rcParams, mask_not
4rcParams["verbose"] = False
5
6class ScantableTest(unittest.TestCase):
7 def setUp(self):
8
9 self.st = scantable("data/MOPS.rpf", average=True)
10 restfreqs = [86.243] # 13CO-1/0, SiO the two IF
11 self.st.set_restfreqs(restfreqs,"GHz")
12
13 def test_init(self):
14 st = scantable("data/MOPS.rpf", average=False)
15 self.assertEqual(st.ncycle(), 32)
16 st = scantable("data/MOPS.rpf", average=True)
17 self.assertEqual(st.ncycle(), 2)
18 st = scantable("data/MOPS.rpf", unit="Jy")
19 self.assertEqual(st.get_fluxunit(), "Jy")
20 st = scantable("data/MOPS.rpf", unit="K")
21 self.assertEqual(st.get_fluxunit(), "K")
22 self.assertRaises(RuntimeError, scantable, "data/MOPS.rpf", unit="junk")
23 st = scantable(["data/MOPS.rpf","data/MOPS.rpf"], average=False)
24 self.assertEqual(st.nscan(), 4)
25
26 def test_copy(self):
27 st = self.st.copy()
28 self.assertNotEqual(id(st), id(self.st))
29
30 def test_drop_scan(self):
31 st = self.st.drop_scan([1])
32 self.assertEqual(st.nscan(), 1)
33
34 def test_get_scan(self):
35 st = self.st.get_scan([1])
36 self.assertEqual(st.nscan(), 1)
37 st = self.st.get_scan("Orion_SiO_R")
38 self.assertEqual(st.get_sourcename()[-1], "Orion_SiO_R")
39 self.assertEqual(st.nscan(), 1)
40
41 def test_get_spectrum(self):
42 spec = self.st.get_spectrum(0)
43 self.assertAlmostEqual(max(spec), 215.279830933)
44
45 def test_get_mask(self):
46 spec = self.st.get_mask(0)
47 self.assertEqual(len(spec), 4096)
48
49 def test_set_spectrum(self):
50 spec = [ 1.0 for i in range(self.st.nchan()) ]
51 self.st.set_spectrum(spec, 0)
52 spec1 = self.st.get_spectrum(0)
53 self.assertAlmostEqual(max(spec1), 1.0)
54
55 def test_selection(self):
56 sel = selector()
57 sel.set_polarisations("YY")
58 self.st.set_selection(sel)
59 self.assertEqual(self.st.getpolnos(), (1,))
60 sel1 = self.st.get_selection()
61 self.assertEqual(sel1.get_pols(), [1])
62 self.st.set_selection(pols="XX")
63 self.assertEqual(self.st.getpolnos(), (0,))
64
65 def test_stats(self):
66 stats = { 'min': 113.767166138,
67 'max':215.279830933, 'sumsq':128759200.0,
68 'sum':720262.375, 'mean':175.845306396,
69 'var':513.95324707, 'stddev':22.6705360413,
70 'avdev':16.3966751099, 'rms':177.300170898,
71 'median':182.891845703}
72 for k,v in stats.iteritems():
73 sval = self.st.stats(stat=k)
74 self.assertAlmostEqual(sval[0], v)
75 msk = self.st.create_mask([0,100], [3900,4096])
76 self.assertAlmostEqual(self.st.stats("sum", msk)[0], 35216.87890625)
77
78 def test_get_column_names(self):
79 cnames = ['SCANNO', 'CYCLENO', 'BEAMNO', 'IFNO',
80 'POLNO', 'FREQ_ID', 'MOLECULE_ID', 'REFBEAMNO',
81 'TIME', 'INTERVAL', 'SRCNAME', 'SRCTYPE',
82 'FIELDNAME', 'SPECTRA', 'FLAGTRA', 'TSYS',
83 'DIRECTION', 'AZIMUTH', 'ELEVATION',
84 'OPACITY', 'TCAL_ID', 'FIT_ID',
85 'FOCUS_ID', 'WEATHER_ID', 'SRCVELOCITY',
86 'SRCPROPERMOTION', 'SRCDIRECTION',
87 'SCANRATE']
88 self.assertEqual(self.st.get_column_names(), cnames)
89
90 def test_get_tsys(self):
91 self.assertAlmostEqual(self.st.get_tsys()[0], 175.830429077)
92
93 def test_get_time(self):
94 self.assertEqual(self.st.get_time(0), '2008/03/12/09:32:50')
95 dt = datetime.datetime(2008,3,12,9,32,50)
96 self.assertEqual(self.st.get_time(0, True), dt)
97
98 def test_get_inttime(self):
99 self.assertAlmostEqual(self.st.get_inttime()[0], 30.720016479)
100
101 def test_get_sourcename(self):
102 self.assertEqual(self.st.get_sourcename(0), 'Orion_SiO_R')
103 self.assertEqual(self.st.get_sourcename()[:2], ['Orion_SiO_R', 'Orion_SiO'])
104
105 def test_get_azimuth(self):
106 self.assertAlmostEqual(self.st.get_azimuth()[0], 5.628767013)
107
108 def test_get_elevation(self):
109 self.assertAlmostEqual(self.st.get_elevation()[0], 1.01711678504)
110
111 def test_get_parangle(self):
112 self.assertAlmostEqual(self.st.get_parangle()[0], 2.5921990871)
113
114 def test_get_direction(self):
115 self.assertEqual(self.st.get_direction()[0], '05:35:14.5 -04.52.29.5')
116
117 def test_get_directionval(self):
118 dv = self.st.get_directionval()[0]
119 self.assertAlmostEqual(dv[0], 1.4627692699)
120 self.assertAlmostEqual(dv[1], -0.0850824415)
121
122 def test_unit(self):
123 self.st.set_unit('')
124 self.st.set_unit('GHz')
125 self.st.set_unit('km/s')
126 self.assertRaises(RuntimeError, self.st.set_unit, 'junk')
127 self.assertEquals(self.st.get_unit(), 'km/s')
128
129 def test_average_pol(self):
130 ap = self.st.average_pol()
131 self.assertEqual(ap.npol(), 1)
132
133 def test_drop_scan(self):
134 s0 = self.st.drop_scan(1)
135 self.assertEqual(s0.getscannos(), (0,))
136 s1 = self.st.drop_scan([0])
137 self.assertEqual(s1.getscannos(), (1,))
138
139 def test_flag(self):
140 q = self.st.auto_quotient()
141 q.set_unit('km/s')
142 q0 = q.copy()
143 q1 = q.copy()
144 msk = q0.create_mask([-10,20])
145 q0.flag(mask=mask_not(msk))
146 self.assertAlmostEqual(q0.stats(stat='max')[0], 95.62171936)
147 q1.flag(mask=msk)
148 self.assertAlmostEqual(q1.stats(stat='max')[0], 2.66563416)
149
150if __name__ == '__main__':
151 unittest.main()
Note: See TracBrowser for help on using the repository browser.