Skip to content

Commit

Permalink
Merge pull request SciTools#2 from scmc72/Dan_branch
Browse files Browse the repository at this point in the history
Dan branch
  • Loading branch information
JosephHogg committed Jul 9, 2015
2 parents 9916b2a + 366ea7c commit 3441431
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/iris/experimental/pic-backproject/cube-grid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def cube_grid(cube):
#creates and returns a numpy meshgrid of lats and longs from cube
#guess bounds if necessary
if cube.coord('latitude').bounds == None:
cube.coord('latitude').guess_bounds()
if cube.coord('longitude').bounds == None:
cube.coord('longitude').guess_bounds()
#convert long bounds to a 1D array
long_size = cube.coord('longitude').bounds.shape[0]
long_nums = cube.coord('longitude').bounds[:,0].reshape(long_size,1)
long_end = np.asarray(cube.coord('longitude').bounds[-1,1]).reshape(1,1)
long_bounds = np.concatenate((long_nums,long_end)).reshape(1+long_size)
#convert lat bounds to a 1D array
lat_size = cube.coord('latitude').bounds.shape[0]
lat_nums = cube.coord('latitude').bounds[:,0].reshape(lat_size,1)
lat_end = np.asarray(cube.coord('latitude').bounds[-1,1]).reshape(1,1)
lat_bounds = np.concatenate((lat_nums,lat_end)).reshape(1+lat_size)

return np.meshgrid(lat_bounds,long_bounds)
22 changes: 22 additions & 0 deletions lib/iris/experimental/pic-backproject/cube_grid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import iris
import numpy as np

def cube_grid(cube):
#creates and returns a numpy meshgrid of lats and longs from cube
#guess bounds if necessary
if cube.coord('latitude').bounds == None:
cube.coord('latitude').guess_bounds()
if cube.coord('longitude').bounds == None:
cube.coord('longitude').guess_bounds()
#convert long bounds to a 1D array
long_size = cube.coord('longitude').bounds.shape[0]
long_nums = cube.coord('longitude').bounds[:,0].reshape(long_size,1)
long_end = np.asarray(cube.coord('longitude').bounds[-1,1]).reshape(1,1)
long_bounds = np.concatenate((long_nums,long_end)).reshape(1+long_size)
#convert lat bounds to a 1D array
lat_size = cube.coord('latitude').bounds.shape[0]
lat_nums = cube.coord('latitude').bounds[:,0].reshape(lat_size,1)
lat_end = np.asarray(cube.coord('latitude').bounds[-1,1]).reshape(1,1)
lat_bounds = np.concatenate((lat_nums,lat_end)).reshape(1+lat_size)

return np.meshgrid(lat_bounds,long_bounds)

0 comments on commit 3441431

Please sign in to comment.