Repository: climate Updated Branches: refs/heads/master 0f3e8860e -> 66413cf0f
CLIMATE-674 - Update the spatial_regrid module to handle data on curvilinear grids or irregularly spaced grids - ocw.dataset_processor.spatial_regrid is updated to handle two dimensional latitudes and longitudes given as input Project: http://git-wip-us.apache.org/repos/asf/climate/repo Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/06c19a38 Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/06c19a38 Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/06c19a38 Branch: refs/heads/master Commit: 06c19a38ca4758d08633e48c5f3b8d226260234e Parents: 082a3ad Author: huikyole <[email protected]> Authored: Tue Sep 22 16:02:15 2015 -0700 Committer: huikyole <[email protected]> Committed: Tue Sep 22 16:02:15 2015 -0700 ---------------------------------------------------------------------- ocw/dataset_processor.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/climate/blob/06c19a38/ocw/dataset_processor.py ---------------------------------------------------------------------- diff --git a/ocw/dataset_processor.py b/ocw/dataset_processor.py index d7b1a3f..e9e03db 100755 --- a/ocw/dataset_processor.py +++ b/ocw/dataset_processor.py @@ -156,17 +156,27 @@ def spatial_regrid(target_dataset, new_latitudes, new_longitudes): :returns: A new spatially regridded Dataset :rtype: :class:`dataset.Dataset` """ - # Make masked array of shape (times, new_latitudes,new_longitudes) - new_values = ma.zeros([len(target_dataset.times), - len(new_latitudes), - len(new_longitudes)]) - + # Create grids of the given lats and lons for the underlying API - # NOTE: np.meshgrid() requires inputs (x, y) and returns data + # NOTE: np.meshgrid() requires inputs (x, y) and returns data # of shape(y|lat|rows, x|lon|columns). So we pass in lons, lats # and get back data.shape(lats, lons) - lons, lats = np.meshgrid(target_dataset.lons, target_dataset.lats) - new_lons, new_lats = np.meshgrid(new_longitudes, new_latitudes) + if target_dataset.lons.ndim ==1 and target_dataset.lats.ndim ==1: + lons, lats = np.meshgrid(target_dataset.lons, target_dataset.lats) + else: + lons = target_dataset.lons + lats = target_dataset.lats + if new_longitudes.ndim ==1 and new_latitudes.ndim ==1: + new_lons, new_lats = np.meshgrid(new_longitudes, new_latitudes) + else: + new_lons = new_longitudes + new_lats = new_latitudes + + # Make masked array of shape (times, new_latitudes,new_longitudes) + new_values = ma.zeros([len(target_dataset.times), + new_lats.shape[0], + new_lons.shape[1]]) + # Convert all lats and lons into Numpy Masked Arrays lats = ma.array(lats) lons = ma.array(lons)
