# re-shaping the data a lot easier to manage. uwnd, uwnd_info = prep_data(uwnd, 'tyx') vwnd, vwnd_info = prep_data(vwnd, 'tyx') # It is also required that the latitude dimension is north-to-south. Again the # bundled tools make this easy. lats, uwnd, vwnd = order_latdim(lats, uwnd, vwnd) # Create a VectorWind instance to handle the computation of streamfunction and # velocity potential. w = VectorWind(uwnd, vwnd) # Compute the streamfunction and velocity potential. Also use the bundled # tools to re-shape the outputs to the 4D shape of the wind components as they # were read off files. sf, vp = w.sfvp() sf = recover_data(sf, uwnd_info) vp = recover_data(vp, uwnd_info) # Pick out the field for December and add a cyclic point (the cyclic point is # for plotting purposes). sf_dec, lons_c = addcyclic(sf[11], lons) vp_dec, lons_c = addcyclic(vp[11], lons) # Plot streamfunction. m = Basemap(projection='cyl', resolution='c', llcrnrlon=0, llcrnrlat=-90, urcrnrlon=360.01, urcrnrlat=90) x, y = m(*np.meshgrid(lons_c, lats)) clevs = [-120, -100, -80, -60, -40, -20, 0, 20, 40, 60, 80, 100, 120] m.contourf(x, y, sf_dec*1e-06, clevs, cmap=plt.cm.RdBu_r, extend='both')
# re-shaping the data a lot easier to manage. uwnd, uwnd_info = prep_data(uwnd, 'tyx') vwnd, vwnd_info = prep_data(vwnd, 'tyx') # It is also required that the latitude dimension is north-to-south. Again the # bundled tools make this easy. lats, uwnd, vwnd = order_latdim(lats, uwnd, vwnd) # Create a VectorWind instance to handle the computation of streamfunction and # velocity potential. w = VectorWind(uwnd, vwnd) # Compute the streamfunction and velocity potential. Also use the bundled # tools to re-shape the outputs to the 4D shape of the wind components as they # were read off files. sf, vp = w.sfvp() sf = recover_data(sf, uwnd_info) vp = recover_data(vp, uwnd_info) # Pick out the field for December and add a cyclic point (the cyclic point is # for plotting purposes). sf_dec, lons_c = add_cyclic_point(sf[11], lons) vp_dec, lons_c = add_cyclic_point(vp[11], lons) # Plot streamfunction. ax1 = plt.axes(projection=ccrs.PlateCarree(central_longitude=180)) clevs = [-120, -100, -80, -60, -40, -20, 0, 20, 40, 60, 80, 100, 120] sf_fill = ax1.contourf(lons_c, lats, sf_dec * 1e-06, clevs,
#--- dimensions of the input wind components, and that wind components must be ---- #--- either 2D or 3D arrays. The data read in is 3D and has latitude and ---- #--- longitude as the last dimensions. ---- #--- It is also required that the latitude dimension is north-to-south. Again the ---- #--- bundled tools make this easy. ---- lats_r, uwnd, vwnd = order_latdim(lats,UE_mean_pin,VE_mean_pin) #- Create a VectorWind instance to handle the computation of streamfunction and velocity potential- w = VectorWind(uwnd, vwnd) #--- fonction de courant (sf ; streamfunction) ---- #--- potentiel de vitesse (vp ; velocity potential) ---- sf, vp = w.sfvp() #--- partie divergente du champ = gradient du potentiel de vitesses ---- grad_vp = w.irrotationalcomponent() #--- on masque les continents parce que les valeurs sur les continents sont trop fortes ---- pourcter_ma = ma.array(pourcter,mask=pourcter>0.1) #--- attention on a re-inverse les latitudes pour pouvoir utiliser VectorWind pour calculer ---- #--- le potentiel de vitesse. Donc il faut que le masque colle bien ---- grad_vp_x_ma = ma.array(grad_vp[0],mask=pourcter_ma.mask[::1,:]) grad_vp_y_ma = ma.array(grad_vp[1],mask=pourcter_ma.mask[::1,:])