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/13 19:51:22 UTC

[1/2] climate git commit: Add new tests for the dataset module

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


Add new tests for the dataset module


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

Branch: refs/heads/master
Commit: 71c8a502e11849c347f3ff8536949810135b2425
Parents: 5ecaa8e
Author: Ibrahim <ja...@gmail.com>
Authored: Sun Jun 5 21:22:52 2016 +0530
Committer: Ibrahim <ja...@gmail.com>
Committed: Tue Jun 14 00:51:58 2016 +0530

----------------------------------------------------------------------
 ocw/tests/test_dataset.py | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/71c8a502/ocw/tests/test_dataset.py
----------------------------------------------------------------------
diff --git a/ocw/tests/test_dataset.py b/ocw/tests/test_dataset.py
index d30fbcc..dcf6490 100644
--- a/ocw/tests/test_dataset.py
+++ b/ocw/tests/test_dataset.py
@@ -91,6 +91,9 @@ class TestInvalidDatasetInit(unittest.TestCase):
         self.value = np.array([1, 2, 3, 4, 5])
         with self.assertRaises(ValueError):
             Dataset(self.lat, self.lon, self.time, self.value, 'prec')
+        self.value = self.value.reshape(1, 5)
+        with self.assertRaises(ValueError):
+            Dataset(self.lat, self.lon, self.time, self.value, 'prec')
 
     def test_values_shape_mismatch(self):
         # If we change lats to this the shape of value will not match
@@ -142,6 +145,26 @@ class TestDatasetFunctions(unittest.TestCase):
     def test_spatial_resolution(self):
         self.assertEqual(self.test_dataset.spatial_resolution(), (2, 2))
 
+    def test_spatial_resolution_2_dim_lat_lon(self):
+        self.lat = np.array([10, 12, 14, 16, 18, 20])
+        self.lon = np.array([100, 102, 104, 106, 108, 110])
+        self.lat = self.lat.reshape(3, 2)
+        self.lon = self.lon.reshape(3, 2)
+        flat_array = np.array(range(72))
+        self.value = flat_array.reshape(12, 3, 2)
+        self.test_dataset = Dataset(self.lat, self.lon, self.time,
+                                    self.value, self.variable)
+        self.assertEqual(self.test_dataset.spatial_resolution(), (6, 6))
+
+    def test_temporal_resolution_hourly(self):
+        self.time = np.array([dt.datetime(2000, 1, 1),
+                              dt.datetime(2000, 1, 1)])
+        flat_array = np.array(range(50))
+        self.value = flat_array.reshape(2, 5, 5)
+        self.test_dataset = Dataset(self.lat, self.lon, self.time,
+                                    self.value, self.variable)
+        self.assertEqual(self.test_dataset.temporal_resolution(), 'minutely')
+
     def test_temporal_resolution_monthly(self):
         self.assertEqual(self.test_dataset.temporal_resolution(), 'monthly')
 
@@ -197,6 +220,22 @@ class TestBounds(unittest.TestCase):
                              dt.datetime(2002, 1, 1))  # End time
         self.another_bounds = Bounds(-80, 80,                # Lats
                                      -160, 160)
+
+    def test_setter_methods(self):
+        self.bounds.lat_min = -10
+        self.bounds.lat_max = 10
+        self.bounds.lon_min = -120
+        self.bounds.lon_max = 120
+        self.bounds.start = dt.datetime(2000, 1, 2)
+        self.bounds.end = dt.datetime(2002, 1, 4)
+
+        self.assertEqual(self.bounds.lat_min, -10)
+        self.assertEqual(self.bounds.lat_max, 10)
+        self.assertEqual(self.bounds.lon_min, -120)
+        self.assertEqual(self.bounds.lon_max, 120)
+        self.assertEqual(self.bounds.start, dt.datetime(2000, 1, 2))
+        self.assertEqual(self.bounds.end, dt.datetime(2002, 1, 4))
+
     # Latitude tests
     def test_inverted_min_max_lat(self):
         with self.assertRaises(ValueError):


[2/2] climate git commit: Add tests for temporal_resolution function

Posted by ja...@apache.org.
Add tests for temporal_resolution function


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

Branch: refs/heads/master
Commit: 5ecaa8e6adedbd07cdefc6f841587953f7343679
Parents: aaa3bc5
Author: Ibrahim <ja...@gmail.com>
Authored: Tue May 31 16:30:38 2016 +0530
Committer: Ibrahim <ja...@gmail.com>
Committed: Tue Jun 14 00:51:58 2016 +0530

