Changeset 17709
- Timestamp:
- 04/10/14 15:46:42 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/interp/interp.py
r17697 r17709 116 116 if npy.ndim(y)==2: 117 117 y=y.reshape(-1,) 118 if len(x) > data.shape[1]+1:119 raise ValueError('x should have same length as ncols(data) +1')120 if len(y) > data.shape[0]+1:121 raise ValueError('y should have same length as nrows(data) +1')118 if len(x) != data.shape[1]+1 and len(x) != data.shape[1]: 119 raise ValueError('x should have same length as ncols(data) or ncols(data)+1') 120 if len(y) != data.shape[0]+1 and len(y) != data.shape[0]: 121 raise ValueError('y should have same length as nrows(data) or nrows(data)+1') 122 122 123 123 # create sub-grid that just covers the limits of xi and yi … … 126 126 xlim=[min(xi)-dx,max(xi)+dx] 127 127 ylim=[min(yi)-dy,max(yi)+dy] 128 xind=npy.nonzero(npy.logical_and(x>xlim[0],x<xlim[1]))[0] 129 yind=npy.nonzero(npy.logical_and(y>ylim[0],y<ylim[1]))[0] 130 subdata=data[yind[0]:yind[-1]+1,xind[0]:xind[-1]+1] 131 128 129 # TODO create grid differently depending on whether data is defined at x,y 130 # or at the center of a grid cell with corner coordinates defined by xi,yi 132 131 # create points array and flattened data array 133 xg,yg=npy.meshgrid(x[xind],y[yind]) 132 if len(x)==data.shape[1] and len(y)==data.shape[0]: 133 print 'x,y taken to define the center of data grid cells' 134 xind=npy.nonzero(npy.logical_and(x>xlim[0],x<xlim[1]))[0] 135 yind=npy.nonzero(npy.logical_and(y>ylim[0],y<ylim[1]))[0] 136 xg,yg=npy.meshgrid(x[xind],y[yind]) 137 subdata=data[yind[0]:yind[-1]+1,xind[0]:xind[-1]+1] 138 elif len(x)==data.shape[1]+1 and len(y)==data.shape[0]+1: 139 print 'x,y taken to define the corners of data grid cells' 140 xcenter=npy.fromiter(((x[i]+x[i+1])/2 for i in range(len(x)-1)),npy.float) 141 ycenter=npy.fromiter(((y[i]+y[i+1])/2 for i in range(len(y)-1)),npy.float) 142 xind=npy.nonzero(npy.logical_and(xcenter>xlim[0],xcenter<xlim[1]))[0] 143 yind=npy.nonzero(npy.logical_and(ycenter>ylim[0],ycenter<ylim[1]))[0] 144 xg,yg=npy.meshgrid(xcenter[xind],ycenter[yind]) 145 subdata=data[yind[0]:yind[-1]+1,xind[0]:xind[-1]+1] 146 else: 147 raise ValueError('x and y have inconsistent sizes: both should have length ncols(data)/nrows(data) or ncols(data)+1/nrows(data)+1') 148 134 149 points=npy.array([xg.ravel(),yg.ravel()]).T 135 150 flatsubdata=subdata.ravel()
Note:
See TracChangeset
for help on using the changeset viewer.