示例#1
0
文件: calcs.py 项目: lcarlaw/meso
def worker(pres, tmpc, hght, dwpc, wspd, wdir):
    mucape = np.zeros((tmpc.shape[1], tmpc.shape[2]))
    mlcape = np.zeros_like(mucape)
    cape3km = np.zeros_like(mucape)
    lr3km = np.zeros_like(mucape)
    mlcin = np.zeros_like(mucape)
    mllcl = np.zeros_like(mucape)
    ebot = np.zeros_like(mucape)
    etop = np.zeros_like(mucape)
    eshr = np.zeros_like(mucape)
    esrh = np.zeros_like(mucape)
    estp = np.zeros_like(mucape)
    tts = np.zeros_like(mucape)

    rm5_u = np.zeros_like(mucape)
    rm5_v = np.zeros_like(mucape)
    lm5_u = np.zeros_like(mucape)
    lm5_v = np.zeros_like(mucape)
    ebwd_u = np.zeros_like(mucape)
    ebwd_v = np.zeros_like(mucape)
    shr1_u = np.zeros_like(mucape)
    shr1_v = np.zeros_like(mucape)
    shr3_u = np.zeros_like(mucape)
    shr3_v = np.zeros_like(mucape)

    for j in prange(tmpc.shape[1]):
        for i in prange(tmpc.shape[2]):
            prof = profile.create_profile(pres=pres[:, j, i],
                                          tmpc=tmpc[:, j, i],
                                          hght=hght[:, j, i],
                                          dwpc=dwpc[:, j, i],
                                          wspd=wspd[:, j, i],
                                          wdir=wdir[:, j, i])

            sfc = prof.pres[prof.sfc]
            p6km = interp.pres(prof, interp.to_msl(prof, 6000.))
            blkshr_u, blkshr_v = winds.wind_shear(prof, pbot=sfc, ptop=p6km)
            mean_u, mean_v = winds.mean_wind(prof, pbot=sfc, ptop=p6km)

            # Bunkers Right and Left motion vectors (approximations here...)
            temp = transform(blkshr_u, blkshr_v, 0., 7.5 * MS2KTS,
                             -7.5 * MS2KTS, 0.)
            BlkMag = np.hypot(blkshr_u, blkshr_v)
            rm5_u[j, i] = mean_u + (temp[0] / BlkMag)
            rm5_v[j, i] = mean_v + (temp[1] / BlkMag)
            lm5_u[j, i] = mean_u - (temp[0] / BlkMag)
            lm5_v[j, i] = mean_v - (temp[1] / BlkMag)

            eff_inflow = params.effective_inflow_layer(prof)
            ebot[j, i] = interp.to_agl(prof, interp.hght(prof, eff_inflow[0]))
            etop[j, i] = interp.to_agl(prof, interp.hght(prof, eff_inflow[1]))

            # Parcel buoyancy calculations
            mupcl = params.parcelx(prof, flag=3)
            mlpcl = params.parcelx(prof, flag=4)

            mllcl[j, i] = mlpcl.lclhght
            mlcape[j, i] = mlpcl.bplus
            mlcin[j, i] = mlpcl.bminus
            mucape[j, i] = mupcl.bplus
            cape3km[j, i] = mlpcl.b3km

            # Effective BWD
            ebot_hght = interp.to_agl(prof, interp.hght(prof, eff_inflow[0]))
            height_top = (mupcl.elhght + ebot_hght) / 2.
            ptop = interp.pres(prof, interp.to_msl(prof, height_top))

            ebwd_u[j, i], ebwd_v[j, i] = winds.wind_shear(prof,
                                                          pbot=eff_inflow[0],
                                                          ptop=ptop)
            eshr[j, i] = utils.mag(ebwd_u[j, i], ebwd_v[j, i])

            p1km = interp.pres(prof, interp.to_msl(prof, 1000.))
            shr1_u[j, i], shr1_v[j, i] = winds.wind_shear(prof,
                                                          pbot=sfc,
                                                          ptop=p1km)

            p3km = interp.pres(prof, interp.to_msl(prof, 3000.))
            shr3_u[j, i], shr3_v[j, i] = winds.wind_shear(prof,
                                                          pbot=sfc,
                                                          ptop=p3km)
            t3km = interp.temp(prof, p3km)
            lr3km[j, i] = (tmpc[0, j, i] - t3km) / 3.

            esrh[j, i] = winds.helicity(prof,
                                        ebot[j, i],
                                        etop[j, i],
                                        stu=rm5_u[j, i],
                                        stv=rm5_v[j, i])[0]
            estp[j, i] = params.stp_cin(mlcape[j, i], esrh[j, i], eshr[j, i],
                                        mllcl[j, i], mlcin[j, i])
            p1km = interp.pres(prof, interp.to_msl(prof, 1000.))
            srh1 = winds.helicity(prof,
                                  ebot[j, i],
                                  p1km,
                                  stu=rm5_u[j, i],
                                  stv=rm5_v[j, i])[0]

            # Tornadic Tilting and Stretching parameter (TTS)
            A = (srh1 * np.clip(cape3km[j, i], 0, 150)) / 6500.
            B = np.clip(mlcape[j, i] / 2000., 1, 1.5)
            ebwd = np.hypot(ebwd_u[j, i], ebwd_v[j, i]) * KTS2MS
            ebwd = np.where(ebwd < 12.5, 0, ebwd)
            C = np.clip(ebwd / 20., 0, 1.5)
            TTS = np.clip(A * B * C, 0, 9999)
            if mllcl[j, i] > 1700 or mlcin[j, i] < -100: TTS = 0
            tts[j, i] = TTS

    return esrh, estp, cape3km, lr3km, mlcape, mlcin, mucape, tts, ebwd_u, ebwd_v, \
           rm5_u, rm5_v, lm5_u, lm5_v, shr1_u, shr1_v, shr3_u, shr3_v
