Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
def get8kmflux(xdir):
    print xdir
    files = sorted(
        glob.glob('/nobackup/rstorer/convperts/revu/' + xdir + '/' + xdir +
                  '*h5'))
    nt = len(files)
    z = getvar(files[0], 'z_coords')
    zarg = np.argmin(np.abs(z - 8000))
    values5 = np.zeros(nt)
    values2 = np.zeros(nt)

    for t, fil in enumerate(files):
        cond = getvar(fil, 'tracer002')[zarg, :, :] * 100. * 100. * 100.
        w = getvar(fil, 'w')
        massflux = cond * w[zarg, :, :]

        colmax = np.max(w, 0)
        w2 = np.where(colmax > 2)
        w5 = np.where(colmax > 5)

        if np.max(w) > 5:
            updraft5 = massflux[w5[0], w5[1]]
            up5 = np.sum(updraft5) * 250 * 250
            values5[t] = up5
        if np.max(w) > 2:
            updraft2 = massflux[w2[0], w2[1]]
            up2 = np.sum(updraft2) * 250 * 250
            values2[t] = up2

    return values2, values5
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
def calcd(fil,var,x=None):
    nnames = {  'pristine':'pris_concen_kg',
                'cloud':'cloud_concen_mg',
                'aggregates':'agg_concen_kg',
                'snow':'snow_concen_kg',
                'drizzle':'drizzle_concen_mg',
                'hail':'hail_concen_kg',
                'rain':'rain_concen_kg',
                'graupel':'graup_concen_kg'
            }

    mass = getvar(fil,var)/1000.
    num = getvar(fil,nnames[var])
    if var == 'cloud' or var == 'drizzle':
        num=num*1000.*1000.
    
    coef, ex, nu = getdefault(var)
    if x is not None:
        coef=x
    
    with np.errstate(invalid='ignore',divide='ignore'):
        d=(mass/(num*coef))**(1./ex)
        d[num==0]=0.0
    
    return d
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
def gettimeprofs(xdir):
    print xdir
    files = sorted(
        glob.glob('/nobackup/rstorer/convperts/revu/' + xdir + '/' + xdir +
                  '*h5'))
    nt = len(files)
    z = getvar(files[0], 'z_coords')
    zarg = np.argmin(np.abs(z - 8000))
    nz = len(z)
    outvar2 = np.zeros((nt, nz))
    outvar5 = np.zeros((nt, nz))
    tmpprof = np.zeros((nt, nz))
    for t, fil in enumerate(files):
        cond = getvar(fil, 'tracer002') * 100. * 100. * 100.
        w = getvar(fil, 'w')
        massflux = cond * w

        colmax = np.max(w, 0)
        w2 = np.where(colmax > 2)
        w5 = np.where(colmax > 5)

        if np.max(w) > 5:
            updraft5 = massflux[:, w5[0], w5[1]]
            up5 = np.mean(updraft5, 1)
            outvar5[t, :] = up5
        updraft2 = massflux[:, w2[0], w2[1]]
        up2 = np.mean(updraft2, 1)
        outvar2[t, :] = up2
        ttm = massflux[:, w5[0], w5[1]]
        tmpprof[t, :] = np.mean(ttm, 1)

    return outvar2, outvar5
Ejemplo n.º 8
0
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
Ejemplo n.º 9
0
def modelvars(filename, arg):
    fil = hdf.File(filename, 'r')
    vapdep = (getvar(fil, 'vapicet')[arg:, :, :] +
              getvar(fil, 'vapliqt')[arg:, :, :]) * 2
    temp = getvar(fil, 'tempk')[arg:, 10, 10]
    w = getvar(fil, 'w')[arg:, :, :]
    fil.close()
    return vapdep, w, temp
