Ticket 504: How attributes should be copied from volume to profile
[baltrad-wrwp.git] / test / pytest / WrwpTest.py
1 '''
2 Copyright (C) 2013 Swedish Meteorological and Hydrological Institute, SMHI,
3
4 This file is part of baltrad-wrwp.
5
6 baltrad-wrwp is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 baltrad-wrwp is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with baltrad-wrwp.  If not, see <http://www.gnu.org/licenses/>.
18 ------------------------------------------------------------------------*/
19
20 Tests the wrwp module.
21
22 @file
23 @author Anders Henja (Swedish Meteorological and Hydrological Institute, SMHI)
24 @date 2013-09-17
25 '''
26
27 import unittest
28 import string
29 import _wrwp
30 import _helpers
31 import _raveio, _rave
32
33 class WrwpTest(unittest.TestCase):
34   FIXTURE = "fixtures/pvol_seang_20090501T120000Z.h5"
35   FIXTURE2 = "fixtures/selul_pvol_20151114T1615Z.h5"
36   
37   def setUp(self):
38     _helpers.triggerMemoryStatus()
39
40   def tearDown(self):
41     pass
42
43   def test_new(self):
44     obj = _wrwp.new()
45     self.assertNotEqual(-1, string.find(`type(obj)`, "WrwpCore"))
46
47   def test_dz(self):
48     obj = _wrwp.new()
49     self.assertEquals(200, obj.dz)
50     obj.dz = 100
51     self.assertEquals(100, obj.dz)
52     try:
53       obj.dz = 200.0
54       self.fail("Expected TypeError")
55     except TypeError, e:
56       pass
57     self.assertEquals(100, obj.dz)
58
59   def test_hmax(self):
60     obj = _wrwp.new()
61     self.assertEquals(12000, obj.hmax)
62     obj.hmax = 100
63     self.assertEquals(100, obj.hmax)
64     try:
65       obj.hmax = 200.0
66       self.fail("Expected TypeError")
67     except TypeError, e:
68       pass
69     self.assertEquals(100, obj.hmax)
70
71   def test_dmin(self):
72     obj = _wrwp.new()
73     self.assertEquals(4000, obj.dmin)
74     obj.dmin = 100
75     self.assertEquals(100, obj.dmin)
76     try:
77       obj.dmin = 200.0
78       self.fail("Expected TypeError")
79     except TypeError, e:
80       pass
81     self.assertEquals(100, obj.dmin)
82     
83   def test_dmax(self):
84     obj = _wrwp.new()
85     self.assertEquals(40000, obj.dmax)
86     obj.dmax = 100
87     self.assertEquals(100, obj.dmax)
88     try:
89       obj.dmax = 200.0
90       self.fail("Expected TypeError")
91     except TypeError, e:
92       pass
93     self.assertEquals(100, obj.dmax)
94
95   def test_emin(self):
96     obj = _wrwp.new()
97     self.assertAlmostEquals(2.5, obj.emin, 4)
98     obj.emin = 3.5
99     self.assertAlmostEquals(3.5, obj.emin, 4)
100     obj.emin = 4
101     self.assertAlmostEquals(4.0, obj.emin, 4)
102
103   def test_vmin(self):
104     obj = _wrwp.new()
105     self.assertAlmostEquals(2.0, obj.vmin, 4)
106     obj.vmin = 3.5
107     self.assertAlmostEquals(3.5, obj.vmin, 4)
108     obj.vmin = 4
109     self.assertAlmostEquals(4.0, obj.vmin, 4)
110   
111   def test_generate(self):
112     pvol = _raveio.open(self.FIXTURE).object
113     generator = _wrwp.new()
114     generator.hmax = 2000
115     generator.dz = 200
116     
117     vp = generator.generate(pvol)
118     
119     ff = vp.getFF()
120     ff_dev = vp.getFFDev()
121     dd = vp.getDD()
122     dbz = vp.getDBZ()
123     dbz_dev = vp.getDBZDev()
124     
125     self.assertEquals(1, ff.xsize)
126     self.assertEquals(10, ff.ysize)
127     self.assertEquals("ff", ff.getAttribute("what/quantity"))
128
129     self.assertEquals(1, ff_dev.xsize)
130     self.assertEquals(10, ff_dev.ysize)
131     self.assertEquals("ff_dev", ff_dev.getAttribute("what/quantity"))
132
133     self.assertEquals(1, dd.xsize)
134     self.assertEquals(10, dd.ysize)
135     self.assertEquals("dd", dd.getAttribute("what/quantity"))
136     
137     self.assertEquals(1, dbz.xsize)
138     self.assertEquals(10, dbz.ysize)
139     self.assertEquals("dbz", dbz.getAttribute("what/quantity"))
140
141     self.assertEquals(1, dbz_dev.xsize)
142     self.assertEquals(10, dbz_dev.ysize)
143     self.assertEquals("dbz_dev", dbz_dev.getAttribute("what/quantity"))
144
145     self.assertEquals(10, vp.getLevels())
146     self.assertEquals(200, vp.interval)
147     self.assertEquals(100, vp.minheight)
148     self.assertEquals(2000, vp.maxheight)
149     self.assertEquals(pvol.source, vp.source)
150     self.assertEquals(pvol.date, vp.date)
151     self.assertEquals(pvol.time, vp.time)
152     
153   def X_test_generate_2(self):
154     pvol = _raveio.open(self.FIXTURE).object
155     generator = _wrwp.new()
156     generator.hmax = 2000
157     generator.dz = 200
158     
159     vp = generator.generate(pvol)
160
161     robj = _raveio.new()
162     robj.object = vp
163     robj.save("slask.h5")
164
165   def test_generate_with_several_howattributes(self):
166     pvol = _raveio.open(self.FIXTURE2).object
167     generator = _wrwp.new()
168     generator.hmax = 2000
169     generator.dz = 200
170     
171     vp = generator.generate(pvol)
172     
173     ff = vp.getFF()
174     ff_dev = vp.getFFDev()
175     dd = vp.getDD()
176     dbz = vp.getDBZ()
177     dbz_dev = vp.getDBZDev()
178     
179     self.assertEquals(1, ff.xsize)
180     self.assertEquals(10, ff.ysize)
181     self.assertEquals("ff", ff.getAttribute("what/quantity"))
182
183     self.assertEquals(1, ff_dev.xsize)
184     self.assertEquals(10, ff_dev.ysize)
185     self.assertEquals("ff_dev", ff_dev.getAttribute("what/quantity"))
186
187     self.assertEquals(1, dd.xsize)
188     self.assertEquals(10, dd.ysize)
189     self.assertEquals("dd", dd.getAttribute("what/quantity"))
190     
191     self.assertEquals(1, dbz.xsize)
192     self.assertEquals(10, dbz.ysize)
193     self.assertEquals("dbz", dbz.getAttribute("what/quantity"))
194
195     self.assertEquals(1, dbz_dev.xsize)
196     self.assertEquals(10, dbz_dev.ysize)
197     self.assertEquals("dbz_dev", dbz_dev.getAttribute("what/quantity"))
198
199     self.assertEquals(10, vp.getLevels())
200     self.assertEquals(200, vp.interval)
201     self.assertEquals(100, vp.minheight)
202     self.assertEquals(2000, vp.maxheight)
203     self.assertEquals(pvol.source, vp.source)
204     self.assertEquals(pvol.date, vp.date)
205     self.assertEquals(pvol.time, vp.time)
206     
207     self.assertEquals(900, vp.getAttribute("how/lowprf"))
208     self.assertEquals(1200, vp.getAttribute("how/highprf"))
209     self.assertAlmostEqual(0.61, vp.getAttribute("how/pulsewidth"), 4)
210     self.assertAlmostEqual(5.35, vp.getAttribute("how/wavelength"), 4)
211     self.assertAlmostEqual(0.8, vp.getAttribute("how/RXbandwidth"), 4)
212     self.assertAlmostEqual(3.1, vp.getAttribute("how/RXloss"), 4)
213     self.assertAlmostEqual(1.9, vp.getAttribute("how/TXloss"), 4)
214     self.assertAlmostEqual(44.9, vp.getAttribute("how/antgain"), 4)
215     self.assertEquals("AVERAGE", vp.getAttribute("how/azmethod"))
216     self.assertEquals("AVERAGE", vp.getAttribute("how/binmethod"))
217     self.assertEquals("False", vp.getAttribute("how/malfunc"))
218     self.assertAlmostEqual(277.4, vp.getAttribute("how/nomTXpower"), 4)
219     self.assertEquals("b94 3dd 000 000 000:", vp.getAttribute("how/radar_msg"), 4)
220     self.assertAlmostEqual(73.101, vp.getAttribute("how/radconstH"), 4)
221     self.assertAlmostEqual(0.2, vp.getAttribute("how/radomeloss"), 4)
222     self.assertAlmostEqual(2.0, vp.getAttribute("how/rpm"), 4)
223     self.assertEquals("PARTEC2", vp.getAttribute("how/software"))
224     self.assertEquals("ERIC", vp.getAttribute("how/system"))
225     self.assertEquals(4000, vp.getAttribute("how/minrange"))
226     self.assertEquals(40000, vp.getAttribute("how/maxrange"))
227     
228     robj = _raveio.new()
229     robj.object = vp
230     robj.save("slask.h5")
231     
232 if __name__ == "__main__":
233   unittest.main()