bff95322fda64a7684360956c232b180983cd1e1
[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   
36   def setUp(self):
37     _helpers.triggerMemoryStatus()
38
39   def tearDown(self):
40     pass
41
42   def test_new(self):
43     obj = _wrwp.new()
44     self.assertNotEqual(-1, string.find(`type(obj)`, "WrwpCore"))
45
46   def test_dz(self):
47     obj = _wrwp.new()
48     self.assertEquals(200, obj.dz)
49     obj.dz = 100
50     self.assertEquals(100, obj.dz)
51     try:
52       obj.dz = 200.0
53       self.fail("Expected TypeError")
54     except TypeError, e:
55       pass
56     self.assertEquals(100, obj.dz)
57
58   def test_hmax(self):
59     obj = _wrwp.new()
60     self.assertEquals(12000, obj.hmax)
61     obj.hmax = 100
62     self.assertEquals(100, obj.hmax)
63     try:
64       obj.hmax = 200.0
65       self.fail("Expected TypeError")
66     except TypeError, e:
67       pass
68     self.assertEquals(100, obj.hmax)
69
70   def test_dmin(self):
71     obj = _wrwp.new()
72     self.assertEquals(4000, obj.dmin)
73     obj.dmin = 100
74     self.assertEquals(100, obj.dmin)
75     try:
76       obj.dmin = 200.0
77       self.fail("Expected TypeError")
78     except TypeError, e:
79       pass
80     self.assertEquals(100, obj.dmin)
81     
82   def test_dmax(self):
83     obj = _wrwp.new()
84     self.assertEquals(40000, obj.dmax)
85     obj.dmax = 100
86     self.assertEquals(100, obj.dmax)
87     try:
88       obj.dmax = 200.0
89       self.fail("Expected TypeError")
90     except TypeError, e:
91       pass
92     self.assertEquals(100, obj.dmax)
93
94   def test_emin(self):
95     obj = _wrwp.new()
96     self.assertAlmostEquals(2.5, obj.emin, 4)
97     obj.emin = 3.5
98     self.assertAlmostEquals(3.5, obj.emin, 4)
99     obj.emin = 4
100     self.assertAlmostEquals(4.0, obj.emin, 4)
101
102   def test_vmin(self):
103     obj = _wrwp.new()
104     self.assertAlmostEquals(2.0, obj.vmin, 4)
105     obj.vmin = 3.5
106     self.assertAlmostEquals(3.5, obj.vmin, 4)
107     obj.vmin = 4
108     self.assertAlmostEquals(4.0, obj.vmin, 4)
109   
110   def test_generate(self):
111     pvol = _raveio.open(self.FIXTURE).object
112     generator = _wrwp.new()
113     generator.hmax = 2000
114     generator.dz = 200
115     
116     vp = generator.generate(pvol)
117     
118     ff = vp.getFF()
119     ff_dev = vp.getFFDev()
120     dd = vp.getDD()
121     dbz = vp.getDBZ()
122     dbz_dev = vp.getDBZDev()
123     
124     self.assertEquals(1, ff.xsize)
125     self.assertEquals(10, ff.ysize)
126     self.assertEquals("ff", ff.getAttribute("what/quantity"))
127
128     self.assertEquals(1, ff_dev.xsize)
129     self.assertEquals(10, ff_dev.ysize)
130     self.assertEquals("ff_dev", ff_dev.getAttribute("what/quantity"))
131
132     self.assertEquals(1, dd.xsize)
133     self.assertEquals(10, dd.ysize)
134     self.assertEquals("dd", dd.getAttribute("what/quantity"))
135     
136     self.assertEquals(1, dbz.xsize)
137     self.assertEquals(10, dbz.ysize)
138     self.assertEquals("dbz", dbz.getAttribute("what/quantity"))
139
140     self.assertEquals(1, dbz_dev.xsize)
141     self.assertEquals(10, dbz_dev.ysize)
142     self.assertEquals("dbz_dev", dbz_dev.getAttribute("what/quantity"))
143
144     self.assertEquals(10, vp.getLevels())
145     self.assertEquals(200, vp.interval)
146     self.assertEquals(100, vp.minheight)
147     self.assertEquals(2000, vp.maxheight)
148     self.assertEquals(pvol.source, vp.source)
149     self.assertEquals(pvol.date, vp.date)
150     self.assertEquals(pvol.time, vp.time)
151     
152   def X_test_generate_2(self):
153     pvol = _raveio.open(self.FIXTURE).object
154     generator = _wrwp.new()
155     generator.hmax = 2000
156     generator.dz = 200
157     
158     vp = generator.generate(pvol)
159
160     robj = _raveio.new()
161     robj.object = vp
162     robj.save("slask.h5")
163     
164 if __name__ == "__main__":
165   unittest.main()