def nc_div(nc, tidx, grd=None): if grd is None: grd = nc_grid(nc) nc = Dataset(nc) u = nc.variables['u'][tidx] v = nc.variables['v'][tidx] return ( (diff(u, axis=-1)/diff(grd.x_u, axis=-1))[...,1:-1,:] + \ (diff(v, axis=-2)/diff(grd.y_v, axis=-2))[...,:,1:-1] )
def nc_curl(nc, tidx, grd=None): if grd is None: grd = nc_grid(nc) nc = Dataset(nc) u = nc.variables['u'][tidx] v = nc.variables['v'][tidx] return ( diff(v, axis=-1)/diff(grd.x_v, axis=-1) - \ diff(u, axis=-2)/diff(grd.y_u, axis=-2) )
def nc_pstrain(nc, tidx, grd=None): if grd is None: grd = nc_grid(nc) nc = Dataset(nc) u = nc.variables['u'][tidx] v = nc.variables['v'][tidx] ex = (diff(u, axis=-1) / diff(grd.x_u, axis=-1))[..., 1:-1, :] ey = (diff(v, axis=-2) / diff(grd.y_v, axis=-2))[..., :, 1:-1] gamma = shrink ( diff(u, axis=-2)/diff(grd.y_u, axis=-2) + \ diff(v, axis=-1)/diff(grd.x_v, axis=-1) , ex.shape) return 0.5*(ex + ey) + sqrt( (0.5*(ex - ey))**2 + (0.5*gamma)**2 ), \ 0.5*(ex + ey) - sqrt( (0.5*(ex - ey))**2 + (0.5*gamma)**2 )
def nc_pstrain(nc, tidx, grd=None): if grd is None: grd = nc_grid(nc) nc = Dataset(nc) u = nc.variables['u'][tidx] v = nc.variables['v'][tidx] ex = (diff(u, axis=-1)/diff(grd.x_u, axis=-1))[...,1:-1,:] ey = (diff(v, axis=-2)/diff(grd.y_v, axis=-2))[...,:,1:-1] gamma = shrink ( diff(u, axis=-2)/diff(grd.y_u, axis=-2) + \ diff(v, axis=-1)/diff(grd.x_v, axis=-1) , ex.shape) return 0.5*(ex + ey) + sqrt( (0.5*(ex - ey))**2 + (0.5*gamma)**2 ), \ 0.5*(ex + ey) - sqrt( (0.5*(ex - ey))**2 + (0.5*gamma)**2 )