climate-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jarifibra...@apache.org
Subject [1/4] climate git commit: Add tests for calc_area_weighted_spatial_average
Date Tue, 14 Jun 2016 06:43:28 GMT
Repository: climate
Updated Branches:
  refs/heads/master 54986818e -> 03e9d9f05


Add tests for calc_area_weighted_spatial_average


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

Branch: refs/heads/master
Commit: a389b628f307e57aa693f0aea1396b5cb8f0e200
Parents: c9b7c4e
Author: Ibrahim <jarifibrahim@gmail.com>
Authored: Sun Jun 12 22:34:05 2016 +0530
Committer: Ibrahim <jarifibrahim@gmail.com>
Committed: Tue Jun 14 01:18:41 2016 +0530

----------------------------------------------------------------------
 ocw/tests/test_utils.py | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/a389b628/ocw/tests/test_utils.py
----------------------------------------------------------------------
diff --git a/ocw/tests/test_utils.py b/ocw/tests/test_utils.py
index 1137bea..d35bc55 100644
--- a/ocw/tests/test_utils.py
+++ b/ocw/tests/test_utils.py
@@ -313,6 +313,26 @@ class TestCalcAreaWeightedSpatialAverage(unittest.TestCase):
         result = utils.calc_area_weighted_spatial_average(self.test_dataset)
         np.testing.assert_array_equal(avg, result)
 
+    def test_spatial_average_with_area_weight(self):
+        avg = np.ma.array([3.985158, 12.985158, 21.985158,
+                           30.985158, 39.985158, 48.985158])
+        result = utils.calc_area_weighted_spatial_average(
+            self.test_dataset, area_weight=True)
+        np.testing.assert_array_almost_equal(avg, result)
+
+    def test__2_dim_lats_lons_area_weight(self):
+        self.lat = np.array([10, 12, 14]).reshape(3, 1)
+        self.lon = np.array([100, 102, 104]).reshape(3, 1)
+        flat_array = np.array(range(18))
+        self.value = flat_array.reshape(6, 3, 1)
+        self.test_dataset = Dataset(self.lat, self.lon, self.time,
+                                    self.value, self.variable)
+        avg = np.ma.array([0.995053, 3.995053, 6.995053, 9.995053, 12.995053,
+                           15.995053])
+        result = utils.calc_area_weighted_spatial_average(
+            self.test_dataset, area_weight=True)
+        np.testing.assert_array_almost_equal(avg, result)
+
 
 class TestCalcClimatologyYear(unittest.TestCase):
     ''' Testing function 'calc_climatology_year' from ocw.utils.py '''


Mime
View raw message