importnetCDF4importnumpyasnpimportdatetime#for i in 03-3{0..1} 04-0{1..9};do nc=wrfout_d01_2018-${i}_00:00:00;ncks -v Times,DUST_1,DUST_2,DUST_2,DUST_3,DUST_4,DUST_5 -d bottom_top,0 $nc dust$i.nc;done
#ncrcat -O dust0*.nc a
#ncks -O -v Times,DUST_1 a dust.nc
fnames=subprocess.check_output('ls dust??-??.nc',shell=True).decode('utf8').strip('\n').split('\n')nc=netCDF4.Dataset('dust.nc','r+')binf={i:1foriinrange(1,4)};binf.update({4:0.87,5:0})it=0forfnameinfnames:nc_in=netCDF4.Dataset(fname,'r')nt,nz,ny,nx=nc_in['DUST_1'].shapedust=np.zeros(shape=(nt,nz,ny,nx))foriinrange(1,6):dust+=nc_in['DUST_'+str(i)][:]*binf[i]nc['DUST_1'][it:it+nt,:,:,:]=dust[:,:,:,:]it+=ntIX,IY=335-1,212-1nt,nz,ny,nx=nc['DUST_1'].shapestrT=[''.join([i.decode('utf-8')foriinnc.variables['Times'][t,:]])fortinrange(nt)]Times=[datetime.datetime.strptime(a,'%Y-%m-%d_%H:00:00')forainstrT]tflag=[i.strftime('%Y%m%d%H')foriinTimes]zs=['WRFchem']forzinzs:exec(z+'=nc["DUST_1"][:,0,IY,IX]*1.1839')#dens of air https://en.wikipedia.org/wiki/Density_of_air
DD={}forzinzs+['tflag']:exec('DD.update({"'+z+'":'+z+'})')df=DataFrame(DD)df.set_index('tflag').to_csv('ntw.csv')nc.close()