示例#2
0
def calcs(**kwargs):
    tmpc = kwargs.get('tmpc')
    dwpc = kwargs.get('dwpc')
    hght = kwargs.get('hght')
    wdir = kwargs.get('wdir')
    wspd = kwargs.get('wspd')
    pres = kwargs.get('pres')

    # For our jitted sharppy routines, need to be REALLY careful with units or
    # things will break. Probably overkill here, but worth it to be safe!
    #tmpc = np.array(tmpc, dtype='float64')
    #dwpc = np.array(dwpc, dtype='float64')
    #hght = np.array(hght, dtype='float64')
    #wdir = np.array(wdir, dtype='float64')
    #wspd = np.array(wspd, dtype='float64')
    #pres = np.array(pres, dtype='int32')

    mucape = np.zeros((tmpc.shape[1], tmpc.shape[2]))
    mlcape = np.zeros((tmpc.shape[1], tmpc.shape[2]))
    mlcin = np.zeros((tmpc.shape[1], tmpc.shape[2]))
    mulpl = np.zeros((tmpc.shape[1], tmpc.shape[2]))
    ebot = np.zeros((tmpc.shape[1], tmpc.shape[2]))
    etop = np.zeros((tmpc.shape[1], tmpc.shape[2]))
    eshr = np.zeros((tmpc.shape[1], tmpc.shape[2]))
    esrh = np.zeros((tmpc.shape[1], tmpc.shape[2]))
    estp = np.zeros((tmpc.shape[1], tmpc.shape[2]))
    ebwd_u = np.zeros((tmpc.shape[1], tmpc.shape[2]))
    ebwd_v = np.zeros((tmpc.shape[1], tmpc.shape[2]))

    for j in range(tmpc.shape[1]):
        for i in range(tmpc.shape[2]):
            prof = profile.create_profile(pres=pres[:, j, i],
                                          tmpc=tmpc[:, j, i],
                                          hght=hght[:, j, i],
                                          dwpc=dwpc[:, j, i],
                                          wspd=wspd[:, j, i],
                                          wdir=wdir[:, j, i])
            #prof = profile.create_profile(pres=pres, tmpc=tmpc[:,j,i],
            #                              hght=hght[:,j,i], dwpc=dwpc[:,j,i],
            #                              wspd=wspd[:,j,i], wdir=wdir[:,j,i])

            # Effective inflow and shear calculations
            eff_inflow = params.effective_inflow_layer(prof)
            ebot[j, i] = interp.to_agl(prof, interp.hght(prof, eff_inflow[0]))
            etop[j, i] = interp.to_agl(prof, interp.hght(prof, eff_inflow[1]))

            # This isn't quite right...need to find midpoint between eff Inflow
            # bottom and EL
            ebwd_u[j, i], ebwd_v[j, i] = winds.wind_shear(prof,
                                                          pbot=eff_inflow[0],
                                                          ptop=500)
            eshr[j, i] = utils.mag(ebwd_u[j, i], ebwd_v[j, i])

            # Bunkers storm motion function not implemented yet.
            #srwind = params.bunkers_storm_motion(prof)
            #esrh[j,i] = winds.helicity(prof, ebot[j,i], etop[j,i], stu=srwind[0],
            #                           stv = srwind[1])[0]
            esrh[j, i] = winds.helicity(prof, ebot[j, i], etop[j, i])[0]

            # Parcel buoyancy calculations
            mupcl = params.parcelx(prof, flag=3)
            mlpcl = params.parcelx(prof, flag=4)
            mucape[j, i] = mupcl.bplus
            mulpl[j, i] = mupcl.lplhght
            mlcape[j, i] = mlpcl.bplus
            mlcin[j, i] = mlpcl.bminus
            estp[j, i] = params.stp_cin(mlpcl.bplus, esrh[j, i], eshr[j, i],
                                        mlpcl.lclhght, mlpcl.bminus)

    ebwd_u = np.where(eshr < 24., np.nan, ebwd_u)
    ebwd_v = np.where(eshr < 24., np.nan, ebwd_v)
    eshr = np.where(eshr < 24., np.nan, eshr)
    esrh = np.where(esrh < -900., -99, esrh)
    estp = np.where(estp < -900, 0., estp)

    ret = {
        'mucape': mucape,
        'mlcape': mlcape,
        'mlcin': mlcin,
        'mulpl': mulpl,
        'ebot': ebot,
        'etop': etop,
        'ebwd_u': ebwd_u,
        'ebwd_v': ebwd_v,
        'eshr': eshr,
        'esrh': esrh,
        'estp': estp
    }
    return ret