Ejemplo n.º 10
0
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
Ejemplo n.º 11
0
def getprofs(xdir):
    print xdir
    budfiles = sorted(
        glob.glob('/nobackup/rstorer/h5files/mature-' + xdir +
                  '-refbudgetvars-90s-smoothed*'))
    condfiles = sorted(
        glob.glob('/nobackup/rstorer/h5files/mature-' + xdir +
                  '-condensate-smoo*'))
    rhofiles = sorted(
        glob.glob('/nobackup/rstorer/h5files/mature-' + xdir + '-rho-smoo*'))
    nt = len(budfiles)
    profsc = []
    profsz = []
    profln = []
    profactz = []
    profactc = []
    for i in range(nt):
        delz = getvar(budfiles[i], 'ref2') - getvar(budfiles[i], 'ref')
        onec = 10 * np.log10(
            getvar(condfiles[i], 'q') * getvar(rhofiles[i], 'q'))
        onec[np.isnan(onec)] = -40
        onec[onec < -40] = -40.
        onez = getvar(budfiles[i], 'ref')
        delc = (10 * np.log10(
            getvar(condfiles[i + 3], 'q') * getvar(rhofiles[i + 3], 'q')) -
                10 *
                np.log10(getvar(condfiles[i], 'q') * getvar(rhofiles[i], 'q')))
        delc[delc > 40] = 40.
        #dlnc = delc/onec
        #dlnc[np.isnan(dlnc)]=0.
        #dlnc[onec<0.00001]=0.
        delc[np.isnan(delc)] = 0.
        dlnc = delc
        w = getvar(budfiles[i], 'w')
        maxw = np.max(w, 0)
        conv = np.where(w > 1)
        pz = delz[conv[0], conv[1], conv[2]]
        pc = delc[conv[0], conv[1], conv[2]]
        pl = dlnc[conv[0], conv[1], conv[2]]
        pac = onec[conv[0], conv[1], conv[2]]
        paz = onez[conv[0], conv[1], conv[2]]
        profactz.extend(paz)
        profactc.extend(pac)
        profln.extend(pl)
        profsc.extend(pc)
        profsz.extend(pz)

    scout = np.asarray(profsc)
    lnout = np.asarray(profln[:])
    szout = np.asarray(profsz[:])
    azout = np.asarray(profactz[:])
    acout = np.asarray(profactc[:])
    print scout.min(), lnout.min(), szout.min(), azout.min(), acout.min()

    return scout, szout, lnout, azout, acout
Ejemplo n.º 12
0
def makeplots(fil1, fil2, mlist, dt, num):
    outnum = str(num)
    if num < 10:
        outnum = '0' + outnum
    diff, vertflux, micro, w = getbudgetvars(fil1, fil2, mlist, dt)
    vert = np.diff(vertflux, axis=0)
    colmax = np.max(w, 0)
    w1 = np.where(colmax > 5)
    diff1 = diff[:, w1[0], w1[1]]
    vert1 = vert[:, w1[0], w1[1]]
    flux = vertflux[:, w1[0], w1[1]]
    micro1 = micro[:, w1[0], w1[1]]
    height = getvar(fil1, 'z_coords')
    mdiff1 = np.mean(diff1, 1)
    mvert1 = np.mean(vert1, 1)
    mmicro1 = np.mean(micro1, 1)
    diffprof = np.mean(np.mean(diff, 1), 1)
    vertprof = np.mean(np.mean(vert, 1), 1)
    micprof = np.mean(np.mean(micro, 1), 1)

    intdiff = np.zeros_like(mdiff1)
    intmicro = np.zeros_like(mmicro1)
    intflux = np.mean(flux, 1)
    for z in range(82):
        intdiff[z] = np.sum(mdiff1[z:])
        intmicro[z] = np.sum(mmicro1[z:])
    return intdiff, intmicro, intflux
Ejemplo n.º 13
0
def calcadvflux(fil):
    u = getvar(fil, 'u')
    v = getvar(fil, 'v')
    q = getvar(fil, 'total_cond') / 1000.
    p = getvar(fil, 'press')
    t = getvar(fil, 'tempk')
    rho = (p * 100.) / (t * 287.)
    umean = np.mean(np.mean(u, 1), 1)
    vmean = np.mean(np.mean(v, 1), 1)
    uprime = u - umean[:, None, None]
    vprime = v - vmean[:, None, None]
    uflux = rho * q * uprime
    vflux = rho * q * vprime
    uadv = rho * q * umean[:, None, None]
    vadv = rho * q * vmean[:, None, None]
    return uflux, vflux, uadv, vadv
