From commits-return-404-apmail-climate-commits-archive=climate.apache.org@climate.incubator.apache.org Wed Jul 24 16:28:41 2013 Return-Path: X-Original-To: apmail-climate-commits-archive@minotaur.apache.org Delivered-To: apmail-climate-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D10F310AA8 for ; Wed, 24 Jul 2013 16:28:41 +0000 (UTC) Received: (qmail 12227 invoked by uid 500); 24 Jul 2013 16:28:41 -0000 Delivered-To: apmail-climate-commits-archive@climate.apache.org Received: (qmail 12186 invoked by uid 500); 24 Jul 2013 16:28:40 -0000 Mailing-List: contact commits-help@climate.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@climate.incubator.apache.org Delivered-To: mailing list commits@climate.incubator.apache.org Received: (qmail 12178 invoked by uid 99); 24 Jul 2013 16:28:40 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 24 Jul 2013 16:28:40 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 24 Jul 2013 16:28:38 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 6ADF82388860; Wed, 24 Jul 2013 16:28:18 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1506615 - /incubator/climate/branches/RefactorInput/ocw/dataset_processor.py Date: Wed, 24 Jul 2013 16:28:18 -0000 To: commits@climate.incubator.apache.org From: goodale@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20130724162818.6ADF82388860@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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