You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@climate.apache.org by ja...@apache.org on 2016/06/14 06:38:07 UTC

[1/6] climate git commit: Add temporal_slice function tests

Repository: climate
Updated Branches:
  refs/heads/master 71c8a502e -> d94bbdc05


Add temporal_slice function tests


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

Branch: refs/heads/master
Commit: 3a0467f32ddd672c72ba361e04d0a51f8773854e
Parents: fb53c09
Author: Ibrahim <ja...@gmail.com>
Authored: Mon May 30 15:54:39 2016 +0530
Committer: Ibrahim <ja...@gmail.com>
Committed: Tue Jun 14 01:06:10 2016 +0530

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


http://git-wip-us.apache.org/repos/asf/climate/blob/3a0467f3/ocw/tests/test_dataset_processor.py
----------------------------------------------------------------------
diff --git a/ocw/tests/test_dataset_processor.py b/ocw/tests/test_dataset_processor.py
index c186e4b..093e510 100644
--- a/ocw/tests/test_dataset_processor.py
+++ b/ocw/tests/test_dataset_processor.py
@@ -157,6 +157,31 @@ class TestVariableUnitConversion(unittest.TestCase):
         np.testing.assert_array_equal(self.ten_year_dataset.values, values)
 
 
+class TestTemporalSlice(unittest.TestCase):
+    def test_returned_dataset_times(self):
+        ''' Tests returned dataset times values '''
+        self.ten_year_dataset = ten_year_monthly_dataset()
+        start_index = 1
+        end_index = 4
+        dates = np.array([datetime.datetime(2000, month, 1)
+                          for month in range(start_index + 1, end_index + 2)])
+        new_dataset = dp.temporal_slice(start_index,
+                                        end_index,
+                                        self.ten_year_dataset)
+        np.testing.assert_array_equal(new_dataset.times, dates)
+
+    def test_returned_dataset_values(self):
+        ''' Tests returned dataset variable values '''
+        self.ten_year_dataset = ten_year_monthly_dataset()
+        start_index = 1
+        end_index = 4
+        values = self.ten_year_dataset.values[start_index:end_index + 1]
+        new_dataset = dp.temporal_slice(start_index,
+                                        end_index,
+                                        self.ten_year_dataset)
+        np.testing.assert_array_equal(new_dataset.values, values)
+
+
 class TestEnsemble(unittest.TestCase):
     def test_unequal_dataset_shapes(self):
         self.ten_year_dataset = ten_year_monthly_dataset()


[4/6] climate git commit: Add tests for dataset processor

Posted by ja...@apache.org.
Add tests for dataset processor

- Multiple tests for Temporal_subset function
- Add test_two_dimensional_lats_lons test for spatial_regrid function
- Add test_subset_without_start_index for subset function


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

Branch: refs/heads/master
Commit: c3691d28ec60e359af28dddf799bc7ae879142ef
Parents: 3a0467f
Author: Ibrahim <ja...@gmail.com>
Authored: Tue May 31 12:41:17 2016 +0530
Committer: Ibrahim <ja...@gmail.com>
Committed: Tue Jun 14 01:08:50 2016 +0530

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


http://git-wip-us.apache.org/repos/asf/climate/blob/c3691d28/ocw/tests/test_dataset_processor.py
----------------------------------------------------------------------
diff --git a/ocw/tests/test_dataset_processor.py b/ocw/tests/test_dataset_processor.py
index 093e510..6430526 100644
--- a/ocw/tests/test_dataset_processor.py
+++ b/ocw/tests/test_dataset_processor.py
@@ -41,6 +41,47 @@ class TestTemporalSubset(unittest.TestCase):
         np.testing.assert_array_equal(
             self.dataset_times, self.tempSubset.times)
 