Ejemplo n.º 14
0
def plot2d2panel(xdir, var1, var2, rh0, rh1):
    height = getvar(
        '/nobackup/rstorer/convperts/revu/' + xdir + '/' + xdir +
        '-revu-001.h5', 'z_coords') / 1000.
    xs = np.arange(var1.shape[1]) * 5
    m = np.argmin(np.abs(height - 5))
    var1[:m, :] = np.min(var1[m:, :])
    var2[:m, :] = np.min(var2[m:, :])
    plt.subplot(1, 2, 1)
    plt.contourf(xs,
                 height,
                 var1,
                 levels=np.linspace(var1.min(), var1.max(), 20))
    plt.title('0-2 km')
    plt.xlabel(str(rh0))
    plt.ylabel('Height (km)')
    plt.ylim(5, 18)
    plt.colorbar()
    plt.subplot(1, 2, 2)
    plt.contourf(xs,
                 height,
                 var2,
                 levels=np.linspace(var2.min(), var2.max(), 20))
    plt.title('2-4 km')
    plt.xlabel(str(rh1))
    plt.yticks([])
    plt.ylim(5, 18)
    plt.colorbar()
    plt.suptitle(xdir)
    plt.savefig('surfacetracers2panel-' + xdir + '.png')
    plt.clf()
Ejemplo n.º 15
0
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
Ejemplo n.º 16
0
def getcloudtop(fil):
    q=getvar(fil,'total_cond')
    c=np.where(q>.01)
    q[c]=100.
    inds = q.shape[0]-1-np.argmax(q[::-1,:,:],0)
    inds[np.max(q,0)<.01]=0

    return inds
Ejemplo n.º 17
0
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)
Ejemplo n.º 18
0
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
Ejemplo n.º 19
0
def getprofs(xdir, varname):
    files = sorted(
        glob.glob('/nobackup/rstorer/convperts/revu/' + xdir + '/trac*h5'))
    nt = len(files)
    varout = np.zeros((82, nt))
    for i, fil in enumerate(files):
        t = getvar(fil, varname) * 100 * 100 * 100
        p = np.sum(np.sum(t, 1), 1)
        varout[:, i] = p
    return varout
Ejemplo n.º 20
0
def gettimeseries(xdir, varname):
    files = sorted(
        glob.glob('/nobackup/rstorer/convperts/revu/' + xdir + '/*h5'))
    nt = len(files)
    outmax = np.zeros(nt)
    outmean = np.zeros(nt)
    for x, fil in enumerate(files):
        v = getvar(fil, varname)
        outmax[x] = np.max(v)
        outmean[x] = np.mean(v)
    return outmax, outmean
Ejemplo n.º 21
0
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
Ejemplo n.º 22
0
def calc_diam(fil, varname, cname, cfmas, pwmas, unit):
    mfile = hdf.File(fil, 'r')
    mass = getvar(mfile, varname) / 1000.
    conc = getvar(mfile, cname[varname])
    rpw = 1. / pwmas[varname]
    if varname == 'cloud' or varname == 'drizzle':
        conc = conc * 1e6

    diam = (mass / (cfmas[varname] * conc))**(1 / pwmas[varname])
    diam[np.isnan(diam)] = 0.
    diam[mass < 1e-10] = 0

    label = unit[varname]
    if label == 'mm':
        diam = diam * 1000.
    else:
        diam = diam * 1e6
    print varname, diam[diam > 0].min(), diam.max(), label
    mfile.close()

    return diam
Ejemplo n.º 23
0
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()
Ejemplo n.º 24
0
def getprofs(xdir):
    print xdir
    budfiles = sorted(
        glob.glob('/nobackup/rstorer/h5files/mature-' + xdir +
                  '-refbudgetvars-90s-smoothed*'))
    condfiles = sorted(
        glob.glob('/nobackup/rstorer/h5files/mature-' + xdir +
                  '-condensate-smoo*'))
    nt = len(budfiles)
    profsc = []
    profsz = []
    profln = []
    for i in range(nt):
        delz = getvar(budfiles[i], 'ref2') - getvar(budfiles[i], 'ref')
        onec = getvar(condfiles[i], 'q')
        delc = (getvar(condfiles[i + 3], 'q') - getvar(condfiles[i], 'q'))
        dlnc = delc / onec
        dlnc[np.isnan(dlnc)] = 0.
        dlnc[onec < 0.00001] = 0.
        w = getvar(budfiles[i], 'w')
        maxw = np.max(w, 0)
        conv = np.where(maxw > 1)
        pz = delz[:, conv[0], conv[1]]
        pc = delc[:, conv[0], conv[1]]
        pl = dlnc[:, conv[0], conv[1]]
        profln.append(pl)
        profsc.append(pc)
        profsz.append(pz)

    scout = np.concatenate(profsc[:], axis=1)
    lnout = np.concatenate(profln[:], axis=1)
    szout = np.concatenate(profsz[:], axis=1)

    return scout, szout, lnout