----------------------------------------------------------------------
 ocw/tests/test_dataset.py | 75 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 73 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/5ecaa8e6/ocw/tests/test_dataset.py
----------------------------------------------------------------------
diff --git a/ocw/tests/test_dataset.py b/ocw/tests/test_dataset.py
index 8a1bad5..d30fbcc 100644
--- a/ocw/tests/test_dataset.py
+++ b/ocw/tests/test_dataset.py
@@ -142,9 +142,52 @@ class TestDatasetFunctions(unittest.TestCase):
     def test_spatial_resolution(self):
         self.assertEqual(self.test_dataset.spatial_resolution(), (2, 2))
 
-    def test_temporal_resolution(self):
+    def test_temporal_resolution_monthly(self):
         self.assertEqual(self.test_dataset.temporal_resolution(), 'monthly')
 
+    def test_temporal_resolution_daily(self):
+        self.time = np.array([dt.datetime(2000, 3, x) for x in range(1, 31)])
+        flat_array = np.array(range(750))
+        self.value = flat_array.reshape(30, 5, 5)
+        self.test_dataset = Dataset(self.lat, self.lon, self.time,
+                                    self.value, self.variable)
+        self.assertEqual(self.test_dataset.temporal_resolution(), 'daily')
+
+    def test_temporal_resolution_yearly(self):
+        self.time = np.array([dt.datetime(x, 6, 1) for x in range(2000, 2015)])
+        flat_array = np.array(range(375))
+        self.value = flat_array.reshape(15, 5, 5)
+        self.test_dataset = Dataset(self.lat, self.lon, self.time,
+                                    self.value, self.variable)
+        self.assertEqual(self.test_dataset.temporal_resolution(), 'yearly')
+
+    def test_str_(self):
+        dataset = self.test_dataset
+        lat_min, lat_max, lon_min, lon_max = dataset.spatial_boundaries()
+        start, end = dataset.time_range()
+        lat_range = "({}, {})".format(lat_min, lon_min)
+        lon_range = "({}, {})".format(lon_min, lon_min)
+        time_range = "({}, {})".format(start, end)
+
+        formatted_repr = (
+            "<Dataset - name: {}, "
+            "lat-range: {}, "
+            "lon-range: {}, "
+            "time_range: {}, "
+            "var: {}, "
+            "units: {}>"
+        )
+
+        output = formatted_repr.format(
+            dataset.name if dataset.name != "" else None,
+            lat_range,
+            lon_range,
+            time_range,
+            dataset.variable,
+            dataset.units
+        )
+        self.assertEqual(str(self.test_dataset), output)
+
 
 class TestBounds(unittest.TestCase):
     def setUp(self):
@@ -152,7 +195,8 @@ class TestBounds(unittest.TestCase):
                              -160, 160,               # Lons
                              dt.datetime(2000, 1, 1),  # Start time
                              dt.datetime(2002, 1, 1))  # End time
-
+        self.another_bounds = Bounds(-80, 80,                # Lats
+                                     -160, 160)
     # Latitude tests
     def test_inverted_min_max_lat(self):
         with self.assertRaises(ValueError):
@@ -219,5 +263,32 @@ class TestBounds(unittest.TestCase):
         with self.assertRaises(ValueError):
             self.bounds.end = "This is not a date time object"
 
+    # Start tests
+    def test_none_value_start(self):
+        self.assertEqual(self.another_bounds.start, None)
+
+    # End tests
+    def test_none_value_end(self):
+        self.assertEqual(self.another_bounds.end, None)
+
+    def test__str__(self):
+        lat_range = "({}, {})".format(self.bounds.lat_min, self.bounds.lat_max)
+        lon_range = "({}, {})".format(self.bounds.lon_min, self.bounds.lon_max)
+        time_range = "({}, {})".format(self.bounds.start, self.bounds.end)
+
+        formatted_repr = (
+            "<Bounds - "
+            "lat-range: {}, "
+            "lon-range: {}, "
+            "time_range: {}> "
+        )
+
+        output = formatted_repr.format(
+            lat_range,
+            lon_range,
+            time_range,
+        )
+        self.assertEqual(str(self.bounds), output)
+
 if __name__ == '__main__':
     unittest.main()