climate-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lewi...@apache.org
Subject [3/4] climate git commit: Add a unit test for Absolute Bias
Date Wed, 01 Aug 2018 05:28:11 GMT
Add a unit test for Absolute Bias

Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/03075741
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/03075741
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/03075741

Branch: refs/heads/master
Commit: 0307574133ff50d8f7f019cf867aa8a2fa2c6bd1
Parents: 8104a2b
Author: Prateek Chanda <prateekkol21@gmail.com>
Authored: Wed Jun 27 07:33:51 2018 +0530
Committer: GitHub <noreply@github.com>
Committed: Wed Jun 27 07:33:51 2018 +0530

----------------------------------------------------------------------
 ocw/tests/test_metrics.py | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/03075741/ocw/tests/test_metrics.py
----------------------------------------------------------------------
diff --git a/ocw/tests/test_metrics.py b/ocw/tests/test_metrics.py
index ac786e5..2257112 100644
--- a/ocw/tests/test_metrics.py
+++ b/ocw/tests/test_metrics.py
@@ -66,6 +66,46 @@ class TestBias(unittest.TestCase):
         expected_result.fill(-300)
         np.testing.assert_array_equal(self.bias.run(
             self.target_dataset, self.reference_dataset), expected_result)
+        
+        
+class TestAbsoluteBias(unittest.TestCase):
+    '''Test the metrics.Bias metric.'''
+
+    def setUp(self):
+        self.bias = metrics.AbsoluteBias()
+        # Initialize reference dataset
+        self.reference_lat = np.array([10, 12, 14, 16, 18])
+        self.reference_lon = np.array([100, 102, 104, 106, 108])
+        self.reference_time = np.array(
+            [dt.datetime(2000, x, 1) for x in range(1, 13)])
+        flat_array = np.array(range(300))
+        self.reference_value = flat_array.reshape(12, 5, 5)
+        self.reference_variable = 'prec'
+        self.reference_dataset = Dataset(self.reference_lat,
+                                         self.reference_lon,
+                                         self.reference_time,
+                                         self.reference_value,
+                                         self.reference_variable)
+        # Initialize target dataset
+        self.target_lat = np.array([1, 2, 4, 6, 8])
+        self.target_lon = np.array([10, 12, 14, 16, 18])
+        self.target_time = np.array(
+            [dt.datetime(2001, x, 1) for x in range(1, 13)])
+        flat_array = np.array(range(300, 600))
+        self.target_value = flat_array.reshape(12, 5, 5)
+        self.target_variable = 'tasmax'
+        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 bias function between reference dataset and target dataset.'''
+        expected_result = np.zeros((12, 5, 5), dtype=np.int)
+        expected_result.fill(300)
+        np.testing.assert_array_equal(self.bias.run(
+            self.target_dataset, self.reference_dataset), expected_result)
 
 
 class TestSpatialPatternTaylorDiagram(unittest.TestCase):


Mime
View raw message