climate-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From good...@apache.org
Subject svn commit: r1506657 - in /incubator/climate/branches/RefactorInput/ocw: dataset_processor.py tests/test_dataset_processor.py
Date Wed, 24 Jul 2013 18:38:29 GMT
Author: goodale
Date: Wed Jul 24 18:38:29 2013
New Revision: 1506657

URL: http://svn.apache.org/r1506657
Log:
Progress toward CLIMATE-213: 
- Cleaned up the docstring for _rcmes_spatial_regrid() function
- Added unit test to check the returned data array.shape from _rcmes_spatial_regrid()

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=1506657&r1=1506656&r2=1506657&view=diff
==============================================================================
--- incubator/climate/branches/RefactorInput/ocw/dataset_processor.py (original)
+++ incubator/climate/branches/RefactorInput/ocw/dataset_processor.py Wed Jul 24 18:38:29
2013
@@ -63,17 +63,22 @@ def _rcmes_spatial_regrid(spatial_values
     Perform regridding from one set of lat,lon values onto a new set (lat2,lon2)
     
     :param spatial_values: Values in a spatial grid that need to be regridded
-    :type spatial_values: 2d numpy masked array.  shape (latitude, longitude)
-         lat,lon    - original co-ordinates corresponding to spatial_values values
-         lat2,lon2  - new set of latitudes and longitudes that you want to regrid spatial_values
onto 
-         order      - (optional) interpolation order 1=bi-linear, 3=cubic spline
-         mdi          - (optional) fill value for missing data (used in creation of masked
array)
+    :type spatial_values: 2d masked numpy array.  shape (latitude, longitude)
+    :param lat: Grid of latitude values which map to the spatial values
+    :type lat: 2d numpy array. shape(latitudes, longitudes)
+    :param lon: Grid of longitude values which map to the spatial values
+    :type lon: 2d numpy array. shape(latitudes, longitudes)
+    :param lat2: Grid of NEW latitude values to regrid the spatial_values onto
+    :type lat2: 2d numpy array. shape(latitudes, longitudes)
+    :param lon2: Grid of NEW longitude values to regrid the spatial_values onto
+    :type lon2: 2d numpy array. shape(latitudes, longitudes)
+    :param order: Interpolation order flag.  1=bi-linear, 3=cubic spline
+    :type order: [optional] Integer
+    :param mdi: Fill value for missing data (used in created of masked array output)
+    :type mdi: [optional] Integer *** NOT USED IN THIS FUNCTION ***
 
-    :returns: Regridded data with a shape of (len(lat2), len(lon2))
-    :rtype: Open Climate Workbench Dataset Object
-     Output::
-         regridded_values  - spatial_values regridded onto the new set of lat2,lon2 
-    
+    :returns: Regridded 2d masked numpy array with a shape of (len(lat2), len(lon2))
+    :rtype: (float, float) 
     '''
 
     nlat = spatial_values.shape[0]

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=1506657&r1=1506656&r2=1506657&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
18:38:29 2013
@@ -16,6 +16,9 @@
 #
 
 import unittest
+from ocw import dataset_processor as dp
+import numpy as np
+import numpy.ma as ma
 
 
 class TestTemporalRebin(unittest.TestCase):
@@ -24,9 +27,35 @@ class TestTemporalRebin(unittest.TestCas
         pass
         
     
-    def test__congrid_neighbor(self, values, new_dims, minus_one, offset):
+    def test__congrid_neighbor(self):
         pass
+    
+
+
+class TestRcmesSpatialRegrid(unittest.TestCase):
+
+    def test_return_array_shape(self):
+        spatial_values = np.ones([90,180])
+        spatial_values = ma.array(spatial_values)
+        
+        lat_range = ma.array(range(-89, 90, 2))
+        lon_range = ma.array(range(-179, 180, 2))
+        
+        lats, lons = np.meshgrid(lat_range, lon_range)
+        # Convert these to masked arrays
+        lats = ma.array(lats)
+        lons = ma.array(lons)
+        
+        lat2_range = np.array(range(-89, 90, 4))
+        lon2_range = np.array(range(-179, 180, 4))
+        
+        lats2, lons2 = np.meshgrid(lat2_range, lon2_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)
 
 
 if __name__ == '__main__':



Mime
View raw message