The sample script for trajectory animation using MeteoInfoLab.
Ouput gif animation figure:
CODE:
import timefn = os.path.join(migl.get_sample_folder(), 'HYSPLIT', 'tdump')f = addfile_hytraj(fn)lon = f['lon'][:]lat = f['lat'][:]height = f['height'][:]#Plotax = axesm()geoshow('country', edgecolor='gray', facecolor=(230,230,230))levs = arange(0, 600, 50)scatter(lon[:,0], lat[:,0], size=6, color='r', marker='S')yticks(arange(35, 54, 5))title('Trajectory')ntraj, npoint = lon.shapefor i in range(2, npoint+1): if i > 2: cll() cll() tlayer = plot(lon[:,-i:], lat[:,-i:], zvalues=height[:,-i:], levels=levs, linewidth=2) scatter(lon[:,-i], lat[:,-i], marker='s', size=5, edgecolor='m', facecolor=None) if i == 2: colorbar(tlayer) xlim(-92, -55) ylim(34, 54) plt.draw() time.sleep(0.1)
CODE:
fn = os.path.join(migl.get_sample_folder(), 'HYSPLIT', 'tdump')f = addfile_hytraj(fn)lon = f['lon'][:]lat = f['lat'][:]height = f['height'][:]#Plotax = axesm()geoshow('country', edgecolor='gray', facecolor=(230,230,230))levs = arange(0, 600, 50)scatter(lon[:,0], lat[:,0], size=6, color='r', marker='S')yticks(arange(35, 54, 5))title('Trajectory')giffn = 'D:/Temp/test/traj_animation.gif'animation = gifanimation(giffn, delay=100)ntraj, npoint = lon.shapefor i in range(2, npoint+1): print(i) if i > 2: cll() cll() tlayer = plot(lon[:,-i:], lat[:,-i:], zvalues=height[:,-i:], levels=levs, linewidth=2) scatter(lon[:,-i], lat[:,-i], marker='s', size=5, edgecolor='m', facecolor=None) if i == 2: colorbar(tlayer) xlim(-92, -55) ylim(34, 54) plt.draw() gifaddframe(animation)animation.finish()
Statistics: Posted by yaqiang — November 3rd, 2023, 4:42 am