You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@climate.apache.org by bo...@apache.org on 2013/11/18 17:07:49 UTC

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

Author: boustani
Date: Mon Nov 18 16:07:48 2013
New Revision: 1543063

URL: http://svn.apache.org/r1543063
Log:
[CLIMATE-322] The dataset_processor now can select subregion of dataset by given imprecise start and end time

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=1543063&r1=1543062&r2=1543063&view=diff
==============================================================================
--- incubator/climate/trunk/ocw/dataset_processor.py (original)
+++ incubator/climate/trunk/ocw/dataset_processor.py Mon Nov 18 16:07:48 2013
@@ -703,8 +703,9 @@ def _get_subregion_slice_indices(subregi
     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]
+
+    timeStart = min(np.nonzero(target_dataset.times >= subregion.start)[0])
+    timeEnd = max(np.nonzero(target_dataset.times <= subregion.end)[0])
 
     return {
         "lat_start"  : latStart,

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=1543063&r1=1543062&r2=1543063&view=diff
==============================================================================
--- incubator/climate/trunk/ocw/tests/test_dataset_processor.py (original)
+++ incubator/climate/trunk/ocw/tests/test_dataset_processor.py Mon Nov 18 16:07:48 2013
@@ -172,12 +172,18 @@ class TestSubset(unittest.TestCase):
             datetime.datetime(2001, 1, 1), 
             datetime.datetime(2004, 1, 1)
         )
-        self.non_exact_subregion = ds.Bounds(
+        self.non_exact_spatial_subregion = ds.Bounds(
             -80.25, 80.5, 
             -160.25, 160.5, 
             datetime.datetime(2001, 1, 1), 
             datetime.datetime(2004, 1, 1)
         )
+        self.non_exact_temporal_subregion = ds.Bounds(
+            -80.25, 80.5, 
+            -160.25, 160.5,
+            datetime.datetime(2001, 1, 15), 
+            datetime.datetime(2004, 2, 15)
+        )
 
     def test_subset(self):
         subset = dp.subset(self.subregion, self.target_dataset)
@@ -189,7 +195,7 @@ class TestSubset(unittest.TestCase):
         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)
+        index_slices = dp._get_subregion_slice_indices(self.non_exact_spatial_subregion,  self.target_dataset)
         control_index_slices = {"lat_start"  : 5,
                                 "lat_end"    : 84,
                                 "lon_start"  : 10,
@@ -198,6 +204,16 @@ class TestSubset(unittest.TestCase):
                                 "time_end"   : 48}
         self.assertDictEqual(index_slices, control_index_slices)
 
+    def test_subset_using_non_exact_temporal_bounds(self):
+        index_slices = dp._get_subregion_slice_indices(self.non_exact_temporal_subregion,  self.target_dataset)
+        control_index_slices = {"lat_start"  : 5,
+                                "lat_end"    : 84,
+                                "lon_start"  : 10,
+                                "lon_end"    : 169,
+                                "time_start" : 13, 
+                                "time_end"   : 49}
+        self.assertDictEqual(index_slices, control_index_slices)
+
 class TestFailingSubset(unittest.TestCase):
     def setUp(self):
         self.target_dataset = ten_year_monthly_dataset()