示例#3
0
def sharppy_calcs(**kwargs):
    tmpc = kwargs.get('tmpc')
    dwpc = kwargs.get('dwpc')
    hght = kwargs.get('hght')
    wdir = kwargs.get('wdir')
    wspd = kwargs.get('wspd')
    pres = kwargs.get('pres')

    mucape = np.zeros((tmpc.shape[1], tmpc.shape[2]))
    mlcape = np.zeros((tmpc.shape[1], tmpc.shape[2]))
    mlcin = np.zeros((tmpc.shape[1], tmpc.shape[2]))
    mulpl = np.zeros((tmpc.shape[1], tmpc.shape[2]))
    ebot = np.zeros((tmpc.shape[1], tmpc.shape[2]))
    etop = np.zeros((tmpc.shape[1], tmpc.shape[2]))
    eshr = np.zeros((tmpc.shape[1], tmpc.shape[2]))
    esrh = np.zeros((tmpc.shape[1], tmpc.shape[2]))
    estp = np.zeros((tmpc.shape[1], tmpc.shape[2]))
    ebwd_u = np.zeros((tmpc.shape[1], tmpc.shape[2]))
    ebwd_v = np.zeros((tmpc.shape[1], tmpc.shape[2]))

    for j in range(tmpc.shape[1]):
        for i in range(tmpc.shape[2]):
            prof = profile.create_profile(pres=pres[:, j, i],
                                          tmpc=tmpc[:, j, i],
                                          hght=hght[:, j, i],
                                          dwpc=dwpc[:, j, i],
                                          wspd=wspd[:, j, i],
                                          wdir=wdir[:, j, i])

            # Effective inflow and shear calculations
            eff_inflow = params.effective_inflow_layer(prof)
            ebot[j, i] = interp.to_agl(prof, interp.hght(prof, eff_inflow[0]))
            etop[j, i] = interp.to_agl(prof, interp.hght(prof, eff_inflow[1]))

            # This isn't quite right...need to find midpoint between eff Inflow
            # bottom and EL
            ebwd_u[j, i], ebwd_v[j, i] = winds.wind_shear(prof,
                                                          pbot=eff_inflow[0],
                                                          ptop=500)
            eshr[j, i] = utils.mag(ebwd_u[j, i], ebwd_v[j, i])

            # Bunkers storm motion function not implemented yet.
            #srwind = params.bunkers_storm_motion(prof)
            #esrh[j,i] = winds.helicity(prof, ebot[j,i], etop[j,i], stu=srwind[0],
            #                           stv = srwind[1])[0]
            esrh[j, i] = winds.helicity(prof, ebot[j, i], etop[j, i])[0]

            # Parcel buoyancy calculations
            mupcl = params.parcelx(prof, flag=3)
            mlpcl = params.parcelx(prof, flag=4)
            mucape[j, i] = mupcl.bplus
            mulpl[j, i] = mupcl.lplhght
            mlcape[j, i] = mlpcl.bplus
            mlcin[j, i] = mlpcl.bminus
            estp[j, i] = params.stp_cin(mlpcl.bplus, esrh[j, i], eshr[j, i],
                                        mlpcl.lclhght, mlpcl.bminus)

    # Apply some data masks
    mlcin = np.where(mlcape < 25., 0, mlcin)
    mulpl = np.where(mlcape < 25., 0, mulpl)
    mucape = gaussian_filter(mucape, sigma=sigma)
    mlcape = gaussian_filter(mlcape, sigma=sigma)
    mlcin = gaussian_filter(mlcin, sigma=sigma)
    mulpl = gaussian_filter(mulpl, sigma=sigma)

    eshr = np.where(np.isnan(eshr), 0, eshr)
    eshr = gaussian_filter(eshr, sigma=sigma)
    eshr = np.where(eshr < 24., np.nan, eshr)
    ebwd_u = np.where(eshr < 24., np.nan, ebwd_u)
    ebwd_v = np.where(eshr < 24., np.nan, ebwd_v)

    esrh = np.where(np.isnan(esrh), 0, esrh)
    esrh = gaussian_filter(esrh, sigma=sigma)
    estp = np.where(np.isnan(estp), 0, estp)
    estp = gaussian_filter(estp, sigma=sigma)

    idx = np.where(np.isnan(ebot))
    ebot = np.where(np.isnan(ebot), 0, ebot)
    ebot = gaussian_filter(ebot, sigma=sigma)
    ebot[idx] = np.nan

    ret = {
        'mucape': mucape,
        'mlcape': mlcape,
        'mlcin': mlcin,
        'mulpl': mulpl,
        'ebot': ebot,
        'etop': etop,
        'ebwd_u': ebwd_u,
        'ebwd_v': ebwd_v,
        'eshr': eshr,
        'esrh': esrh,
        'estp': estp
    }
    return ret
