Trajectory animation

Post Reply
yaqiang
Posts: 59
Joined: October 5th, 2015, 10:20 pm
Registered HYSPLIT User: Yes

Trajectory animation

Post by yaqiang »

The sample script for trajectory animation using MeteoInfoLab.

Code: Select all

import time

fn = os.path.join(migl.get_sample_folder(), 'HYSPLIT', 'tdump')
f = addfile_hytraj(fn)
lon = f['lon'][:]
lat = f['lat'][:]
height = f['height'][:]

#Plot
ax = 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.shape
for 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)
Ouput gif animation figure:

Code: Select all

fn = os.path.join(migl.get_sample_folder(), 'HYSPLIT', 'tdump')
f = addfile_hytraj(fn)
lon = f['lon'][:]
lat = f['lat'][:]
height = f['height'][:]

#Plot
ax = 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.shape
for 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()
traj_animation.gif
Post Reply

Return to “MeteoInfo Software”