7#working under 16??, the file in directory(or file by link) will be modified
8yrmn=subprocess.check_output('pwd',shell=True).decode('utf8').strip('\n').split('/')[-1]9begd=datetime.datetime(2000+int(yrmn[:2]),int(yrmn[2:4]),1)+datetime.timedelta(days=-1)10b,e=monthrange(2000+int(yrmn[:2]),int(yrmn[2:4]))11x='XTIME'12y='ITIMESTEP'13#accumulation variables
14acc=['ACGRDFLX','ACSNOM','RAINC','RAINSH','RAINNC','SNOWNC','GRAUPELNC','HAILNC','ACHFX','ACLHF']
由於程式將會更動acc變數的內容,建議先就wrfout的內容另存備份。
15#note acc should be saved and restored(if needed) before following actions:
16# for dm in 1 2 4;do
17# for i in $(ls wrfout_d0${dm}*);do d=$(echo $i|cut -d'_' -f3)
18# ncks -O -v Times,ACGRDFLX,ACSNOM,RAINC,RAINSH,RAINNC,SNOWNC,GRAUPELNC,HAILNC,ACHFX,ACLHF $i $d.nc;done
19# ncrcat -O 2016*.nc acc_d0${dm}.nc
20# done
每層網格系統的迴圈
讀取起始時間、年、Julian Day數據
累積變數由0起算
21forDMin['1','2','4']:22#each run must begin with same day(last day of previous month)
23fname='wrfout_d0'+DM+'_'+begd.strftime("%Y-%m-%d")+'_00:00:00'24nc=netCDF4.Dataset(fname,'r')25min0=nc.variables[x][-1]+6026START_DATE=nc.SIMULATION_START_DATE27JULYR=nc.JULYR28JULDAY=nc.JULDAY29ifJULYR%4==0:30JULDAY=min(366,JULDAY)31else:32JULDAY=min(365,JULDAY)33TITLE=nc.TITLE34# begin with zero accumulation
35acmx={ac:np.zeros(shape=nc.variables[ac].shape)foracinacc}36nc.close()
56fortinrange(24):57mins=min0+((d-1)*24+t)*6058nc.variables[x][t]=float(mins)59nc.variables[x].units='minutes since '+START_DATE60nc.variables[x].description='minutes since '+START_DATE61nc.variables[y][t]=int(mins)62nc.close()63