"""Test :func:`~vacumm.misc.plot.section2` in quiver mode""" # Imports from vcmq import create_lon, N, MV2, create_dep, os, code_file_name, section2 from vacumm.misc.phys.units import deg2m # Init data with z 1D nz = 11 nx = 11 x = create_lon(N.arange(nx)) xm = deg2m(x[:],lat=45.) # meters dx = xm[:].ptp() z = create_dep((-nz+1, 1.), units='m', long_name='Depth') dz = z[:].ptp() scale = dz/dx u = MV2.ones((nz,nx)) # 1 m/s w = u*scale # 1 m/s * scale for var in u,w: var.setAxis(0, z) var.setAxis(1, x) var.units = 'm/s' # Plot figfile = code_file_name(ext='png') if os.path.exists(figfile): os.remove(figfile) s = section2((u,w), quiver_norm=1, fill=False, show=False, savefig=figfile, close=False, axes_aspect=1) # Result result = dict(files=figfile)
# - grille grid = create_grid(lon, lat) # -> ESSAYEZ AVEC LON EXPLICITE gridc = create_grid(lon2d, lat2d) # Verifier print islon(lon) print isgrid(grid) # -> TEST PARAM CURV=... print isrect(gridc) # -> CREEZ GRILLE NON RECT ET RETESTER print isdepthup(dep) # -> TESTEZ EN CHANGEANT ATTRIBUT POSITIVE ET VALEURS print isregular(lon) # Affecter var = MV2.ones(grid.shape) set_grid(var, grid) varc = MV2.ones(gridc.shape) set_grid(varc, gridc) # -> VERIFIEZ ID DES AXES # Récupérer mygrid = get_grid(gridc) # -> TESTEZ AVEC (LON,LAT) ET PARAMS STRICT ET INTERCEPT mylon2d = get_axis(gridc, 1) # -> COMPAREZ AVEC .GETAXIS() # Sélectionner print coord2slice(lon, lon=(2, 4.5))# -> COMPAREZ AVEC .GETINTERVALEXT(...) print coord2slice(grid, lon=(4, 8), lat=(44, 46)) # -> TESTEZ SUR GRIDC # -> TESTEZ VARSEL
# Input grid x0, y0, nx, ny, dx, dy = 0., 0., 20, 15, 5., 5. x = x0 + N.arange(0, nx * dx, dx) y = y0 + N.arange(0, ny * dy, dy) xxbi, yybi = meshbounds(x, y) xb = bounds1d(x) yb = bounds1d(y) lon = create_lon(x) lat = create_lat(y) lon.setBounds(xb) lat.setBounds(yb) gridi = cdms2.createRectGrid(lat, lon) # Input data vari = MV2.ones(gridi.shape) * 50 vari[5:10, 7:13] = -10 #vari[:, -1] = MV2.masked # <<< THIS MAKES IT WORK! vari.setAxisList([gridi.getLatitude(), gridi.getLongitude()]) vari.setGrid(gridi) # Output grid grido, xxbo, yybo = gridi, xxbi, yybi # Regrid diag = {'dstAreaFractions': None} varo = vari.regrid(grido, tool='esmf', method='conservative', diag=diag,
f = cdms2.open(ncfile, 'w') for var in lons, lats, mob, temp_error, sal_error: var.setAxis(-1, paxis) if var.ndim == 2: var.setAxis(0, daxis) f.write(var) f.close() print os.path.abspath(ncfile) # HF radars ncfile = '../data/obs.hfradars.nc' lon = create_lon((-5.8, -4.7, .1)) lat = create_lat((47.8, 48.3, .1)) nx = len(lon) ny = len(lat) u_error = MV2.ones((ny, nx), id='u_error', axes=[lat, lon]) u_error[:] *= .2 u_error[:] += N.resize(N.linspace(0, .1, nx), (ny, nx)) u_error[:2, :2] = u_error[-2:, :2] = N.ma.masked v_error = u_error.clone() v_error.id = 'v_error' mob = MV2.zeros((ny, nx), id='mobility', axes=[lat, lon], dtype='i') f = cdms2.open(ncfile, 'w') for var in mob, u_error, v_error: f.write(var) f.depth = 'surf' f.close() print os.path.abspath(ncfile) # Satellite SST ncfile = '../data/obs.satsst.nc'
lon2d, lat2d = create_axes2d(xx, yy) ii = lon2d.getAxis(1) # - grille grid = create_grid(lon, lat) # -> ESSAYEZ AVEC LON EXPLICITE gridc = create_grid(lon2d, lat2d) # Verifier print islon(lon) print isgrid(grid) # -> TEST PARAM CURV=... print isrect(gridc) # -> CREEZ GRILLE NON RECT ET RETESTER print isdepthup(dep) # -> TESTEZ EN CHANGEANT ATTRIBUT POSITIVE ET VALEURS print isregular(lon) # Affecter var = MV2.ones(grid.shape) set_grid(var, grid) varc = MV2.ones(gridc.shape) set_grid(varc, gridc) # -> VERIFIEZ ID DES AXES # Récupérer mygrid = get_grid( gridc) # -> TESTEZ AVEC (LON,LAT) ET PARAMS STRICT ET INTERCEPT mylon2d = get_axis(gridc, 1) # -> COMPAREZ AVEC .GETAXIS() # Sélectionner print coord2slice(lon, lon=(2, 4.5)) # -> COMPAREZ AVEC .GETINTERVALEXT(...) print coord2slice(grid, lon=(4, 8), lat=(44, 46)) # -> TESTEZ SUR GRIDC # -> TESTEZ VARSEL # Transformer
"""Test :func:`~vacumm.misc.plot.section2` in quiver mode""" # Imports from vcmq import create_lon, N, MV2, create_dep, os, code_file_name, section2 from vacumm.misc.phys.units import deg2m # Init data with z 1D nz = 11 nx = 11 x = create_lon(N.arange(nx)) xm = deg2m(x[:], lat=45.) # meters dx = xm[:].ptp() z = create_dep((-nz + 1, 1.), units='m', long_name='Depth') dz = z[:].ptp() scale = dz / dx u = MV2.ones((nz, nx)) # 1 m/s w = u * scale # 1 m/s * scale for var in u, w: var.setAxis(0, z) var.setAxis(1, x) var.units = 'm/s' # Plot figfile = code_file_name(ext='png') if os.path.exists(figfile): os.remove(figfile) s = section2((u, w), quiver_norm=1, fill=False, show=False, savefig=figfile, close=True,
# Input grid x0, y0, nx, ny, dx, dy = 0., 0., 20, 15, 5., 5. x = x0+N.arange(0, nx*dx, dx) y = y0+N.arange(0, ny*dy, dy) xxbi, yybi = meshbounds(x, y) xb = bounds1d(x) yb = bounds1d(y) lon = create_lon(x) lat = create_lat(y) lon.setBounds(xb) lat.setBounds(yb) gridi = cdms2.createRectGrid(lat, lon) # Input data vari = MV2.ones(gridi.shape)*50 vari[5:10, 7:13] = -10 #vari[:, -1] = MV2.masked # <<< THIS MAKES IT WORK! vari.setAxisList([gridi.getLatitude(), gridi.getLongitude()]) vari.setGrid(gridi) # Output grid grido, xxbo, yybo = gridi, xxbi, yybi # Regrid diag = {'dstAreaFractions':None} varo = vari.regrid(grido, tool='esmf', method='conservative', diag=diag, coordSys='cart') # Norm