climate-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From good...@apache.org
Subject svn commit: r1506680 - in /incubator/climate/branches/RefactorInput/ocw: dataset_processor.py tests/test_dataset_processor.py
Date Wed, 24 Jul 2013 19:47:50 GMT
Author: goodale
Date: Wed Jul 24 19:47:49 2013
New Revision: 1506680

URL: http://svn.apache.org/r1506680
Log:
Progress toward CLIMATE-213: Test Driving the development of dataset_processor.spatial_regrid()
- Added tests to check the returned Latitude and Longitude Arrays

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

Modified: incubator/climate/branches/RefactorInput/ocw/dataset_processor.py
URL: http://svn.apache.org/viewvc/incubator/climate/branches/RefactorInput/ocw/dataset_processor.py?rev=1506680&r1=1506679&r2=1506680&view=diff
==============================================================================
--- incubator/climate/branches/RefactorInput/ocw/dataset_processor.py (original)
+++ incubator/climate/branches/RefactorInput/ocw/dataset_processor.py Wed Jul 24 19:47:49
2013
@@ -15,6 +15,8 @@
 #  limitations under the License.
 #
 
+from ocw import dataset as ds
+
 import numpy as np
 import numpy.ma as ma
 import scipy.interpolate
@@ -38,22 +40,32 @@ def temporal_rebin(Dataset, temporal_res
     # Dataset will be changed 
     pass
 
-def spatial_regrid(Dataset, lon_resolution, lat_resolution):
-    """ Regrid a Dataset using the new latitude and longitude resolutions
-    
-    :param Dataset: Dataset object that need temporal regridding applied
-    :type Dataset: Open Climate Workbench Dataset Object
-    :param lon_resolution: Longitude resolution in degrees
-    :type lon_resolution: float
-    :param lat_resolution: Latitude resolution in degrees
-    :type lat_resolution: float
-    
+def spatial_regrid(target_dataset, new_latitudes, new_longitudes):
+    """ Regrid a Dataset using the new latitudes and longitudes
+
+    :param target_dataset: Dataset object that needs temporal regridding applied
+    :type target_dataset: Open Climate Workbench Dataset Object
+    :param new_latitudes: Array of latitudes
+    :type new_latitudes: 1d Numpy Array
+    :param new_longitudes: Array of longitudes
+    :type new_longitudes: 1d Numpy Array
+
     :returns: A new spatially regridded Dataset
     :rtype: Open Climate Workbench Dataset Object
     """
+    # Create an empty Numpy Array of shape (len(Dataset.times), len(new_latitudes), len(new_longitudes))
+    
+    # Extract the Dataset.values, existing lats and lons
+    
+    # Create Meshgrids of the existing lats and lons
+    
+    # Call _rcmes_spatial_regrid on each time slice 
     # This will call down to the _congrid() function and the lat and lon 
     # axis will be adjusted with the time axis being held constant
-    pass
+    
+    # Create a new Dataset Object to return using new data
+    regridded_dataset = ds.Dataset(new_latitudes, new_longitudes, target_dataset.times, target_dataset.values)
+    return regridded_dataset
 
 def ensemble(datasets):
     pass

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=1506680&r1=1506679&r2=1506680&view=diff
==============================================================================
--- incubator/climate/branches/RefactorInput/ocw/tests/test_dataset_processor.py (original)
+++ incubator/climate/branches/RefactorInput/ocw/tests/test_dataset_processor.py Wed Jul 24
19:47:49 2013
@@ -16,7 +16,9 @@
 #
 
 import unittest
+import datetime
 from ocw import dataset_processor as dp
+from ocw import dataset as ds
 import numpy as np
 import numpy.ma as ma
 
@@ -57,6 +59,31 @@ class TestRcmesSpatialRegrid(unittest.Te
         regridded_values = dp._rcmes_spatial_regrid(spatial_values, lats, lons, lats2, lons2)
         self.assertEqual(regridded_values.shape, lats2.shape)
 
+class TestSpatialRegrid(unittest.TestCase):
+    
+    def setUp(self):
+        self.lats = np.array(range(-89, 90, 2))
+        self.lons = np.array(range(-179, 180, 2))
+        # Ten Years of monthly data
+        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
+    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)
+    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)
+
+
+
+
 
 if __name__ == '__main__':
     unittest.main()
\ No newline at end of file



Mime
View raw message