Animated version of Gulf Stream sea surface temperatures done with @oceanographer from yesterday - inspired by the moving media #artinstallations @refikanadol! Shading and texture comes from simulated zonal currents #SciArt @neuro_rish@matplotlib #FESOM2 FESOM2 SST shaded by U component of velocityExample of scalar field visualization shaded by corresponding vector field.Data used are from FESOM2 modelsimulations with 1km resolutionin Gulf Stream area. Data areinterpolated to regular 1/100 degree grid. 数据空间上进行了插值,大概就是1km左右的格点分辨率了。 链接: (数据+代码+测试图) 代码:
( z4 Z9 \: p% Y" H3 s1 Z6 o2 |: f# @[Python] 纯文本查看 复制代码 importxarray asxr
importnumpy asnp
importmatplotlib.pylab asplt
importmatplotlib.cm ascm
###Download data:
#wget [url]https://zenodo.org/record/4759091/files/GF_FESOM2_testdata.tar.gz[/url]
###Unpack data:
#gunzip GF_FESOM2_testdata.tar.gz
#tar -xvf GF_FESOM2_testdata.tar
###Open netCDF files
sst = xr.open_dataset('./GF_FESOM2_testdata/sst.nc')
u = xr.open_dataset('./GF_FESOM2_testdata/u_surf.nc')
v = xr.open_dataset('./GF_FESOM2_testdata/v_surf.nc')
###Plot the figure with U shading
fig, ax = plt.subplots(
1,
1,
constrained_layout=True,
figsize=(10,10),
)
ax.imshow(np.flipud(sst.sst.values), cmap=cm.RdBu_r, vmin=12, vmax=24)
ax.imshow(np.flipud(u.u_surf.values), alpha=0.3, cmap=cm.gray, vmin=-.3, vmax=0.3)
ax.axis('off');
### plt.savefig('./out_figure.png', dpi=300)
###Plot the figure with V shading
fig, ax = plt.subplots(
1,
1,
constrained_layout=True,
figsize=(10,10),
)
ax.imshow(np.flipud(sst.sst.values), cmap=cm.RdBu_r, vmin=12, vmax=24)
ax.imshow(np.flipud(v.v_surf.values), alpha=0.3, cmap=cm.gray, vmin=-.3, vmax=0.3)
ax.axis('off');
###Rotate "light source" for U by 45 degrees
direct = np.rad2deg(np.arctan2(v.v_surf.values, u.u_surf.values))
speed_rot = np.hypot(u.u_surf.values, v.v_surf.values)
myangle = 45
U = speed_rot * np.cos(np.deg2rad(myangle - direct))
# V = speed_rot * np.sin(np.deg2rad(myangle - direct))
fig, ax = plt.subplots(
1,
1,
constrained_layout=True,
figsize=(10,10),
)
ax.imshow(np.flipud(sst.sst.values), cmap=cm.RdBu_r, vmin=12, vmax=24)
ax.imshow(np.flipud(U), alpha=0.3, cmap=cm.gray, vmin=-.3, vmax=0.3)
ax.axis('off');
. b( t P+ k N! A) t7 P) \测试图:
把高分辨率的图拼起来,帧数至少得30 FPS看起来视频就很丝滑了!
+ F2 K1 ?% |6 J3 O }5 Z; _
* J$ g$ y( F8 T+ Y* e3 f
' F3 v# O% p( R. V! |
2 C) ~$ ~8 m1 g5 \& ?) H9 x4 I- l : Y/ W7 F( F X- g* `1 ~/ F' y7 Q
|