def get_cape(filename, flag, coords=None): fil = hdf.File(filename, 'r') height = getvar(fil, 'z_coords') if height.size < 3: height = getvar( '/nobackup/rstorer/convperts/revu/aug11-control/aug11-control-revu-001.h5', 'z_coords') dz = getdz( '/nobackup/rstorer/convperts/revu/aug11-control/aug11-control-revu-001.h5' ) else: dz = getdz(fil) tempk = getvar(fil, 'tempk') q = getvar(fil, 'vapor') press = getvar(fil, 'press') fil.close() # except: # print 'error reading variables' if type(coords) is tuple: c0, c1 = coords capevar, cinvar = capecalc(height, tempk[:, c0, c1], q[:, c0, c1], press[:, c0, c1], flag) else: capevar = np.zeros((tempk.shape[1], tempk.shape[2])) cinvar = np.zeros_like(capevar) for c0 in range(capevar.shape[0]): for c1 in range(capevar.shape[1]): capevar[c0, c1], cinvar[c0, c1] = capecalc(height, tempk[:, c0, c1], q[:, c0, c1], press[:, c0, c1], flag) return capevar, cinvar
def getrh(fil): heights = getvar(fil, 'z_coords')[1:] tempk = np.mean(np.mean(getvar(fil, 'tempk')[1:, :, :], 1), 1) press = np.mean(np.mean(getvar(fil, 'press')[1:, :, :], 1), 1) vapor = np.mean(np.mean(getvar(fil, 'vapor')[1:, :, :], 1), 1) rho = (press * 100.) / (287. * tempk) dz = getdz(fil)[:-1] es = 611.2 * np.exp(17.67 * (tempk - 273.15) / (tempk - 29.65)) rvs = 622 * es / ((press * 100.) - es) vsat = rvs * rho * dz vact = vapor * rho * dz lows = np.where(press > 850.) mids = np.logical_and(press < 850, press > 500) highs = np.where(press < 500) lowsat = np.sum( vact[lows]) #100. * (np.sum(vact[lows]) / np.sum(vsat[lows])) midsat = np.sum( vact[mids]) #100. * (np.sum(vact[mids]) / np.sum(vsat[mids])) highsat = np.sum( vact[highs]) #100. * (np.sum(vact[highs]) / np.sum(vsat[highs])) allsat = np.sum(vact) #100. * (np.sum(vact) / np.sum(vsat)) return lowsat, midsat, highsat, allsat
def getrh(filename): hfile = hdf.File(filename, 'r') press = getvar(hfile, 'press') tempk = getvar(hfile, 'tempk') relhum = getvar(hfile, 'relhum') rho = (press * 100.) / (287. * tempk) vapor = getvar(hfile, 'vapor') sat = satmixratio(tempk, press) * 1000. dz = getdz(hfile) hfile.close() vsatall = sat * rho * dz[:, None, None] vactall = vapor * rho * dz[:, None, None] vsat = np.mean(np.mean(vsatall, 1), 1) vact = np.mean(np.mean(vactall, 1), 1) mpress = np.mean(np.mean(press, 1), 1) lows = np.where(mpress > 850.) mids = np.logical_and(mpress < 850, mpress > 500) highs = np.where(mpress < 500) lowsat = 100. * (np.sum(vact[lows]) / np.sum(vsat[lows])) midsat = 100. * (np.sum(vact[mids]) / np.sum(vsat[mids])) highsat = 100. * (np.sum(vact[highs]) / np.sum(vsat[highs])) return lowsat, midsat, highsat
def get3levels(filename,varname): hfile = hdf.File(filename,'r') press = getvar(hfile,'press') tempk = getvar(hfile,'tempk') rho = (press*100.)/ (287.*tempk) vartoavg = getvar(hfile,varname) dz = getdz(hfile) hfile.close() vall = vartoavg * rho * dz[:,None,None] mass = rho * dz[:,None,None] vtop = np.mean(np.mean(vall,1),1) vbot = np.mean(np.mean(mass,1),1) mpress = np.mean(np.mean(press,1),1) lows = np.where(mpress > 850.) mids = np.logical_and(mpress < 850, mpress > 500) highs = np.where(mpress < 500) lowsat = np.sum(vtop[lows]) / np.sum(vbot[lows]) midsat = np.sum(vtop[mids]) / np.sum(vbot[mids]) highsat = np.sum(vtop[highs]) / np.sum(vbot[highs]) allsat = np.sum(vtop) / np.sum(vbot) return lowsat, midsat, highsat, allsat
def makeoneplot(i,fil1,fil2,yval): outdir = '/nobackup/rstorer/plots/budgetslices/' cond1 = getvar(fil1, 'total_cond')/1000. cond2 = getvar(fil2, 'total_cond')/1000. micro2 = (getvar(fil2, 'nuccldrt') + getvar(fil2, 'nucicert') + getvar(fil2, 'vapliqt') + getvar(fil2, 'vapicet'))/1000. diff = cond2-cond1 height = getvar(fil1, 'z_coords') xs = np.arange(400)*.25 dz = getdz(fil1) plt.subplot(2,1,1) plt.contourf(xs[160:320], height, diff[:,yval,160:320]) plt.ylim(0,18000) plt.ylabel('height') plt.title('Condensate Difference') plt.colorbar() plt.subplot(2,1,2) plt.contourf(xs[160:320], height, micro2[:,yval,160:320]) plt.ylim(0,18000) plt.ylabel('height') plt.title('microphysics') plt.colorbar() plt.savefig(outdir+'time_'+i+'_y'+str(yval)+'.png') plt.clf()
def getbudgetvars(fil1, dt): cond = getvar(fil1, 'total_cond') / 1000. rho = (getvar(fil1, 'press') * 100.) / (getvar(fil1, 'tempk') * 287.) w = getvar(fil1, 'w') pcp = getvar(fil1, 'precip3d') * -1 dz = getdz(fil1) massflux = cond * rho * w return massflux, w, pcp
def gettracer(dirname): files = sorted(glob.glob('/nobackup/rstorer/convperts/revu/'+dirname+'/*h5')) outdir = '/nobackup/rstorer/plots/' nt = len(files) t2 = getvar(files[0],'tracer002')[:,100,100] dz = getdz(files[0]) x = t2*dz*100*100*100 return np.sum(x)
def getcapeparcel(filename, flag): try: fil = hdf.File(filename, 'r') height = getvar(fil, 'z_coords') if height.size < 3: height = getvar( '/nobackup/rstorer/convperts/revu/aug11-control/aug11-control-revu-001.h5', 'z_coords') dz = getdz( '/nobackup/rstorer/convperts/revu/aug11-control/aug11-control-revu-001.h5' ) else: dz = getdz(fil) tempk = getvar(fil, 'tempk')[:, 10, 10] q = getvar(fil, 'vapor')[:, 10, 10] press = getvar(fil, 'press')[:, 10, 10] fil.close() except: print 'error reading variables' if flag == 'sfc': zlcl, lcl, tlcl = find_lcl_sfc(height, tempk, q, press) elif flag == 'mu': zlcl, lcl, tlcl, zstart = find_lcl_mostunstable( height, tempk, q, press) else: zlcl, lcl, tlcl = find_lcl_ml100(height, tempk, q, press) parcel = moistadiabat(height, press, zlcl, tlcl, tempk, q) parceltv = parcel * (1 + (.61 * satmixratio(parcel, press))) parceltv[:zlcl + 1] = parcel[:zlcl + 1] * (1 + (.61 * q[0])) Tv = tempk * (1 + (.61 * (q / 1000.))) posarea = np.where(parceltv > Tv) intvar = (parceltv - Tv) * (G / Tv) lfc = np.min(np.asarray(posarea)) el = np.max(np.asarray(posarea)) if lfc < zlcl: lfc = zlcl intvarpos = intvar[lfc:el + 1] zpos = height[lfc:el + 1] cape = np.trapz(intvarpos, dx=np.diff(zpos)) return cape, parceltv - Tv
def gettavg(fil,bottom,top): tempk = np.mean(np.mean(getvar(fil,'tempk')[1:,:,:],1),1) dz = getdz(fil)[:-1] press = np.mean(np.mean(getvar(fil,'press')[1:,:,:],1),1) layer = np.logical_and(press < bottom, press > top) vact = tempk*dz tavg = np.sum(vact[layer])/ np.sum(dz[layer]) return tavg
def plots(maindir, stagevar, xdir, locvars, flag): if flag == '500mb': zval = 39 if flag == '8km': zval = 46 i1, i2, j1, j2, location = locvars stage, dt = stagevar filesrams = sorted(glob.glob(maindir + stage + '/' + xdir + '/*h5')) nt = len(filesrams) totflux = np.zeros(nt) condflux = np.zeros(nt) totmass = np.zeros(nt) massdiff = np.zeros(nt) pcp3d = np.zeros(nt) for tim in range(nt): fil = hdf.File(filesrams[tim], 'r') w = getvar(fil, 'w') q = getvar(fil, 'total_cond') / 1000. v = getvar(fil, 'vapor') / 1000. precip = getvar(fil, 'precip3d') rho = (getvar(fil, 'press') * 100) / (getvar(fil, 'tempk') * rd) dz = getdz(fil) fil.close() massfluxcond = w * q * rho massfluxtot = w * (q + v) * rho masstot = (q + v) * rho * dz[:, None, None] totmass[tim] = np.sum(masstot[zval:, i1:i2, j1:j2]) * 250 * 250 totflux[tim] = np.sum(massfluxtot[zval, i1:i2, j1:j2]) * 250 * 250 * dt condflux[tim] = np.sum(massfluxcond[zval, i1:i2, j1:j2]) * 250 * 250 * dt pcp3d[tim] = np.sum(precip[zval, i1:i2, j1:j2]) * 250 * 250 * dt * -1 massdiff[1:] = np.diff(totmass) netcond = pcp3d + condflux netvert = pcp3d + totflux plt.plot(totflux, linewidth=3, label='total updraft flux') plt.plot(condflux, linewidth=3, label='condensate updraft') plt.plot(pcp3d, linewidth=3, label='precip') plt.plot(netcond, linewidth=3, label='net condensate flux') plt.plot(netvert, linewidth=3, label='net vertical flux') plt.plot(massdiff, linewidth=3, label='Actual Mass Change') plt.legend() plt.title('Mass Budget above ' + flag + ' (kg)') plt.savefig('/nobackup/rstorer/plots/massfluxplots/newbudget-' + xdir + '-' + stage + '-' + location + '-' + flag + '.png') plt.clf() return [totflux, condflux, pcp3d, netcond, netvert, massdiff]
def getbudgetvars(fil1,fil2,mlist,dt): cond1 = getvar(fil1, 'total_cond')/1000. cond2 = getvar(fil2, 'total_cond')/1000. rho1 = (getvar(fil1, 'press') * 100.) / (getvar(fil1, 'tempk') *287.) rho2 = (getvar(fil2, 'press') * 100.) / (getvar(fil2, 'tempk') *287.) w1 = getvar(fil1, 'w') micro2 = np.zeros_like(w1) for files in mlist: micro2 = micro2+ getvar(files, 'nuccldrt') + getvar(files, 'nucicert') + getvar(files, 'vapliqt') + getvar(files, 'vapicet') pcp1 = getvar(fil1, 'precip3d') dz = getdz(fil1) micro2 = (micro2*rho2*dz[:,None,None])/(dt*1000) massflux1 = cond1*rho1*w1 diff = ((cond2*rho2*dz[:,None,None])-(cond1*rho1*dz[:,None,None]))/dt vert1 = massflux1-pcp1 return diff, vert1, micro2
def budgetplot(maindir, xdir, dx, dy, dt): files = sorted(glob.glob(maindir + xdir + '/*.h5')) nt = len(files) updraft = np.zeros(nt) vapflux = np.zeros(nt) tracflux = np.zeros(nt) totalmass = np.zeros(nt) for t, filename in enumerate(files): print t f = hdf.File(filename, 'r') w = getvar(f, 'w') q = getvar(f, 'total_cond') / 1000. vap = getvar(f, 'vapor') / 1000. trac = getvar(f, 'tracer002') * (100.**3) height = getvar(f, 'z_coords') rho = getrho(f) dz = getdz(f) f.close() nz, nx, ny = q.shape azz = np.argmin(np.absolute(height - 8000)) bzz = nz - 1 advw = rho * w * q advv = rho * w * vap advt = w * trac updraft[t] = dx * dy * dt * (np.sum(advw[azz, :, :]) - np.sum(advw[bzz, :, :])) vapflux[t] = dx * dy * dt * (np.sum(advv[azz, :, :]) - np.sum(advv[bzz, :, :])) tracflux[t] = dx * dy * dt * (np.sum(advt[azz, :, :]) - np.sum(advt[bzz, :, :])) totalmass[t] = np.sum(q[azz:bzz, :, :] * rho[azz:bzz, :, :] * dz[azz:bzz, None, None]) * dx * dy for t, filename in enumerate(files): print t # advw = rho * w * q # advv = rho * w * vap # advt = w * trac # updraft[t] = dx * dy * dt * (np.sum(advw[azz,:,:]) - np.sum(advw[bzz,:,:])) # vapflux[t] = dx * dy * dt * (np.sum(advv[azz,:,:]) - np.sum(advv[bzz,:,:])) # tracflux[t] = dx * dy * dt * (np.sum(advt[azz,:,:]) - np.sum(advt[bzz,:,:])) # totalmass[t] = np.sum(q[azz:bzz,:,:]*rho[azz:bzz,:,:] * dz[azz:bzz,None,None]) * dx * dy return updraft, vapflux, tracflux, totalmass
def getrh(fil, bottom, top): heights = getvar(fil, 'z_coords')[1:] tempk = np.mean(np.mean(getvar(fil, 'tempk')[1:, :, :], 1), 1) press = np.mean(np.mean(getvar(fil, 'press')[1:, :, :], 1), 1) vapor = np.mean(np.mean(getvar(fil, 'vapor')[1:, :, :], 1), 1) rho = (press * 100.) / (287. * tempk) dz = getdz(fil)[:-1] es = 611.2 * np.exp(17.67 * (tempk - 273.15) / (tempk - 29.65)) rvs = 622 * es / ((press * 100.) - es) vsat = rvs * rho * dz vact = vapor * rho * dz layer = np.logical_and(press < bottom, press > top) columnvapor = np.sum(vact[layer]) columnrh = 100. * (np.sum(vact[layer]) / np.sum(vsat[layer])) return columnvapor, columnrh
def getbudgetvars(fil1, fil2, dt): cond1 = getvar(fil1, 'total_cond') / 1000. cond2 = getvar(fil2, 'total_cond') / 1000. rho1 = (getvar(fil1, 'press') * 100.) / (getvar(fil1, 'tempk') * 287.) rho2 = (getvar(fil2, 'press') * 100.) / (getvar(fil2, 'tempk') * 287.) w = getvar(fil1, 'w') u = getvar(fil1, 'u') v = getvar(fil1, 'v') micro2 = (getvar(fil2, 'nuccldrt') + getvar(fil2, 'nucicert') + getvar(fil2, 'vapliqt') + getvar(fil2, 'vapicet')) / 1000. pcp3d = getvar(fil1, 'precip3d') z = getvar(fil1, 'z_coords') dz = getdz(fil1) diff = ((cond2 * rho2 * dz[:, None, None]) - (cond1 * rho1 * dz[:, None, None])) / dt mic = (micro2 * rho2 * dz[:, None, None]) / dt dzdz = np.zeros_like(w) dzdz[1:-1, :, :] = (cond1[2:, :, :] * rho1[2:, :, :] * w[2:, :, :]) - ( cond1[:-2, :, :] * rho1[:-2, :, :] * w[:-2, :, :]) dzdx = np.zeros_like(u) dzdx[:, :, 1:-1] = (cond1[:, :, 2:] * rho1[:, :, 2:] * u[:, :, 2:]) - ( cond1[:, :, :-2] * rho1[:, :, :-2] * u[:, :, :-2]) dzdy = np.zeros_like(v) dzdy[:, 1:-1, :] = (cond1[:, 2:, :] * rho1[:, 2:, :] * v[:, 2:, :]) - ( cond1[:, :-2, :] * rho1[:, :-2, :] * v[:, :-2, :]) term = np.zeros_like(w) term[1:-1, :, :] = (pcp3d[2:, :, :] - pcp3d[:-2, :, :]) vert = dzdz * -1 horiz = (dzdx + dzdy) * -1 rhs = mic + horiz + vert + term res = diff - rhs return w, diff, horiz, vert, term, mic, res
def plots(maindir, stagevar, xdir, locvars, flag): if flag == '500mb': zval = 39 if flag == '8km': zval = 46 i1, i2, j1, j2, location = locvars stage, dt = stagevar filesrams = sorted(glob.glob(maindir+stage+'/'+xdir+'/*h5')) nt = len(filesrams) totflux= np.zeros(nt) condflux= np.zeros(nt) totmass = np.zeros(nt) massdiff = np.zeros(nt) pcp3d = np.zeros(nt) for tim in range(nt): fil = hdf.File(filesrams[tim],'r') w = getvar(fil, 'w') q = getvar(fil,'total_cond')/1000. v = getvar(fil,'vapor')/1000. precip = getvar(fil, 'precip3d') rho = (getvar(fil,'press')*100)/(getvar(fil,'tempk')*rd) dz = getdz(fil) fil.close() massfluxcond = w*q*rho massfluxtot = w*(q+v)*rho masstot = (q+v)*rho*dz[:,None,None] totmass[tim] = np.sum(masstot[zval:,i1:i2,j1:j2])*250*250 totflux[tim]=np.sum(massfluxtot[zval,i1:i2,j1:j2])*250*250*dt condflux[tim] = np.sum(massfluxcond[zval,i1:i2,j1:j2])*250*250*dt pcp3d[tim] = np.sum(precip[zval,i1:i2,j1:j2])*250*250*dt*-1 massdiff[1:]=np.diff(totmass) netcond = pcp3d + condflux netvert = pcp3d + totflux return [totflux,condflux,pcp3d,netcond,netvert,massdiff]
def budgetplot(maindir, xdir, dx, dy, dt): files = sorted(glob.glob(maindir + xdir + '/*.h5')) nt = len(files) updraft = np.zeros(nt) onlyup = np.zeros(nt) for t, filename in enumerate(files): print t f = hdf.File(filename, 'r') w = getvar(f, 'w') height = getvar(f, 'z_coords') rho = getrho(f) dz = getdz(f) f.close() nz, nx, ny = w.shape azz = np.argmin(np.absolute(height - 8000)) bzz = nz - 1 advw = rho * w upw = copy.deepcopy(advw) upw[w < 1] = 0. updraft[t] = dx * dy * dt * (np.sum(advw[azz, :, :]) - np.sum(advw[bzz, :, :])) onlyup[t] = dx * dy * dt * (np.sum(upw[azz, :, :]) - np.sum(upw[bzz, :, :])) return updraft, onlyup
def plots(maindir, stage, xdir): filesrams = sorted(glob.glob(maindir + stage + '/' + xdir + '/*h5')) nt = len(filesrams) timemax = np.zeros(nt) massadd = np.zeros(nt) masscondflux = np.zeros(nt) flux500 = [] w5 = [] w8 = [] totmass = np.zeros(nt) massdiff = np.zeros(nt) microadd = np.zeros(nt) pcp3d = np.zeros(nt) for tim in range(nt): fil = hdf.File(filesrams[tim], 'r') w = getvar(fil, 'w') q = getvar(fil, 'total_cond') / 1000. v = getvar(fil, 'vapor') / 1000. precip = getvar(fil, 'precip3d') rho = (getvar(fil, 'press') * 100) / (getvar(fil, 'tempk') * rd) micro = (getvar(fil, 'nuccldrt') + getvar(fil, 'nucicert') + getvar(fil, 'vapicet') + getvar(fil, 'vapliqt')) / 1000. dz = getdz(fil) fil.close() massfluxcond = w * q * rho massflux = w * (q + v) * rho timemax[tim] = np.max(massfluxcond[39, 125:175, 200:250]) flux500.append(massflux[39, 125:175, 200:250]) w[w < 1] = 0 w5.append(w[39, :, :]) w8.append(w[46, :, :]) mass = (q + v) * rho * dz[:, None, None] totmic = micro * rho * dz[:, None, None] totmass[tim] = np.sum(mass[39:, 125:175, 200:250]) * 250 * 250 massadd[tim] = np.sum(massflux[39, 125:175, 200:250]) * 250 * 250 * 30 masscondflux[tim] = np.sum(massfluxcond[39, 125:175, 200:250]) * 250 * 250 * 30 microadd[tim] = np.sum(totmic[39:, 125:175, 200:250]) * 250 * 250 pcp3d[tim] = np.sum(precip[39, 125:175, 200:250]) * 250 * 250 * 30 * -1 massdiff[1:] = np.diff(totmass) plt.plot(massdiff, linewidth=3) plt.title('mass difference (kg)') plt.savefig('/nobackup/rstorer/plots/massfluxplots/massdiff.png') plt.clf() movie(flux500, '/nobackup/rstorer/plots/massfluxplots/' + xdir + stage, 'massflux500mb') movie(w5, '/nobackup/rstorer/plots/massfluxplots/' + xdir + stage, 'w500mb') movie(w8, '/nobackup/rstorer/plots/massfluxplots/' + xdir + stage, 'w8km') plt.plot(massadd, linewidth=3) plt.title('Mass added through vertical flux 500mb (kg)') plt.savefig('/nobackup/rstorer/plots/massfluxplots/massfluxadded.png') plt.clf() plt.plot(timemax, linewidth=3) plt.title('Max Mass Flux at 500mb (kg/m2s)') plt.savefig('/nobackup/rstorer/plots/massfluxplots/timemax.png') plt.clf() plt.plot(totmass, linewidth=3) plt.title('Condensate above 500mb (kg)') plt.savefig('/nobackup/rstorer/plots/massfluxplots/totmass.png') plt.clf() plt.plot(massadd, linewidth=3, label='vertical flux') plt.plot(masscondflux, linewidth=3, label='cond flux') # plt.plot(microadd, linewidth = 3, label = 'micro') plt.plot(pcp3d, linewidth=3, label='precip') plt.plot((pcp3d + massadd), linewidth=3, label='sum') plt.plot(massdiff, linewidth=3, label='diff') plt.legend() plt.title('Mass Budget above 500mb (kg)') plt.savefig( '/nobackup/rstorer/plots/massfluxplots/newbudget-growing-125-200.png') plt.clf()
outdzdx = {} outdzdy = {} outdzdz = {} outw = {} outu = {} outv = {} for xdir in dirs: print xdir modelfiles = sorted( glob.glob('/nobackup/rstorer/convperts/' + time + '/' + xdir + '/*h5')) radarfiles = sorted( glob.glob('/nobackup/rstorer/convperts/' + time + '/quickbeam/' + xdir + '*h5')) height = getvar(modelfiles[0], 'z_coords')[37:] dz = getdz(modelfiles[0])[37:] nt = len(modelfiles) outdzdt[xdir] = [] outdzdx[xdir] = [] outdzdy[xdir] = [] outdzdz[xdir] = [] outw[xdir] = [] outu[xdir] = [] outv[xdir] = [] for t in range(nt - 3): print t w = smoothedvar(getvar(modelfiles[t], 'w')) u = smoothedvar(getvar(modelfiles[t], 'u')) v = smoothedvar(getvar(modelfiles[t], 'v')) ref = smoothedvar(getvar(radarfiles[t], 'reflectivity')) ref2 = smoothedvar(getvar(radarfiles[t + 3], 'reflectivity'))
def makeplots(fil1, fil2, mlist, dt, num): dz = getdz(fil1) outnum = str(num) if num < 10: outnum = '0' + outnum diff, vertflux, micro, w, cmf, pcp = getbudgetvars(fil1, fil2, mlist, dt) udet, vdet, uadv, vadv = calcadvflux(fil1) advprofs = advprofiles(fil1, uadv, vadv) detprofs = advprofiles(fil1, udet, vdet) vert = np.diff(vertflux, axis=0) * -1 diff1 = diff[:, 100:300, 100:300] vert1 = vert[:, 100:300, 100:300] flux = vertflux[:, 100:300, 100:300] * 250 * 250 updraftonly = cmf[:, 100:300, 100:300] * 250 * 250 pcponly = pcp[:, 100:300, 100:300] * 250 * 250 micro1 = micro[:, 100:300, 100:300] height = getvar(fil1, 'z_coords') diffprof = np.sum(np.sum(diff1, 1), 1) * 250 * 250 vertprof = np.sum(np.sum(vert1, 1), 1) * 250 * 250 micprof = np.sum(np.sum(micro1, 1), 1) * 250 * 250 advprof = np.sum(advprofs, 1) * dz * 250 detprof = np.sum(detprofs, 1) * dz * 250 intdiff = np.zeros_like(diffprof) intmicro = np.zeros_like(diffprof) intadv = np.zeros_like(diffprof) intdet = np.zeros_like(diffprof) intflux = np.sum(np.sum(flux, 1), 1) intpcp = np.sum(np.sum(pcponly, 1), 1) * -1 intcmf = np.sum(np.sum(updraftonly, 1), 1) testvert = np.zeros_like(diffprof) for z in range(82): intdiff[z] = np.sum(diffprof[z:]) intmicro[z] = np.sum(micprof[z:]) intadv[z] = np.sum(advprof[z:]) intdet[z] = np.sum(detprof[z:]) testvert[z] = np.sum(vertprof[z:]) print intmicro.shape, intflux.shape, intadv.shape, intdet.shape sumvar = intmicro + intflux + intadv + intdet plt.plot(intdiff[37:], height[37:], color='black', linewidth=3, label='mass diff') plt.plot(intmicro[37:], height[37:], color='blue', linewidth=3, label='micro') plt.plot(intflux[37:], height[37:], color='red', linewidth=3, label='flux') plt.plot(testvert[37:], height[37:], color='black', linewidth=2, linestyle='dashed', label='fluxtestint') plt.plot(intpcp[37:], height[37:], color='gray', linewidth=3, label='pcp') plt.plot(intcmf[37:], height[37:], color='orange', linewidth=3, label='updraft') plt.plot(intadv[37:], height[37:], color='green', linewidth=3, label='advection') plt.plot(intdet[37:], height[37:], color='yellow', linewidth=3, label='detrainment') plt.plot(sumvar[37:], height[37:], color='purple', linewidth=3, label='sum') # plt.xlim(-.006,.010) # plt.xlim(-400,500) plt.legend() plt.title('integrated') plt.savefig( '/nobackup/rstorer/plots/budgetslices/bigdomainsplitadvectionprofilesintegrated5-' + outnum + '.png') plt.clf() return intdiff[46], intmicro[46], intadv[46], intflux[46]
def getbudgetvars(fil1, dt): cond = getvar(fil1, 'tracer002') * 100. * 100. * 100. w = getvar(fil1, 'w') dz = getdz(fil1) massflux = cond * w return massflux, w
for i in range(25): cols.append('y') initval = {} profs = {} allupdraft = {} for i, dirname in enumerate(dirs): print dirname files = sorted( glob.glob('/nobackup/rstorer/convperts/revu/' + dirname + '/' + dirname + '*h5')) #outdir = '/nobackup/rstorer/code/' outdir = '.' nt = len(files) t2 = getvar(files[0], 'tracer002')[:, 100, 100] dz = getdz(files[0]) x = t2 * dz * 100 * 100 * 100 initval[dirname] = np.sum(x) profs[dirname] = t2 intup = np.zeros((nt, 82)) intnum = 0. z = getvar(files[0], 'z_coords') zarg = np.argmin(np.abs(z - 8000)) for num in range(1, nt - 1): up = makecode(files[num], 300., num) intup[num, :] = up allupdraft[dirname] = intup
outdir = '/nobackup/rstorer/plots/budgetslices/' cond1 = getvar(fil1, 'total_cond')/1000. cond2 = getvar(fil2, 'total_cond')/1000. rho1 = (getvar(fil1, 'press') * 100.) / (getvar(fil1, 'tempk') *287.) rho2 = (getvar(fil2, 'press') * 100.) / (getvar(fil2, 'tempk') *287.) w1 = getvar(fil1, 'w') w2 = getvar(fil2, 'w') micro1 = (getvar(fil1, 'nuccldrt') + getvar(fil1, 'nucicert') + getvar(fil1, 'vapliqt') + getvar(fil1, 'vapicet'))/1000. micro2 = (getvar(fil2, 'nuccldrt') + getvar(fil2, 'nucicert') + getvar(fil2, 'vapliqt') + getvar(fil2, 'vapicet'))/1000. pcp1 = getvar(fil1, 'precip3d') pcp2 = getvar(fil2, 'precip3d') height = getvar(fil1, 'z_coords') xs = np.arange(400)*.25 dz = getdz(fil1) #micro1=micro1*rho1*dz[:,None,None]/30. #micro2 = micro2*rho2*dz[:,None,None]/30. #plt.contourf(xs[160:320], height, cond1[:,170,160:320]) #plt.ylim(0,18000) #plt.ylabel('height') #plt.xlabel('km') #plt.title('Condensate Time 1') #plt.colorbar() #plt.savefig(outdir+'cond1.png') #plt.clf() # #plt.contourf(xs[160:320], height, cond2[:,170,160:320])
#meanprof2 = np.load('newtracerprofiles-meanprof-wgt2.npz') #meanprof5 = np.load('newtracerprofiles-meanprof-wgt5.npz') y2 = {} y5 = {} #make time series of 8km flux and get cumulative sum for powerlaw plot for xdir in dirs: y2[xdir] = makesum(var2d2[xdir], zarg) y5[xdir] = makesum(var2d5[xdir], zarg) #get initial values of tracer to weight flux by initval = {} for xdir in dirs: fil = '/nobackup/rstorer/convperts/revu/' + xdir + '/' + xdir + '-revu-001.h5' t0 = getvar(fil, 'tracer002')[:, 100, 100] dz = getdz(fil) x = t0 * dz * 100 * 100 * 100 initval[xdir] = np.sum(x) rh0 = np.load('rhlow.npz') rh = makearray(rh0, dirs) plotprofiles(meanprof2, z, dirs, 'newtracerprofileswgt2.png', rh) plotprofiles(meanprof5, z, dirs, 'newtracerprofileswgt5.png', rh) #plotscatter(y2, rh, dirs, 'newtracerprofiles-scatter-wgt2.png', initval) #plotscatter(y5, rh, dirs, 'newtracerprofiles-scatter-wgt5.png', initval) coloredplot(meanprof2, z, dirs, 'newtracerprofileswgt2-zoom.png', rh) coloredplot(meanprof5, z, dirs, 'newtracerprofileswgt5-zoom.png', rh)
import matplotlib import numpy as np matplotlib.use("Agg") import matplotlib.pyplot as plt import h5py as hdf from rachelutils.hdfload import getvar, getdz import glob from rachelutils.dumbnaming import pert75 dirs = pert75() #dirs = ['aug11-control','feb23-control','aug17-control'] height = getvar('/nobackup/rstorer/convperts/revu/feb23-control/feb23-control-revu-001.h5','z_coords') dz = getdz('/nobackup/rstorer/convperts/revu/feb23-control/feb23-control-revu-001.h5') zarg = [] for outheight in range(2,13,2): zarg.append(np.argmin(np.abs(height-(outheight*1000)))) for zval in zarg: times = ['mature','growing'] for time in times: outdzdt = {} outdzdx = {} outdzdy = {} outdzdz = {} outw = {} outu = {} outv = {} for xdir in dirs: print xdir modelfiles = sorted(glob.glob('/nobackup/rstorer/code/budgetfiles/'+time+'*'+xdir+'*h5'))
import numpy as np import copy import matplotlib matplotlib.use("Agg") import glob import matplotlib.pyplot as plt from rachelutils.hdfload import getvar,getrho,getdz from rachelutils.dumbnaming import pert75 height = getvar('/nobackup/rstorer/convperts/mature/feb23-control/feb23-control-mature-001.h5','z_coords') h8km = np.argmin(np.abs(height-8000)) height=height[h8km:] dz = getdz('/nobackup/rstorer/convperts/mature/feb23-control/feb23-control-mature-001.h5')[h8km:] modeldirs = pert75() modeldirs = ['feb23-control','aug11-control','aug17-control'] updraftfrac = {} plt.set_cmap('summer') for xdir in modeldirs: print xdir files = sorted(glob.glob('/nobackup/rstorer/convperts/revu/'+xdir+'/*h5')) nt = len(files) uptimes = np.zeros(nt) downtimes = np.zeros(nt) for t in range(nt): w = (getvar(files[t],'w')[h8km:,:,:])