示例#4
0
wspds = thermo.wind_speed(uwnd, vwnd)

rh = ds.r.values / 100.
tmpc = ds.t.values - ZEROCNK
dwpc = thermo.dewpoint_from_rh(tmpc + ZEROCNK, rh)

# For our jitted sharppy routines, need to be carefuly about units. The float64
# type is standard (type 'double'), but specify here just to be safe. 
tmpc = np.array(tmpc, dtype='float64')
dwpc = np.array(dwpc, dtype='float64')
hghts = np.array(hghts, dtype='float64')
wdirs = np.array(wdirs, dtype='float64')
wspds = np.array(wspds, dtype='float64')
pres = np.array(pres, dtype='int32')

t,j,i = 0,0,70
prof = profile.create_profile(pres=pres,tmpc=tmpc[t,:,j,i],
                              hght=hghts[t,:,j,i],dwpc=dwpc[t,:,j,i],
                              wspd=wspds[t,:,j,i],wdir=wdirs[t,:,j,i])
#print(prof.tmpc, prof.dwpc)
#mupcl = params.parcelx( prof, flag=3 )
#effpcl = params.effective_inflow_layer( prof, mupcl)
#mlpcl = params.parcelx( prof, flag=6 )
eff_inflow = params.effective_inflow_layer(prof)
ebot_hght = interp.to_agl(prof, interp.hght(prof, eff_inflow[0]))
etop_hght = interp.to_agl(prof, interp.hght(prof, eff_inflow[1]))

print(ebot_hght, etop_hght)

#print(mupcl.bplus)