+    def test_temporal_subset_with_average_time(self):
+        self.dataset_times = np.array([datetime.datetime(year, 2, 1)
+                                       for year in range(2000, 2010)])
+        self.tempSubset = dp.temporal_subset(1, 3,
+                                             self.ten_year_dataset,
+                                             average_each_year=True)
+        np.testing.assert_array_equal(self.dataset_times,
+                                      self.tempSubset.times)
+
+    def test_temporal_subset_with_average_values(self):
+        self.tempSubset = dp.temporal_subset(1, 3,
+                                             self.ten_year_dataset,
+                                             average_each_year=True)
+        self.dataset_values = np.ones([len(self.tempSubset.times),
+                                       len(self.ten_year_dataset.lats),
+                                       len(self.ten_year_dataset.lons)])
+        np.testing.assert_array_equal(self.dataset_values,
+                                      self.tempSubset.values)
+
+    def test_temporal_subset_attributes(self):
+        self.tempSubset = dp.temporal_subset(1, 3,
+                                             self.ten_year_dataset,
+                                             average_each_year=True)
+        self.assertEqual(self.tempSubset.name, self.ten_year_dataset.name)
+        self.assertEqual(self.tempSubset.variable,
+                         self.ten_year_dataset.variable)
+        self.assertEqual(self.tempSubset.units, self.ten_year_dataset.units)
+        np.testing.assert_array_equal(self.tempSubset.lats,
+                                      self.ten_year_dataset.lats)
+        np.testing.assert_array_equal(self.tempSubset.lons,
+                                      self.ten_year_dataset.lons)
+
+    def test_temporal_subset_equal_start_end_month(self):
+        self.dataset_times = np.array([datetime.datetime(year, 1, 1)
+                                       for year in range(2000, 2010)])
+        self.tempSubset = dp.temporal_subset(1, 1,
+                                             self.ten_year_dataset,
+                                             average_each_year=True)
+        np.testing.assert_array_equal(self.dataset_times,
+                                      self.tempSubset.times)
+
     def test_startMonth_greater_than_endMonth(self):
         self.dataset_times = np.array([datetime.datetime(year, month, 1)
                                        for year in range(2000, 2010)
@@ -334,6 +375,15 @@ class TestSpatialRegrid(unittest.TestCase):
         self.assertEquals(self.input_dataset.variable,
                           self.regridded_dataset.variable)
 
+    def test_two_dimensional_lats_lons(self):
+        self.input_dataset.lats = np.array(range(-89, 90, 2))
+        self.input_dataset.lons = np.array(range(-179, 180, 4))
+        self.input_dataset.lats = self.input_dataset.lats.reshape(2, 45)
+        self.input_dataset.lons = self.input_dataset.lons.reshape(2, 45)
+        new_dataset = dp.spatial_regrid(
+            self.input_dataset, self.new_lats, self.new_lons)
+        np.testing.assert_array_equal(new_dataset.lats, self.new_lats)
+
 
 class TestNormalizeDatasetDatetimes(unittest.TestCase):
     def setUp(self):
@@ -418,6 +468,23 @@ class TestSubset(unittest.TestCase):
                                 "time_end": 49}
         self.assertDictEqual(index_slices, control_index_slices)
 
+    def test_subset_without_start_index(self):
+        self.subregion = ds.Bounds(
+            -81, 81,
+            -161, 161,
+        )
+        subset = dp.subset(self.subregion, self.target_dataset)
+        times = np.array([datetime.datetime(year, month, 1)
+                         for year in range(2000, 2010)
+                         for month in range(1, 13)])
+        self.assertEqual(subset.lats.shape[0], 82)
+        self.assertSequenceEqual(list(np.array(range(-81, 82, 2))),
+                                 list(subset.lats))
+        self.assertEqual(subset.lons.shape[0], 162)
+        self.assertEqual(subset.values.shape, (120, 82, 162))
+        self.assertEqual(subset.times.shape[0], 120)
+        np.testing.assert_array_equal(subset.times, times)
+
 
 class TestSafeSubset(unittest.TestCase):
     def setUp(self):


[3/6] climate git commit: add variable_unit_conversion function tests

Posted by ja...@apache.org.
add variable_unit_conversion function tests


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

Branch: refs/heads/master
Commit: fb53c09c54eefb27cac1c5303c1d7295afd5f48b
Parents: dd93d7f
Author: Ibrahim <ja...@gmail.com>
Authored: Sun May 29 23:47:01 2016 +0530
Committer: Ibrahim <ja...@gmail.com>
Committed: Tue Jun 14 01:06:10 2016 +0530

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


http://git-wip-us.apache.org/repos/asf/climate/blob/fb53c09c/ocw/tests/test_dataset_processor.py
----------------------------------------------------------------------
diff --git a/ocw/tests/test_dataset_processor.py b/ocw/tests/test_dataset_processor.py
index 1271995..c186e4b 100644
--- a/ocw/tests/test_dataset_processor.py
+++ b/ocw/tests/test_dataset_processor.py
@@ -95,6 +95,68 @@ class TestTemporalRebinWithTimeIndex(unittest.TestCase):
         np.testing.assert_array_equal(self.ten_year_dataset.lons, dataset.lons)
 
 
+class TestVariableUnitConversion(unittest.TestCase):
+    def setUp(self):
+        self.ten_year_dataset = ten_year_monthly_dataset()
+        self.ten_year_dataset.variable = 'temp'
+        self.ten_year_dataset.units = 'celsius'
+
+    def test_returned_variable_unit_celsius(self):
+        ''' Tests returned dataset unit if original dataset unit is celcius '''
+        dp.variable_unit_conversion(self.ten_year_dataset)
+        self.assertEqual(self.ten_year_dataset.units, 'K')
+
+    def test_returned_variable_unit_kelvin(self):
+        ''' Tests returned dataset unit if original dataset unit is kelvin '''
+        self.ten_year_dataset.units = 'K'
+        another_dataset = dp.variable_unit_conversion(self.ten_year_dataset)
+        self.assertEqual(another_dataset.units, self.ten_year_dataset.units)
+
+    def test_temp_unit_conversion(self):
+        ''' Tests returned dataset temp values '''
+        self.ten_year_dataset.values = np.ones([
+            len(self.ten_year_dataset.times),
+            len(self.ten_year_dataset.lats),
+            len(self.ten_year_dataset.lons)])
+        values = self.ten_year_dataset.values + 273.15
+        dp.variable_unit_conversion(self.ten_year_dataset)
+        np.testing.assert_array_equal(self.ten_year_dataset.values, values)
+
+    def test_returned_variable_unit_swe(self):
+        ''' Tests returned dataset unit if original dataset unit is swe '''
+        self.ten_year_dataset.variable = 'swe'
+        self.ten_year_dataset.units = 'm'
+        dp.variable_unit_conversion(self.ten_year_dataset)
+        self.assertEqual(self.ten_year_dataset.variable, 'swe')
+        self.assertEqual(self.ten_year_dataset.units, 'km')
+
+    def test_returned_variable_unit_pr(self):
+        '''
+        Tests returned dataset unit if original dataset unit is kgm^-2s^-1
+        '''
+        self.ten_year_dataset.variable = 'pr'
+        self.ten_year_dataset.units = 'kg m-2 s-1'
+        dp.variable_unit_conversion(self.ten_year_dataset)
+        self.assertEqual(self.ten_year_dataset.variable, 'pr')
+        self.assertEqual(self.ten_year_dataset.units, 'mm/day')
+
+    def test_water_flux_unit_conversion_swe(self):
+        ''' Tests variable values in returned dataset '''
+        self.ten_year_dataset.variable = 'swe'
+        self.ten_year_dataset.units = 'm'
+        values = self.ten_year_dataset.values + 999
+        dp.variable_unit_conversion(self.ten_year_dataset)
+        np.testing.assert_array_equal(self.ten_year_dataset.values, values)
+
+    def test_water_flux_unit_conversion_pr(self):
+        ''' Tests variable values in returned dataset '''
+        self.ten_year_dataset.variable = 'pr'
+        self.ten_year_dataset.units = 'kg m-2 s-1'
+        values = self.ten_year_dataset.values + 86399
+        dp.variable_unit_conversion(self.ten_year_dataset)
+        np.testing.assert_array_equal(self.ten_year_dataset.values, values)
+
+
 class TestEnsemble(unittest.TestCase):
     def test_unequal_dataset_shapes(self):
         self.ten_year_dataset = ten_year_monthly_dataset()


[6/6] climate git commit: Merge branch 'CLIMATE-795'

Posted by ja...@apache.org.
Merge branch 'CLIMATE-795'


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

Branch: refs/heads/master
Commit: d94bbdc05a6474382cfa9f34a0073a4101f236dd
Parents: 71c8a50 91da3a2
Author: Ibrahim <ja...@gmail.com>
Authored: Tue Jun 14 12:07:15 2016 +0530
Committer: Ibrahim <ja...@gmail.com>
Committed: Tue Jun 14 12:07:15 2016 +0530

----------------------------------------------------------------------
 ocw/tests/test_dataset_processor.py | 225 ++++++++++++++++++++++++++++++-
 1 file changed, 222 insertions(+), 3 deletions(-)
----------------------------------------------------------------------



[5/6] climate git commit: Add new tests to dataset processor

Posted by ja...@apache.org.
Add new tests to dataset processor

- Add test_daily_to_daily_rebin test in TestTemporalRebin class
- Add test_invalid_unit_rebin test in TestTemporalRebin class
- Add test_daily_time in TestNormalizeDatasetDatetimes class
- Fix ten_year_monthly_15th_dataset function


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

Branch: refs/heads/master
Commit: 91da3a2fa8c9b616f999acf60878dc2e6d2eb27b
Parents: c3691d2
Author: Ibrahim <ja...@gmail.com>
Authored: Fri Jun 3 19:42:52 2016 +0530
Committer: Ibrahim <ja...@gmail.com>
Committed: Tue Jun 14 01:08:50 2016 +0530

----------------------------------------------------------------------
 ocw/tests/test_dataset_processor.py | 29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/91da3a2f/ocw/tests/test_dataset_processor.py
----------------------------------------------------------------------
diff --git a/ocw/tests/test_dataset_processor.py b/ocw/tests/test_dataset_processor.py
index 6430526..eb39ba6 100644
--- a/ocw/tests/test_dataset_processor.py
+++ b/ocw/tests/test_dataset_processor.py
@@ -318,6 +318,16 @@ class TestTemporalRebin(unittest.TestCase):
         self.assertEquals(annual_dataset.variable,
                           self.ten_year_monthly_dataset.variable)
 
+    def test_daily_to_daily_rebin(self):
+        daily_dataset = dp.temporal_rebin(
+            self.two_years_daily_dataset, "daily")
+        np.testing.assert_array_equal(
+            daily_dataset.times, self.two_years_daily_dataset.times)
+
+    def test_invalid_unit_rebin(self):
+        with self.assertRaises(ValueError):
+            dp.temporal_rebin(self.two_years_daily_dataset, "days")
+
 
 class TestRcmesSpatialRegrid(unittest.TestCase):
 
@@ -403,6 +413,17 @@ class TestNormalizeDatasetDatetimes(unittest.TestCase):
         # Check that all the days have been shifted to the first of the month
         self.assertTrue(all(x.day == 1 for x in new_ds.times))
 
+    def test_daily_time(self):
+        # Test daily with time.hour != 0
+        self.monthly_dataset.times = np.array([
+                                              datetime.datetime(
+                                                  year, month, 15, 5)
+                                              for year in range(2000, 2010)
+                                              for month in range(1, 13)])
+        new_ds = dp.normalize_dataset_datetimes(self.monthly_dataset, 'daily')
+        # Check that all the days have been shifted to the first of the month
+        self.assertTrue(all(x.hour == 0 for x in new_ds.times))
+
 
 class TestSubset(unittest.TestCase):
     def setUp(self):
@@ -475,8 +496,8 @@ class TestSubset(unittest.TestCase):
         )
         subset = dp.subset(self.subregion, self.target_dataset)
         times = np.array([datetime.datetime(year, month, 1)
-                         for year in range(2000, 2010)
-                         for month in range(1, 13)])
+                          for year in range(2000, 2010)
+                          for month in range(1, 13)])
         self.assertEqual(subset.lats.shape[0], 82)
         self.assertSequenceEqual(list(np.array(range(-81, 82, 2))),
                                  list(subset.lats))
@@ -645,8 +666,8 @@ def ten_year_monthly_dataset():
 def ten_year_monthly_15th_dataset():
     lats = np.array(range(-89, 90, 2))
     lons = np.array(range(-179, 180, 2))
-    # Ten Years of monthly data
-    times = np.array([datetime.datetime(year, month, 1)
+    # Ten Years of monthly 15th data
+    times = np.array([datetime.datetime(year, month, 15)
                       for year in range(2000, 2010) for month in range(1, 13)])
     values = np.ones([len(times), len(lats), len(lons)])
     input_dataset = ds.Dataset(lats,


[2/6] climate git commit: add TemporalRebinWithTimeIndex function tests

Posted by ja...@apache.org.
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 <ja...@gmail.com>
Authored: Wed May 25 23:01:00 2016 +0530
Committer: Ibrahim <ja...@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()