1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| import netCDF4
from netCDF4 import Dataset
import datetime as dt
import numpy as np
import numpy.ma as ma
from datetime import date, datetime, timedelta
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
nc=Dataset('datasets/Med.nc')
lat = nc.variables['g0_lat_1']
lat = np.array(lat)
lat = lat[:1]
lon = nc.variables['g0_lon_2']
lon = np.array(lon)
lon = lon[:1]
u = nc.variables['UOGRD_GDS0_DBSL']
# u = np.array(u)
u = u[1, :]
v = nc.variables['VOGRD_GDS0_DBSL']
# v = np.array(v)
v = v[1, :]
m = Basemap(llcrnrlon = -15,llcrnrlat = 28,
urcrnrlon = 42,urcrnrlat = 48,
projection='merc',resolution ='l')
# Calculate positions of vectors on map projection
y, x = np.meshgrid(lat,lon)
# Calculate the orientation of the vectors
x1, y1 = m(lon+u, lat+v)
u_map, v_map = x1-x, y1-y
# Rescale the magnitudes of the vectors...
mag_scale = np.hypot(u_map, v_map) / np.hypot(u, v)
u_map /= mag_scale
v_map /= mag_scale
m.quiver(x, y, u_map, v_map)
plt.show() |
Partager