- 积分
- 55950
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-6-21
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 MeteoInfo 于 2015-12-2 12:39 编辑
在MeteoInfoLab脚本中生成gif动画图要用gifanimation()方法创建一个gif动画:
gifanimation(filename, repeat=0, delay=1000)
方法中第一个参数是gif动画图片的文件名,后面两个参数是可选的,repeat是动画的重复次数,0指的无限次重复;delay指的动画帧之间的时间间隔,单位是毫秒,delay=1000及时间间隔为1秒。
然后在脚本的循环中给gif动画添加帧,用gifaddframe()方法,方法中的参数为之前创建的gif动画变量。
最后用gif动画变量(此例中为animation)的finish()方法结束动画创建过程,同时会完成gif动画图片的写入。
这个示例脚本中的内容很丰富,演示了CUACE-Haze/Fog模式预报的能见度和站点观测的雾-霾天气符号的叠加,从而直观的判断模式的预报效果。
脚本程序:
- #Set data folders
- fcstdir = 'W:/CUACE_out/haze_54'
- obsdir = 'U:/data/micaps'
- mapdir = 'T:/verification/map'
- outdir = 'T:/verification/cases/cuace_54km/result'
- #Set time
- st = datetime.datetime(2015,11,1,0)
- sbjt = st + datetime.timedelta(hours=8)
- #Get forecasting data files
- fcstfn = os.path.join(fcstdir, str(st.year) + '/' + st.strftime('%Y%m') + '/' + \
- st.strftime('%Y%m%d%H') + '/produce/haze_post_aero_' + st.strftime('%Y%m%d%H') + '.ctl')
- print 'Forecasting data file: ' + fcstfn
- fcstf = addfile(fcstfn)
- fcstf.bigendian(True)
- #Plot
- figure(figsize=[768,480], newfig=False)
- axesm(position=[0,0,1,1], xyscale=1.2, tickfontsize=12)
- lworld = shaperead(os.path.join(mapdir, 'country1.shp'))
- lchina = shaperead(os.path.join(mapdir, 'bou2_4p.shp'))
- geoshow(lchina)
- geoshow(lworld, edgecolor='k')
- levs = [0.1, 0.5, 1, 5, 10, 20, 30, 50]
- cols = [(192,0,0),(255,69,0),(255,105,180),(255,128,0),(255,192,128),(51,255,255), \
- (153,255,153),(204,255,204),(255,255,255)]
- #Set weather list - haze, mist and fog
- weathers = [5,10,11,12,40,41,42,43,44,45,46,47,48,49]
- ls = weatherspec(weathers)
- #Add south China Sea
- lscs = shaperead(os.path.join(mapdir, 'bou1_4l.shp'))
- axesm(position=[0.76,0.09,0.16,0.22], axison=False, xyscale=1.2)
- geoshow(lscs, facecolor=(0,0,255))
- xlim(106, 123)
- ylim(2, 23)
- #Set current plot to 1
- currentplot(1)
- #Create gif animation
- giffn = os.path.join(outdir, 'V_vis_' + st.strftime('%Y%m%d') + '--loop-.gif')
- print giffn
- animation = gifanimation(giffn)
- #Loop
- tnum = fcstf.timenum()
- nn = 0
- for t in range(1, 25):
- if nn > 0:
- cll()
- cll()
- tt = fcstf.gettime(t)
- bjt = tt + datetime.timedelta(hours=8)
- obsfn = os.path.join(obsdir, str(bjt.year) + '/plot/' + bjt.strftime('%y%m%d%H.000'))
- if os.path.exists(obsfn):
- print 'Observation data file: ' + obsfn
- obsf = addfile_micaps(obsfn)
- fdata = fcstf['VIS'][t,:,:]
- lfcst = contourfm(fdata, levs, colors=cols, proj=fcstf.proj)
- odata = obsf.stationdata('WeatherNow')
- lobs = scatterm(odata, symbolspec=ls)
- title('CUACE/Haze-Fog visibility (km) ' + sbjt.strftime('%Y-%m-%d %H:00') + \
- ' +' + str(t*3) + ' (' + bjt.strftime('%Y-%m-%d %H:00') + ')', \
- bold=False)
- xlim(68.6, 140.5)
- ylim(17.3, 54)
- colorbar(lfcst, extendrect=False, shrink=0.6)
- #Add frame to gif animation
- gifaddframe(animation)
- nn += 1
- #Finish gif animation
- animation.finish()
- print 'Finished...'
|
|