- 积分
- 55955
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-6-21
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
日本大地震福岛核电站泄漏事件发生后曾利用MeteoInfo脚本程序自动绘制气团轨迹预报图,脚本程序的内容比较丰富(部分代码被注释掉了,实际应用时根据需要取消注释即可),包括ftp自动下载MM5预报的气象数据,调用HYSPLIT的MM5转ARL模块将MM5输出的气象数据转换为HYSPLIT用的ARL格式,自动生成CONTROL文件(HYSPLIT轨迹计算的控制文件),调用HYSPLIT轨迹计算模块自动计算前向气团轨迹(也就是预报),调用MeteoInfo绘制气团轨迹图形,将图形自动ftp上传至指定服务器。MeteoInfo脚本程序其实在业务自动化中有很好的应用前景,不过估计目前也就我自己用用了。
轨迹预报图形:
脚本程序:
# This Python file uses the following encoding: GB2312
import sys
sys.path.append("C:\\Program Files (x86)\\MeteoInfo")
import os
import time
import shutil
import clr
clr.AddReferenceByPartialName("System")
clr.AddReferenceByPartialName("System.Windows.Forms")
clr.AddReferenceByPartialName("System.Drawing")
from System import *
from System.Windows.Forms import *
from System.Drawing import *
clr.AddReference("MeteoInfoC.dll")
from MeteoInfoC import *
from MeteoInfoC.Data import *
from MeteoInfoC.Legend import *
from MeteoInfoC.Layout import *
from MeteoInfoC.Shape import *
from MeteoInfoC.Drawing import *
from ftplib import FTP
# Set variables
Today = DateTime.Now
Today = Today.AddDays(-1)
MetDir = 'E:\\MetData\\'
MetFile = 'MMOUT_DOMAIN1'
MapDir = 'C:\\Program Files (x86)\\MeteoInfo\\Map\\'
## ftp MM5 data
#print 'Login ftp host'
#f = FTP('***.***.***')
#f.login('****', '****')
#f.cwd('****')
#print 'start download MM5 data ...'
#f.retrbinary('RETR %s' % MetFile, open(MetDir + MetFile, 'wb').write)
#print 'MM5 data downloaded!'
#f.quit()
#print 'Quit ftp host'
## Convert MM5 data to ARL data
#print 'Start convert MM5 data to ARL data ...'
#os.system("c:\\hysplit4\\exec\\mm5toarl.exe " + MetDir + MetFile)
#print 'Convert finished'
MetFile = 'DATA1.ARL.' + Today.ToString("yyyyMMdd")
#shutil.copyfile('DATA1.ARL', MetDir + MetFile)
#os.remove('DATA1.ARL')
## Write CONTROL file
#print 'Write CONTROL file ...'
#ctFile = ".\\CONTROL"
#ctf = open(ctFile, 'w')
#ctf.write(Today.ToString("yy MM dd 00") + "\n")
#ctf.write("3\n")
#ctf.write("37.5 141.0 500.0\n")
#ctf.write("37.5 141.0 1500.0\n")
#ctf.write("37.5 141.0 3000.0\n")
#ctf.write("96\n")
#ctf.write("0\n")
#ctf.write("10000.0\n")
#ctf.write("1\n")
#ctf.write(MetDir + "\n")
#ctf.write(MetFile + "\n")
#ctf.write("..\\trajdata\\" + "\n")
trajFile = "Traj_" + Today.ToString("yyyyMMdd")
#ctf.write(trajFile)
#ctf.close()
## Run HYSPLIT trajectory
#print 'Run HYSPLIT trajectory ...'
#os.system("c:\\hysplit4\\exec\\hyts_std.exe ")
# Draw trajectory map
print 'Drawing trajectory map ...'
myApp = MIApp()
myApp.OpenLayer(MapDir + "country1.shp")
myApp.SetLegendBreak("country1.shp",0,Color.LemonChiffon,Color.DarkGray,1,True,True,True)
myApp.OpenLayer(MapDir + "bou2_4p.shp")
myApp.SetLegendBreak("bou2_4p.shp",0,Color.Yellow,Color.Blue,1,True,False,True)
myApp.Zoom(115,210,10,70)
# Open trajectory data
myApp.OpenHYSPLITTraj("..\\trajdata\\" + trajFile)
myApp.SetLegendScheme("..\\trajdata\\traj.lgs")
myApp.SetDrawType("traj_line")
myApp.DisplayTraj()
myApp.MoveLayerToTop("bou2_4p.shp")
myApp.MapLayout.DefaultLayoutMap.Width = 660
title = "福岛第一核电站核泄漏扩散趋势(" + Today.ToString("MM月dd日") + " - " + Today.AddDays(4).ToString("MM月dd日") + ")"
myApp.SetTitle(title)
myApp.MapLayout.DefaultTitle.SetFont("黑体", 13)
myApp.MapLayout.DefaultTitle.Left = 130
myApp.MapLayout.DefaultTitle.Top = 10
myApp.MapLayout.DefaultLegend.LegendStyle = LegendStyleEnum.Normal
myApp.MapLayout.DefaultLegend.Left = 605
myApp.MapLayout.DefaultLegend.Top = 365
myApp.MapLayout.DefaultLegend.DrawNeatLine = True
myApp.MapLayout.DefaultLegend.Title = "气团轨迹"
myApp.MapLayout.DefaultLegend.BackColor = Color.White
myApp.MapLayout.DefaultLegend.Font = Font("Arial", 8)
aPS = PointShape()
aPS.Point = PointD(141.0, 37.5)
aPB = PointBreak()
aPB.Size = 15
aPB.Style = PointStyle.Star
aGraphic = Graphic(aPS, aPB)
myApp.MapLayout.MapView.GraphicCollection.Add(aGraphic)
myApp.MapLayout.MapView.BackColor = Color.LightCyan
myApp.SetAntiAlias(True)
myApp.ReDraw()
outFile = "..\\figure\\Nuclear_Trajectory_" + Today.ToString("yyyyMMdd") + ".png"
myApp.SaveFigure(outFile)
Application.Run(myApp)
# Ftp to NMC
print 'Login NMC ftp host'
ftp = FTP('***.***.***')
ftp.login('****', '****')
ftp.cwd('****')
filelist = []
ftp.retrlines('LIST', filelist.append)
datedir = Today.ToString("yyyyMMdd")
hasdir = False
for f in filelist:
if datedir in f:
hasdir = True
break
if not hasdir:
ftp.mkd(datedir)
ftp.cwd(datedir)
print 'start upload trajectory figure ...'
ftp.storbinary('STOR %s' % os.path.basename(outFile), open(outFile, 'rb'))
print 'Trajectory figure uploaded!'
ftp.quit()
|
评分
-
查看全部评分
|