for i in{12..12};do
cdate=2019${i}pdate=`date-d"${cdate}01 -1 days" +%Y%j`ndate=`date-d"${cdate}01 +1 month" +%Y%j`mkdir-p$cdatecd$cdatefor((d=$pdate;d<=$ndate;d+=1));do
for h in 00 06 12 18;do
ff=../ICON_${d}${h}.d1
if![-e$ff];then continue;fi
ln-sf$ff.done
done
cd ..
ncrcat -O${cdate}/* ICON_d1_${cdate}.nc &
done
按照執行批次的日期範圍,進行字串累加, 再以ncrcat整合
for mo in{01..12};do
begd=$(date-ud"2019${mo}15 - 1 month" +%Y%m%d)for r in{5..12};do
d0=$((($r-1)*4))d=d0
II=ICON_
for((d=d0;d<=$(($d0+5));d+=1));do
j=$(date-ud"$begd + $d days" +%Y%j)if[$d==$d0];then
files=$II${j}*.d1
else
files=${files}' '$II${j}*.d1
fi
done
sub ncrcat -O${files} ICON_d1_${y}${mo}_run${r}.nc
done
done
#read the mozart model results
fname='moz_41_20'+yrmn+'.nc'ifnotos.path.exists(fname):sys.exit(fname+' not exist')ncM=netCDF4.Dataset(fname,'r')v4M=list(filter(lambdax:ncM.variables[x].ndim==4,[iforiinncM.variables]))ntM,nlayM,nrowM,ncolM=(ncM.variables[v4M[0]].shape[i]foriinrange(4))lonM=[ncM.XORIG+ncM.XCELL*iforiinrange(ncolM)]latM=[ncM.YORIG+ncM.YCELL*iforiinrange(nrowM)]tflagM=[str(i*100+j//10000)[2:]fori,jinzip(ncM.variables['TFLAG'][:,0,0],ncM.variables['TFLAG'][:,0,1])]tM=tflagM.index(yrjulhh)
#read the template(s)
fname='ICON_20'+yrjulhh+'.d1'nc=netCDF4.Dataset(fname,'r')v4=list(filter(lambdax:nc.variables[x].ndim==4,[iforiinnc.variables]))nt,nlay,nrow,ncol=(nc.variables[v4[0]].shape[i]foriinrange(4))X=[nc.XORIG+nc.XCELL*iforiinrange(ncol)]Y=[nc.YORIG+nc.YCELL*iforiinrange(nrow)]lon,lat=pnyc(X,Y,inverse=True)lon_ss=np.searchsorted(lonM,lon)lat_ss=np.searchsorted(latM,lat)tflag=nc.variables['TFLAG'][:,0,:]nc.close()
去除對照不到的項目
#drop keys which values not in new CMAQ spec_list
mc=list(mz2cm)foriinmc:ifinotinv4M:mz2cm.pop(i)continueifmz2cm[i]notinv4:mz2cm.pop(i)
儲存全球模式濃度矩陣
進行高度對照
將濃度單位由Volume Mixing Ratio轉到CMAQ的PPM
#save the matrix
v4M=list(mz2cm)A5=np.zeros(shape=(len(v4M),nlayM,nrowM,ncolM))forixinrange(len(v4M)):forkinrange(nlayM):A5[ix,k,:,:]=ncM.variables[v4M[ix]][tM,lay2VGLEVLS[str(k)],:,:]*1000.*1000.#Volume Mixing Ratio to PPM
ncM.close()
#perform the horizontal interpolation and write results
fname='ICON_20'+yrjulhh+'.d1'nc=netCDF4.Dataset(fname,'r+')forxinv4M:nc.variables[mz2cm[x]][0,:,:,:]=0