Ejemplo n.º 25
0
def makeplots(fil1, dt, num):
    outnum = str(num)
    if num < 10:
        outnum = '0' + outnum
    w = getvar(fil1, 'w')
    colmax = np.max(w, 0)
    w1 = np.where(colmax > 5)

    wup = w[:, w1[0], w1[1]]

    wout = np.mean(wup, 1)

    return wout
Ejemplo n.º 26
0
def advprofiles(fil, u, v):
    w = getvar(fil, 'w')
    wmax = np.max(w[37:, :, :], 0)
    advprofs = np.zeros(82)
    ii = 200
    jj = 200
    uleft = u[:, ii - 100:ii + 100, jj - 100]
    uright = u[:, ii - 100:ii + 100, jj + 100]
    udiff = (uleft - uright) / 200.
    vbottom = v[:, ii - 100, jj - 100:jj + 100]
    vtop = v[:, ii + 100, jj - 100:jj + 100]
    vdiff = (vbottom - vtop) / 200.
    advprofs = udiff + vdiff
    return advprofs
Ejemplo n.º 27
0
def intsizedist(fil,var,coord=None):
    nnames = {  'pristine':'pris_concen_kg',
                'cloud':'cloud_concen_mg',
                'aggregates':'agg_concen_kg',
                'snow':'snow_concen_kg',
                'drizzle':'drizzle_concen_mg',
                'hail':'hail_concen_kg',
                'rain':'rain_concen_kg',
                'graupel':'graup_concen_kg'
            }
    #If no coord given, uses None, which just returns full array + a dimension
    
    
    mass = np.array(getvar(fil,var)[coord]/1000.)
    num = np.array(getvar(fil,nnames[var])[coord])
    
        
    if var == 'cloud' or var == 'drizzle':
        num=num*1000.*1000.
    coef, ex, nu = getdefault(var) 

    m=mass.flatten()
    n=num.flatten()
    tval = np.zeros_like(m)
    bval = np.zeros_like(m)
    for i in range(len(m)):
        if n[i] >0:
            dvals, func = calcgammadist(m[i],n[i],coef,ex,nu)
            diffr = np.zeros_like(dvals)
            diffr[1:] = np.diff(dvals)/2
            tval[i] = np.sum( (dvals/2.)**3 * diffr * func * 3.14 )
            bval[i] = np.sum( (dvals/2.)**2 * diffr * func * 3.14 )
    bot = np.reshape(bval,mass.shape)
    top = np.reshape(tval,mass.shape)

    return mass, num, bot,top
Ejemplo n.º 28
0
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
Ejemplo n.º 29
0
def plot2d(xdir, varname, var):
    height = getvar(
        '/nobackup/rstorer/convperts/revu/' + xdir + '/' + xdir +
        '-revu-001.h5', 'z_coords') / 1000.
    xs = np.arange(var.shape[1]) * 5
    m = np.argmin(np.abs(height - 5))
    var[:m, :] = np.min(var[m:, :])
    plt.contourf(xs, height, var, levels=np.linspace(var.min(), var.max(), 20))
    plt.title(xdir)
    plt.xlabel('Time (min)')
    plt.ylabel('Height (km)')
    plt.ylim(5, 18)
    plt.colorbar()
    plt.savefig('total2dprof-' + xdir + '-' + varname + '.png')
    plt.clf()
Ejemplo n.º 30
0
def advprofiles(fil, u, v):
    w = getvar(fil, 'w')
    wmax = np.max(w[37:, :, :], 0)
    vals = np.where(wmax > 5)
    nprofs = len(vals[0])
    print nprofs
    advprofs = np.zeros((82, nprofs))
    for i in range(nprofs):
        ii = vals[0][i]
        jj = vals[1][i]
        udiff = (
            u[:, ii, jj - 10] - u[:, ii, jj + 10]
        ) / 20.  #April 11, changed from +-1/2 to +-10/20 for 5km avg for advection
        vdiff = (v[:, ii - 10, jj] - v[:, ii + 10, jj]) / 20.
        advprofs[:, i] = udiff + vdiff
    return advprofs