- 积分
- 1102
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2014-11-24
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2017-1-16 07:55:41
|
显示全部楼层
王老师,现在我可以把arl数据直接读出来算平均,怎样再存成ARL格式呢?之前是3-hr的数据,我现在算出了每一个格点的日平均,不知道怎么保存。我对python是新手,模型也是刚刚接触,总问些基础的问题,麻烦您了!
# Set working directory
meteoDir = '/Users/kaif/Downloads/ARLdata1'
# Open meteorological data file
print 'Open meteorological data file...'
meteof = [1]*11
for i in range(0,11):
meteofn = os.path.join(meteoDir, os.listdir(meteoDir))
print 'Meteorological file: ' + meteofn
meteof = addfile(meteofn)
# Read data
print 'Read data...'
rh = meteof[0]['U10M'][:,:,:,:]
#calculate average and save to rh
for i in range(0,10):
for j in range(0,10):
m=0
for k in range(0,120,8):
a=0
for l in range(0,11):
a=a+sum(meteof[l]['U10M'][k:k+7,0,i,j])
rh[m,i,j]=a/88
rh[m+1:m+7,i,j]=-1
m+=8
print i,j
#From here, the code is from MeteoInfoLab scripts, and I did some revisions
#---- Set times - this case show seasonal variation
cal = Calendar.getInstance()
cal.set(2010, 5, 1, 0 ,0 ,0)
sTime = cal.getTime()
cal.set(2010, 5, 15, 0, 0, 0)
eTime = cal.getTime()
aTime = sTime
from java.text import SimpleDateFormat
format = SimpleDateFormat('yyyyMMdd')
cal.setTime(sTime)
outFile = os.path.join(meteoDir, 'test2.arl')
mydata = MeteoDataInfo()
mydata.openARLData('/Users/fankai/Downloads/ARLdata1/edas.jun15.001')
arlDI = ARLDataInfo()
avars = ['U10M']
levels = [0]
for l in levels:
arlDI.levels.add(l)
if l == 0:
arlDI.LevelVarList.add(['U10M'])
# else:
# arlDI.LevelVarList.add([])
dataInfo = mydata.getDataInfo()
arlDI.createDataFile(outFile)
arlDI.X = dataInfo.getXDimension().getValues()
arlDI.Y = dataInfo.getYDimension().getValues()
variables = dataInfo.getVariables()
tNum = 15
for t in range(0, tNum):
aDH = arlDI.getDataHead(mydata.getProjectionInfo(), 'FNL1', 2)
arlDI.writeIndexRecord(atime, aDH)
lidx = 0
for l in arlDI.levels:
print l
for v in arlDI.LevelVarList[lidx]:
vName = rh
print vName
if lidx == 0:
mydata.setLevelIndex(lidx)
else:
variable = dataInfo.getVariable(vName)
# nlidx = variable.getZDimension().getDimValue().indexOf(l*100.0)
# mydata.setLevelIndex(nlidx)
aDL = DataLabel(atime)
aDL.setLevel(lidx)
aDL.setVarName(v)
aDL.setGrid(99)
aDL.setForecast(0)
arlDI.writeGridData(aDL, rh)
lidx += 1
arlDI.closeDataFile()
print 'Finished!'
显示错误:
Traceback (most recent call last):
File "<iostream>", line 32, in <module>
TypeError: getDataHead(): expected 5 args; got 3
数据:EDAS 40km |
|