climate-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From good...@apache.org
Subject svn commit: r1508594 - /incubator/climate/branches/RefactorInput/ocw/tests/test_dataset_processor.py
Date Tue, 30 Jul 2013 20:03:20 GMT
Author: goodale
Date: Tue Jul 30 20:03:20 2013
New Revision: 1508594

URL: http://svn.apache.org/r1508594
Log:
CLIMATE-213 - Updated the tests for dataset_processor module after finally understanding how
numpy.meshgrid works

Modified:
    incubator/climate/branches/RefactorInput/ocw/tests/test_dataset_processor.py

Modified: incubator/climate/branches/RefactorInput/ocw/tests/test_dataset_processor.py
URL: http://svn.apache.org/viewvc/incubator/climate/branches/RefactorInput/ocw/tests/test_dataset_processor.py?rev=1508594&r1=1508593&r2=1508594&view=diff
==============================================================================
--- incubator/climate/branches/RefactorInput/ocw/tests/test_dataset_processor.py (original)
+++ incubator/climate/branches/RefactorInput/ocw/tests/test_dataset_processor.py Tue Jul 30
20:03:20 2013
@@ -43,7 +43,7 @@ class TestRcmesSpatialRegrid(unittest.Te
         lat_range = ma.array(range(-89, 90, 2))
         lon_range = ma.array(range(-179, 180, 2))
         
-        lats, lons = np.meshgrid(lat_range, lon_range)
+        lons, lats = np.meshgrid(lon_range, lat_range)
         # Convert these to masked arrays
         lats = ma.array(lats)
         lons = ma.array(lons)
@@ -51,13 +51,14 @@ class TestRcmesSpatialRegrid(unittest.Te
         lat2_range = np.array(range(-89, 90, 4))
         lon2_range = np.array(range(-179, 180, 4))
         
-        lats2, lons2 = np.meshgrid(lat2_range, lon2_range)
+        lons2, lats2 = np.meshgrid(lon2_range, lat2_range)
         # Convert to masked arrays
         lats2 = ma.array(lats2)
         lons2 = ma.array(lons2)
 
         regridded_values = dp._rcmes_spatial_regrid(spatial_values, lats, lons, lats2, lons2)
         self.assertEqual(regridded_values.shape, lats2.shape)
+        self.assertEqual(regridded_values.shape, lons2.shape)
 
 class TestSpatialRegrid(unittest.TestCase):
     
@@ -68,18 +69,23 @@ class TestSpatialRegrid(unittest.TestCas
         self.times = np.array([datetime.datetime(year, month, 1) for year in range(2000,
2010) for month in range(1, 13)])
         self.values = np.ones([len(self.times), len(self.lats), len(self.lons)])
         self.input_dataset = ds.Dataset(self.lats, self.lons, self.times, self.values, variable="test
variable name")
-        self.new_lons = np.array(range(-179, 180, 5))
         self.new_lats = np.array(range(-89, 90, 4))
-    # Custome Assertions to handle Numpy Arrays
+        self.new_lons = np.array(range(-179, 180, 4))
+        self.regridded_dataset = dp.spatial_regrid(self.input_dataset, self.new_lats, self.new_lons)
+    # Custom Assertions to handle Numpy Arrays
     def assert1DArraysEqual(self, array1, array2):
         self.assertSequenceEqual(tuple(array1), tuple(array2))
 
     def test_returned_lats(self):
-        regridded_dataset = dp.spatial_regrid(self.input_dataset, self.new_lats, self.new_lons)
-        self.assert1DArraysEqual(regridded_dataset.lats, self.new_lats)
+        self.assert1DArraysEqual(self.regridded_dataset.lats, self.new_lats)
+
     def test_returned_lons(self):
-        regridded_dataset = dp.spatial_regrid(self.input_dataset, self.new_lats, self.new_lons)
-        self.assert1DArraysEqual(regridded_dataset.lons, self.new_lons)
+        self.assert1DArraysEqual(self.regridded_dataset.lons, self.new_lons)
+
+    def test_shape_of_values(self):
+        regridded_data_shape = self.regridded_dataset.values.shape
+        expected_data_shape = (len(self.times), len(self.new_lats), len(self.new_lons))
+        self.assertSequenceEqual(regridded_data_shape, expected_data_shape)
 
 
 



Mime
View raw message