- 积分
- 225
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2015-1-4
- 最后登录
- 1970-1-1
|
发表于 2016-9-26 17:54:10
|
显示全部楼层
#--------------------------------------------------------
# Author: Yaqiang Wang
# Date: 2014-9-11
# Purpose: Extract station PBL data from ARL meteorological data
# Note: Sample
#-----------------------------------------------------------
from org.meteoinfo.data.meteodata import MeteoDataInfo
import os.path
from java.util import Date
from java.util import Calendar
from java.util import Locale
from java.text import SimpleDateFormat
#---- Set directories
dataDir = 'F:\\20160826\\meteodata\\2006'
#---- Set times - this case show seasonal variation
cal = Calendar.getInstance()
cal.set(2006, 10, 1)
sTime = cal.getTime()
cal.set(2006, 11, 1)
eTime = cal.getTime()
aTime = sTime
format = SimpleDateFormat('MMMyy', Locale.ENGLISH)
format1 = SimpleDateFormat('yyyy-MM-dd HH:00')
format2 = SimpleDateFormat('yyyyMMddHH')
cal.setTime(sTime)
#---- Create a MeteoDataInfo object
mydata = MeteoDataInfo()
#---- Set lon/lat of the location
lon = 116.30
lat = 39.99
#---- Set output text file
outpath = os.path.join(dataDir, 'PBL_data-1.txt')
outf = open(outpath, 'w')
outf.write('Time,PBLH')
#---- Loop
i = 0
sum = 0.0
while aTime <= eTime:
for w in range(5):
inFile = dataDir + 'gdas1.' + format.format(aTime) + '.w' + str(w + 1)
print inFile
if os.path.isfile(inFile):
mydata.openARLData(inFile) #Open ARL data file
tNum = mydata.getDataInfo().getTimeNum()
print tNum
for t in range(tNum):
dTime = mydata.getDataInfo().getTimes().get(t)
print format1.format(dTime)
mydata.setTimeIndex(t) #Set time index
gData = mydata.getGridData("PBLH") #Get PBLH grid data
pblh = gData.toStation(lon, lat) #Intepolate PBLH data to the location
print 'PBLH = %10.2f' %pblh
outf.write(os.linesep)
outf.write(format2.format(dTime) + ',%-7.2f ' %pblh)
sum += pblh
i += 1
cal.add(Calendar.MONTH, 1)
aTime = cal.getTime()
outf.close()
#---- Calculate seasonal average PBLH value
ave = sum / i
print 'Average PBLH: %10.2f' %ave
print 'Finished!'
改写提取PBLH数据代码后,为什么提示下面的错误?
F:\20160826\meteodata\2006gdas1.Dec06.w3
F:\20160826\meteodata\2006gdas1.Dec06.w4
F:\20160826\meteodata\2006gdas1.Dec06.w5
Traceback (most recent call last):
File "<iostream>", line 62, in <module>
ZeroDivisionError: float division
line 62 为:ave = sum / i
|
|