climate-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jarifibra...@apache.org
Subject [2/6] climate git commit: add TemporalRebinWithTimeIndex function tests
Date Tue, 14 Jun 2016 06:38:08 GMT
add TemporalRebinWithTimeIndex function tests


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

Branch: refs/heads/master
Commit: dd93d7fbff8bea33dad0189644f9df9267548279
Parents: aaa3bc5
Author: Ibrahim <jarifibrahim@gmail.com>
Authored: Wed May 25 23:01:00 2016 +0530
Committer: Ibrahim <jarifibrahim@gmail.com>
Committed: Tue Jun 14 01:06:10 2016 +0530

----------------------------------------------------------------------
 ocw/tests/test_dataset_processor.py | 46 +++++++++++++++++++++++++++++++-
 1 file changed, 45 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/dd93d7fb/ocw/tests/test_dataset_processor.py
----------------------------------------------------------------------
diff --git a/ocw/tests/test_dataset_processor.py b/ocw/tests/test_dataset_processor.py
index 2301cda..1271995 100644
--- a/ocw/tests/test_dataset_processor.py
+++ b/ocw/tests/test_dataset_processor.py
@@ -30,7 +30,6 @@ logging.basicConfig(level=logging.CRITICAL)
 
 
 class TestTemporalSubset(unittest.TestCase):
-
     def setUp(self):
         self.ten_year_dataset = ten_year_monthly_dataset()
 
@@ -51,6 +50,51 @@ class TestTemporalSubset(unittest.TestCase):
             self.dataset_times, self.tempSubset.times)
 
 
+class TestTemporalRebinWithTimeIndex(unittest.TestCase):
+    def setUp(self):
+        self.ten_year_dataset = ten_year_monthly_dataset()
+
+    def test_time_dimension_multiple_of_orig_time_dimension(self):
+        # ten_year_dataset.times.size is 120
+        nt_avg = self.ten_year_dataset.times.size / 2
+        # Temporal Rebin to exactly 2 (time) values
+        dataset = dp.temporal_rebin_with_time_index(
+            self.ten_year_dataset, nt_avg)
+        start_time = self.ten_year_dataset.times[0]
+        # First month of the middle year
+        middle_element = self.ten_year_dataset.times.size / 2
+        end_time = self.ten_year_dataset.times[middle_element]
+        self.assertEqual(dataset.times.size,
+                         self.ten_year_dataset.times.size / nt_avg)
+        np.testing.assert_array_equal(dataset.times, [start_time, end_time])
+
+    def test_time_dimension_not_multiple_of_orig_time_dimension(self):
+        # ten_year_dataset.times.size is 120
+        nt_avg = 11
+        # Temporal Rebin to exactly 10 (time) values
+        dataset = dp.temporal_rebin_with_time_index(
+            self.ten_year_dataset, nt_avg)
+        new_times = self.ten_year_dataset.times[::11][:-1]
+        self.assertEqual(dataset.times.size,
+                         self.ten_year_dataset.times.size / nt_avg)
+        np.testing.assert_array_equal(dataset.times, new_times)
+
+    def test_returned_dataset_attributes(self):
+        nt_avg = 3
+        dataset = dp.temporal_rebin_with_time_index(
+            self.ten_year_dataset, nt_avg)
+        new_times = self.ten_year_dataset.times[::3]
+        new_values = self.ten_year_dataset.values[::3]
+        self.assertEqual(self.ten_year_dataset.name, dataset.name)
+        self.assertEqual(self.ten_year_dataset.origin, dataset.origin)
+        self.assertEqual(self.ten_year_dataset.units, dataset.units)
+        self.assertEqual(self.ten_year_dataset.variable, dataset.variable)
+        np.testing.assert_array_equal(new_times, dataset.times)
+        np.testing.assert_array_equal(new_values, dataset.values)
+        np.testing.assert_array_equal(self.ten_year_dataset.lats, dataset.lats)
+        np.testing.assert_array_equal(self.ten_year_dataset.lons, dataset.lons)
+
+
 class TestEnsemble(unittest.TestCase):
     def test_unequal_dataset_shapes(self):
         self.ten_year_dataset = ten_year_monthly_dataset()


Mime
View raw message