- 积分
- 1028
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2015-6-2
- 最后登录
- 1970-1-1
|
发表于 2020-2-3 13:13:52
|
显示全部楼层
王老师新年好,@MeteoInfo 请问一下,为什么在使用这段代码的时候,只计算1月的tgs,并且计算出来的都是106字节的空文件。麻烦王老师指导一下。
结果如下:
- >>> run script...
- Set paramters...
- Trajectory calculation...
- Month: 1
- Convert trajectory endpoint files to tgs files...
- Join tgs files...
- Convert tgs file to shape file...
- Traceback (most recent call last):
- File "C:\Users\1988y\Desktop\codes\one_year_trajectories.py", line 108, in <module>
- TrajUtil.convertToShapeFile(tgsfn, shpfn)
- at trajstat.trajectory.TrajUtil.convertToShapeFile(TrajUtil.java:423)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
- at java.lang.reflect.Method.invoke(Unknown Source)
- java.lang.NoClassDefFoundError: java.lang.NoClassDefFoundError: org/meteoinfo/data/DataTypes
复制代码 代码如下:
- #-----------------------------------------------------
- # Author: Yaqiang Wang
- # Date: 2014-7-11
- # Purpose: Run TrajStat - calculate trajectories
- # Note: Sample
- #-----------------------------------------------------
- import sys
- sys.path.append('D:/meteoinfo/MeteoInfo_1.4.7R10/MeteoInfo/plugins/TrajStat_Plugin_1.4.4R8/TrajStat/TrajStat.jar')
- import os
- import time
- from datetime import datetime
- from datetime import timedelta
- from calendar import monthrange
- from trajstat.trajectory import TrajUtil
- from trajstat.trajectory import TrajConfig
- # Set working directory
- metDir = 'D:/gdas1/201420152016'
- outDir = 'D:/try'
- # Get month abstract string
- def getmonthstr(m):
- mmm = 'jan'
- if m == 1:
- mmm = 'jan'
- elif m == 2:
- mmm = 'feb'
- elif m == 3:
- mmm = 'mar'
- elif m == 4:
- mmm = 'apr'
- elif m == 5:
- mmm = 'may'
- elif m == 6:
- mmm = 'jun'
- elif m == 7:
- mmm = 'jul'
- elif m == 8:
- mmm = 'aug'
- elif m == 9:
- mmm = 'sep'
- elif m == 10:
- mmm = 'oct'
- elif m == 11:
- mmm = 'nov'
- elif m == 12:
- mmm = 'dec'
- return mmm
- # Get GDAS1 meteorological data files by time
- def getmeteofiles(y, m):
- ystr = str(y)[2:]
- mmm = getmonthstr(m)
- fns = []
- # The meteo files of this month
- cdir = os.path.join(metDir, str(y))
- for i in range(1,6):
- fn = os.path.join(cdir, 'gdas1.' + mmm + ystr + '.w' + str(i))
- if os.path.exists(fn):
- fns.append(fn)
- # The last two meteo files of last month
- m = m - 1
- if m == 0:
- m = 12
- y = y - 1
- ystr = str(y)[2:]
- cdir = os.path.join(metDir, str(y))
- mmm = getmonthstr(m)
- fn = os.path.join(cdir, 'gdas1.' + mmm + ystr + '.w4')
- fns.append(fn)
- fn = os.path.join(cdir, 'gdas1.' + mmm + ystr + '.w5')
- if not os.path.exists(fn):
- fn = os.path.join(cdir, 'gdas1.' + mmm + ystr + '.w3')
- fns.append(fn)
- return fns
- # Set parameters
- print 'Set paramters...'
- year = 2015
- tc = TrajConfig()
- tc.setStartDay(1)
- tc.setStartHours('00')
- tc.setLocation('28 100 500.00')
- tc.setRunHours(-24)
- tc.setTopOfModel(10000.0)
- tc.setVertical(0)
- tc.setOutPath(outDir)
- # Loop - one year calculation
- print 'Trajectory calculation...'
- for month in range(1, 13):
- print 'Month: ' + str(month)
- eday = monthrange(year, month)[1]
- tc.setEndDay(eday)
- tc.initStartTime(year, month)
- fns = getmeteofiles(year, month)
- tc.setMeteoFiles(fns)
- TrajUtil.trajCal(tc)
- print 'Convert trajectory endpoint files to tgs files...'
- TrajUtil.trajToTGS(tc)
- print 'Join tgs files...'
- tgsfn = TrajUtil.joinTGSFiles(tc)
- print 'Convert tgs file to shape file...'
- shpfn = tgsfn.replace('.tgs','.shp')
- TrajUtil.convertToShapeFile(tgsfn, shpfn)
- print 'Remove trajectory files...'
- TrajUtil.removeTrajFiles(tc)
- print 'Finish !'
复制代码
|
|