def zslice(z, q, qo, mode='spline'): if mode == 'linear': imode = 0 elif mode == 'spline': imode = 1 else: imode = 1 print mode, ' not supported, defaulting to splines' z = atleast_3d(z) q = atleast_3d(q) assert z.shape == q.shape, 'z and q must be the same shape' qo *= ones(q.shape[1:]) q2d = _iso.zslice(z, q, qo, imode) if any(q2d == 1e20): q2d = ma.masked_where(q2d == 1e20, q2d) return q2d
def zslice(z, q, qo, mode='spline'): if mode=='linear': imode=0 elif mode=='spline': imode=1 else: imode=1 print mode, ' not supported, defaulting to splines' z = atleast_3d(z) q = atleast_3d(q) assert z.shape == q.shape, 'z and q must be the same shape' qo *= ones(q.shape[1:]) q2d = _iso.zslice(z, q, qo, imode) if any(q2d==1e20): q2d = ma.masked_where(q2d==1e20, q2d) return q2d
def isoslice(q, z, zo=0, mode='spline'): """Return a slice a 3D field along an isosurface. result is a a projection of variable at property == isoval in the first nonsingleton dimension. In the case when there is more than one zero crossing, the results are averaged. EXAMPLE: Assume two three dimensional variable, s (salt), z (depth), and u (velicity), all on the same 3D grid. x and y are the horizontal positions, with the same horizontal dimensions as z (the 3D depth field). Here, assume the vertical dimension, that will be projected, is the first. s_at_m5 = isoslice(s,z,-5); # s at z == -5 h_at_s30 = isoslice(z,s,30); # z at s == 30 u_at_s30 = isoslice(u,s,30); # u at s == 30 """ if mode == 'linear': imode = 0 elif mode == 'spline': imode = 1 else: imode = 1 raise Warning, '%s not supported, defaulting to splines' % mode z = np.atleast_3d(z) q = np.atleast_3d(q) assert z.shape == q.shape, 'z and q must be the same shape' zo *= np.ones(q.shape[1:]) q2d = _iso.zslice(z, q, zo, imode) if np.any(q2d == 1e20): q2d = np.ma.masked_where(q2d == 1e20, q2d) return q2d
def isoslice(q, z, zo=0, mode='spline'): """Return a slice a 3D field along an isosurface. result is a a projection of variable at property == isoval in the first nonsingleton dimension. In the case when there is more than one zero crossing, the results are averaged. EXAMPLE: Assume two three dimensional variable, s (salt), z (depth), and u (velicity), all on the same 3D grid. x and y are the horizontal positions, with the same horizontal dimensions as z (the 3D depth field). Here, assume the vertical dimension, that will be projected, is the first. s_at_m5 = isoslice(s,z,-5); # s at z == -5 h_at_s30 = isoslice(z,s,30); # z at s == 30 u_at_s30 = isoslice(u,s,30); # u at s == 30 """ if mode=='linear': imode=0 elif mode=='spline': imode=1 else: imode=1 raise Warning, '%s not supported, defaulting to splines' % mode z = np.atleast_3d(z) q = np.atleast_3d(q) assert z.shape == q.shape, 'z and q must be the same shape' zo *= np.ones(q.shape[1:]) q2d = _iso.zslice(z, q, zo, imode) if np.any(q2d==1e20): q2d = np.ma.masked_where(q2d==1e20, q2d) return q2d
def zslice(var, depth, grd, Cpos='rho', vert=False, mode='linear'): """ zslice, lon, lat = zslice(var, depth, grd) optional switch: - Cpos='rho', 'u', 'v' or 'w' specify the C-grid position where the variable rely - vert=True/False If True, return the position of the verticies - mode='linear' or 'spline' specify the type of interpolation return a constant-z slice at depth depth from 3D variable var lon and lat contain the C-grid position of the slice for plotting. If vert=True, lon and lat contain contain the position of the verticies (to be used with pcolor) """ if mode=='linear': imode=0 elif mode=='spline': imode=1 else: imode=0 raise Warning, '%s not supported, defaulting to linear' % mode # compute the depth on Arakawa-C grid position if Cpos is 'u': # average z_r at Arakawa-C u points z = 0.5 * (grd.vgrid.z_r[0,:,:,:-1] + grd.vgrid.z_r[0,:,:,1:]) if vert == True: lon = 0.5 * (grd.hgrid.lon_vert[:,:-1] + grd.hgrid.lon_vert[:,1:]) lat = 0.5 * (grd.hgrid.lat_vert[:,:-1] + grd.hgrid.lat_vert[:,1:]) else: lon = grd.hgrid.lon_u[:] lat = grd.hgrid.lat_u[:] mask = grd.hgrid.mask_u[:] elif Cpos is 'v': # average z_r at Arakawa-C v points z = 0.5 * (grd.vgrid.z_r[0,:,:-1,:] + grd.vgrid.z_r[0,:,1:,:]) if vert == True: lon = 0.5 * (grd.hgrid.lon_vert[:-1,:] + grd.hgrid.lon_vert[1:,:]) lat = 0.5 * (grd.hgrid.lat_vert[:-1,:] + grd.hgrid.lat_vert[1:,:]) else: lon = grd.hgrid.lon_v[:] lat = grd.hgrid.lat_v[:] mask = grd.hgrid.mask_v[:] elif Cpos is 'w': # for temp, salt, rho z = grd.vgrid.z_w[0,:] if vert == True: lon = grd.hgrid.lon_vert[:] lat = grd.hgrid.lat_vert[:] else: lon = grd.hgrid.lon_rho[:] lat = grd.hgrid.lat_rho[:] mask = grd.hgrid.mask_rho[:] elif Cpos is 'rho': # for temp, salt, rho z = grd.vgrid.z_r[0,:] if vert == True: lon = grd.hgrid.lon_vert[:] lat = grd.hgrid.lat_vert[:] else: lon = grd.hgrid.lon_rho[:] lat = grd.hgrid.lat_rho[:] mask = grd.hgrid.mask_rho[:] else: raise Warning, '%s bad position. Valid Arakawa-C are \ rho, u or v.' % Cpos assert len(z.shape) == 3, 'z must be 3D' assert len(var.shape) == 3, 'var must be 3D' assert z.shape == var.shape, 'data and prop must be the same size' depth = -abs(depth) depth = depth * np.ones(z.shape[1:]) zslice = _iso.zslice(z, var, depth, imode) # mask land zslice = np.ma.masked_where(mask == 0, zslice) # mask region with shalower depth than requisted depth zslice = np.ma.masked_where(zslice == 1e20, zslice) return zslice, lon, lat