以下是 netCDF 文件显示的变量:
我编写了这段代码,以便使用 netCDF 文件绘制地中海表面电流:
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/essai.nc')
y = nc.variables['g0_lat_1']
y = np.array(y)
x = nc.variables['g0_lon_2']
x = np.array(x)
u = nc.variables['UOGRD_GDS0_DBSL']
u = np.array(u)
u = u[0, :, :]
u = np.deg2rad(u)
v = nc.variables['VOGRD_GDS0_DBSL']
v = np.array(v)
v = v[0, :, :]
v = np.deg2rad(v)
y, x = np.meshgrid(y,x)
plt.quiver(x [::10], y[::10], u[::10], v[::10], pivot='tail')
plt.show()
这给了我这个:
当我放大时,我们可以看到有箭头和点: 首先,我不知道这些点是什么意思,我无法想象海岸线。然后,我所有的箭头都指向同一个方向!所以我在论坛上找到了这段代码:
# 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()
但它只给我一个箭头。你有什么想法吗?