climate-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From boust...@apache.org
Subject svn commit: r1565452 - /incubator/climate/trunk/ocw/tests/test_metrics.py
Date Thu, 06 Feb 2014 21:53:35 GMT
Author: boustani
Date: Thu Feb  6 21:53:35 2014
New Revision: 1565452

URL: http://svn.apache.org/r1565452
Log:
[CLIMATE-337] Unittest for Class TemporalStdDev on metrics.py module.

Modified:
    incubator/climate/trunk/ocw/tests/test_metrics.py

Modified: incubator/climate/trunk/ocw/tests/test_metrics.py
URL: http://svn.apache.org/viewvc/incubator/climate/trunk/ocw/tests/test_metrics.py?rev=1565452&r1=1565451&r2=1565452&view=diff
==============================================================================
--- incubator/climate/trunk/ocw/tests/test_metrics.py (original)
+++ incubator/climate/trunk/ocw/tests/test_metrics.py Thu Feb  6 21:53:35 2014
@@ -20,11 +20,11 @@
 import unittest
 import datetime as dt
 
-from ocw.metrics import Bias
+from ocw.metrics import Bias, TemporalStdDev
 from ocw.dataset import Dataset
 
 import numpy as np
-
+import numpy.testing as npt
 
 class TestBias(unittest.TestCase):
     '''Test the metrics.Bias metric.'''
@@ -57,5 +57,26 @@ class TestBias(unittest.TestCase):
         self.assertTrue(np.array_equal(self.bias.run(self.reference_dataset, self.target_dataset),
expected_result))
 
 
+class TestTemporalStdDev(unittest.TestCase):
+    '''Test the metrics.TemporalStdDev metric.'''
+    def setUp(self):
+        self.temporal_std_dev = TemporalStdDev()
+        #Initialize target dataset
+        self.target_lat = np.array([10, 12, 14, 16, 18])
+        self.target_lon = np.array([100, 102, 104, 106, 108])
+        self.target_time = np.array([dt.datetime(2000, x, 1) for x in range(1, 13)])
+        flat_array = np.array(range(300))
+        self.target_value = flat_array.reshape(12, 5, 5)
+        self.target_variable = 'prec'
+        self.target_dataset = Dataset(self.target_lat, self.target_lon, self.target_time,
+            self.target_value, self.target_variable)
+
+
+    def test_function_run(self):
+        '''Test TemporalStdDev function for target dataset.'''
+        expected_result = np.zeros((12, 5),)
+        expected_result.fill(7.90569415)
+        npt.assert_almost_equal(self.temporal_std_dev.run(self.target_dataset), expected_result)
+
 if __name__ == '__main__':
     unittest.main()



Mime
View raw message