You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@climate.apache.org by go...@apache.org on 2013/11/11 16:08:43 UTC

svn commit: r1540747 - in /incubator/climate/trunk/ocw: dataset_processor.py tests/test_dataset_processor.py

Author: goodale
Date: Mon Nov 11 15:08:43 2013
New Revision: 1540747

URL: http://svn.apache.org/r1540747
Log:
CLIMATE-321: Fixed Subregion Slicing Method

Modified:
    incubator/climate/trunk/ocw/dataset_processor.py
    incubator/climate/trunk/ocw/tests/test_dataset_processor.py

Modified: incubator/climate/trunk/ocw/dataset_processor.py
URL: http://svn.apache.org/viewvc/incubator/climate/trunk/ocw/dataset_processor.py?rev=1540747&r1=1540746&r2=1540747&view=diff
==============================================================================
--- incubator/climate/trunk/ocw/dataset_processor.py (original)
+++ incubator/climate/trunk/ocw/dataset_processor.py Mon Nov 11 15:08:43 2013
@@ -697,11 +697,11 @@ def _get_subregion_slice_indices(subregi
 
     :returns: The indices to slice the Datasets arrays as a Dictionary.
     '''
-    latStart = np.nonzero(target_dataset.lats == subregion.lat_min)[0][0]
-    latEnd = np.nonzero(target_dataset.lats == subregion.lat_max)[0][0]
+    latStart = min(np.nonzero(target_dataset.lats >= subregion.lat_min)[0])
+    latEnd = max(np.nonzero(target_dataset.lats <= subregion.lat_max)[0])
 
-    lonStart = np.nonzero(target_dataset.lons == subregion.lon_min)[0][0]
-    lonEnd = np.nonzero(target_dataset.lons == subregion.lon_max)[0][0]
+    lonStart = min(np.nonzero(target_dataset.lons >= subregion.lon_min)[0])
+    lonEnd = max(np.nonzero(target_dataset.lons <= subregion.lon_max)[0])
 
     timeStart = np.nonzero(target_dataset.times == subregion.start)[0][0]
     timeEnd = np.nonzero(target_dataset.times == subregion.end)[0][0]

Modified: incubator/climate/trunk/ocw/tests/test_dataset_processor.py
URL: http://svn.apache.org/viewvc/incubator/climate/trunk/ocw/tests/test_dataset_processor.py?rev=1540747&r1=1540746&r2=1540747&view=diff
==============================================================================
--- incubator/climate/trunk/ocw/tests/test_dataset_processor.py (original)
+++ incubator/climate/trunk/ocw/tests/test_dataset_processor.py Mon Nov 11 15:08:43 2013
@@ -172,6 +172,12 @@ class TestSubset(unittest.TestCase):
             datetime.datetime(2001, 1, 1), 
             datetime.datetime(2004, 1, 1)
         )
+        self.non_exact_subregion = ds.Bounds(
+            -80.25, 80.5, 
+            -160.25, 160.5, 
+            datetime.datetime(2001, 1, 1), 
+            datetime.datetime(2004, 1, 1)
+        )
 
     def test_subset(self):
         subset = dp.subset(self.subregion, self.target_dataset)
@@ -181,6 +187,16 @@ class TestSubset(unittest.TestCase):
         self.assertEqual(subset.lons.shape[0], 162)
         self.assertEqual(subset.times.shape[0], 37)
         self.assertEqual(subset.values.shape, (37, 82, 162))
+    
+    def test_subset_using_non_exact_spatial_bounds(self):
+        index_slices = dp._get_subregion_slice_indices(self.non_exact_subregion,  self.target_dataset)
+        control_index_slices = {"lat_start"  : 5,
+                                "lat_end"    : 84,
+                                "lon_start"  : 10,
+                                "lon_end"    : 169,
+                                "time_start" : 12, 
+                                "time_end"   : 48}
+        self.assertDictEqual(index_slices, control_index_slices)
 
 class TestFailingSubset(unittest.TestCase):
     def setUp(self):