climate-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From good...@apache.org
Subject svn commit: r1506615 - /incubator/climate/branches/RefactorInput/ocw/dataset_processor.py
Date Wed, 24 Jul 2013 16:28:18 GMT
Author: goodale
Date: Wed Jul 24 16:28:18 2013
New Revision: 1506615

URL: http://svn.apache.org/r1506615
Log:
Progress toward CLIMATE-213: Variable renaming and docstring changes

Modified:
    incubator/climate/branches/RefactorInput/ocw/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=1506615&r1=1506614&r2=1506615&view=diff
==============================================================================
--- incubator/climate/branches/RefactorInput/ocw/dataset_processor.py (original)
+++ incubator/climate/branches/RefactorInput/ocw/dataset_processor.py Wed Jul 24 16:28:18
2013
@@ -58,24 +58,26 @@ def spatial_regrid(Dataset, lon_resoluti
 def ensemble(datasets):
     pass
 
-def _rcmes_spatial_regrid(q, lat, lon, lat2, lon2, order=1, mdi=-999999999):
+def _rcmes_spatial_regrid(spatial_values, lat, lon, lat2, lon2, order=1, mdi=-999999999):
     '''
-     Perform regridding from one set of lat,lon values onto a new set (lat2,lon2)
+    Perform regridding from one set of lat,lon values onto a new set (lat2,lon2)
     
-     Input::
-         q          - the variable to be regridded
-         lat,lon    - original co-ordinates corresponding to q values
-         lat2,lon2  - new set of latitudes and longitudes that you want to regrid q onto

+    :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)
-      
+
+    :returns: Regridded data with a shape of (len(lat2), len(lon2))
+    :rtype: Open Climate Workbench Dataset Object
      Output::
-         q2  - q regridded onto the new set of lat2,lon2 
+         regridded_values  - spatial_values regridded onto the new set of lat2,lon2 
     
     '''
 
-    nlat = q.shape[0]
-    nlon = q.shape[1]
+    nlat = spatial_values.shape[0]
+    nlon = spatial_values.shape[1]
 
     nlat2 = lat2.shape[0]
     nlon2 = lon2.shape[1]
@@ -118,34 +120,34 @@ def _rcmes_spatial_regrid(q, lat, lon, l
     # Preserve MDI mask, by only changing data part of masked array object.
     for shift in (-1, 1):
         for axis in (0, 1):
-            q_shifted = np.roll(q, shift=shift, axis=axis)
-            idx = ~q_shifted.mask * q.mask
-            q.data[idx] = q_shifted[idx]
+            q_shifted = np.roll(spatial_values, shift=shift, axis=axis)
+            idx = ~q_shifted.mask * spatial_values.mask
+            spatial_values.data[idx] = q_shifted[idx]
 
     # Now we actually interpolate
     # map_coordinates does cubic interpolation by default, 
     # use "order=1" to preform bilinear interpolation instead...
-    q2 = map_coordinates(q, [lati, loni], order=order)
-    q2 = q2.reshape([nlat2, nlon2])
+    regridded_values = map_coordinates(spatial_values, [lati, loni], order=order)
+    regridded_values = regridded_values.reshape([nlat2, nlon2])
 
     # Set values to missing data outside of original domain
-    q2 = ma.masked_array(q2, mask=np.logical_or(np.logical_or(lat2 >= lat.max(), 
+    regridded_values = ma.masked_array(regridded_values, mask=np.logical_or(np.logical_or(lat2
>= lat.max(), 
                                                               lat2 <= lat.min()), 
                                                 np.logical_or(lon2 <= lon.min(), 
                                                               lon2 >= lon.max())))
     
     # Make second map using nearest neighbour interpolation -use this to determine locations
with MDI and mask these
-    qmdi = np.zeros_like(q)
-    qmdi[q.mask == True] = 1.
-    qmdi[q.mask == False] = 0.
+    qmdi = np.zeros_like(spatial_values)
+    qmdi[spatial_values.mask == True] = 1.
+    qmdi[spatial_values.mask == False] = 0.
     qmdi_r = map_coordinates(qmdi, [lati, loni], order=order)
     qmdi_r = qmdi_r.reshape([nlat2, nlon2])
     mdimask = (qmdi_r != 0.0)
     
     # Combine missing data mask, with outside domain mask define above.
-    q2.mask = np.logical_or(mdimask, q2.mask)
+    regridded_values.mask = np.logical_or(mdimask, regridded_values.mask)
 
-    return q2
+    return regridded_values
 
 def _congrid(a, newdims, method='linear', centre=False, minusone=False):
     '''
@@ -198,15 +200,6 @@ def _congrid(a, newdims, method='linear'
 
     if method == 'neighbour':
         newa = _congrid_neighbor(a, newdims, m1, ofs)
-        """
-        for i in range( ndims ):
-            base = np.indices(newdims)[i]
-            dimlist.append( (old[i] - m1) / (newdims[i] - m1) \
-                            * (base + ofs) - ofs )
-        cd = np.array( dimlist ).round().astype(int)
-        newa = a[list( cd )]
-        return newa
-        """
 
     elif method in ['nearest','linear']:
         # calculate new dims
@@ -281,5 +274,5 @@ def _congrid_neighbor(values, new_dims, 
         dimlist.append( (old_dims[i] - minus_one) / (new_dims[i] - minus_one) \
                         * (base + offset) - offset )
     cd = np.array( dimlist ).round().astype(int)
-    new_values = a[list( cd )]
+    new_values = values[list( cd )]
     return new_values    
\ No newline at end of file



Mime
View raw message