Exemplo n.º 1
0
def calc_wqv(ncFileName, dt):
    print(ncFileName)
    out = {}
    for model in models:
        print('\t' + model)
        srcNCPath = inpPath + model + '/zlev/' + ncFileName

        ncf = ncField.ncField('QV', srcNCPath, ssI)
        ncf.loadValues()
        qv = ncf.vals[0, 20, :, :]
        WQVncf = ncf.copy()
        WQVncf.fieldName = var

        #ncf = ncField.ncField('RHO', srcNCPath, ssI)
        #ncf.loadValues()
        #rho = ncf.vals

        ncf = ncField.ncField('W', srcNCPath, ssI)
        ncf.loadValues()
        w = ncf.vals[0, 20, :, :]

        wqv = w * qv
        wqv = wqv.mean()
        #wqv = rho*w*qv

        #WQVncf.vals = wqv
        #WQVncf.addVarToExistingNC(srcNCPath)
        out[model] = wqv
        out['time'] = dt

    return (out)
Exemplo n.º 2
0
def calc_cw(ncFileName):
    print(ncFileName)
    for model in models:
        srcNCPath = inpPath + model + '/zlev/' + ncFileName

        l_already_done = False
        try:
            fqvfield = ncField.ncField(var, srcNCPath, ssI)
            l_already_done = True
        except:
            pass

        if not l_already_done:
            NCF = ncField.ncField('QC', srcNCPath, ssI)
            NCF.loadValues()
            qc = NCF.vals

            NCF = ncField.ncField('QI', srcNCPath, ssI)
            NCF.loadValues()
            qi = NCF.vals

            cw = qc + qi
            
            CWncf = NCF.copy() 
            CWncf.fieldName = 'CW'
            CWncf.vals = cw
            CWncf.addVarToExistingNC(srcNCPath)
Exemplo n.º 3
0
def calc_bulk(tCount, VOL, Atot):
    ncFileName = 'lffd{0:%Y%m%d%H}z.nc'.format(dts[tCount].astype(datetime))
    if tCount % 24 == 0:
        print('\t\t'+ncFileName)
    #print('\t\t'+ncFileName)

    srcNCPath = inpPath + res + mode + '/' + ncFileName

    RHOncf = ncField.ncField('RHO', srcNCPath, ssI[res])
    RHOncf.loadValues()
    rho = RHOncf.vals

    result = {}

    # CALCULATE TENDENCIES
    #Mtot = np.nansum(rho*100*A)
    MASS = rho * VOL
    for var in vars:
        NCF = ncField.ncField(var, srcNCPath, ssI[res])
        NCF.loadValues()
        vals = NCF.vals
        if i_variables == 'QV':
            # unit is domain average mm/h precipitation
            result[var] = np.sum(MASS*vals*3600)/Atot
            #print(out[var][tCount])
        else:
            raise NotImplementedError()
        #out[var][tCount] = np.nansum(vals*rho*100*A)/Mtot

    return(result)
Exemplo n.º 4
0
def calc_horflux(ncFileName):
    print(ncFileName)

    for res in ress:
        for mode in modes:
            #print('\t'+res+mode)
            srcNCPath = inpPath + res + mode + '/' + ncFileName

            ################################## AQVT
            l_already_done = False
            try:
                field = ncField.ncField('AQVT_HADV', srcNCPath, ssI)
                l_already_done = True
            except:
                pass

            if not l_already_done:
                QV_ADVncf = ncField.ncField('AQVT_ADV', srcNCPath, ssI[res])
                QV_ADVncf.loadValues()
                qv_adv = QV_ADVncf.vals
                QV_ZADVncf = ncField.ncField('AQVT_ZADV', srcNCPath, ssI[res])
                QV_ZADVncf.loadValues()
                qv_zadv = QV_ZADVncf.vals

                qv_hadv = qv_adv - qv_zadv

                QV_HADVncf = QV_ADVncf.copy() 
                QV_HADVncf.fieldName = 'AQVT_HADV'
                QV_HADVncf.vals = qv_hadv
                QV_HADVncf.addVarToExistingNC(srcNCPath)
Exemplo n.º 5
0
def calc_rho(ncFileName):
    print(ncFileName)
    for res in ress:
        for mode in modes:
            #print('\t'+res+mode)

            srcNCPath = inpPath + res + mode + '/' + ncFileName

            l_already_done = False
            try:
                rhofield = ncField.ncField('RHO', srcNCPath, ssI)
                l_already_done = True
            except:
                pass


            if not l_already_done:
                QCncf = ncField.ncField('QC', srcNCPath, ssI)
                QCncf.loadValues()
                qc = QCncf.vals
                QRncf = ncField.ncField('QR', srcNCPath, ssI)
                QRncf.loadValues()
                qr = QRncf.vals
                QIncf = ncField.ncField('QI', srcNCPath, ssI)
                QIncf.loadValues()
                qi = QIncf.vals
                QSncf = ncField.ncField('QS', srcNCPath, ssI)
                QSncf.loadValues()
                qs = QSncf.vals
                QGncf = ncField.ncField('QG', srcNCPath, ssI)
                QGncf.loadValues()
                qg = QGncf.vals
                
                hydrotot = qc + qr + qi + qs + qg

                QVncf = ncField.ncField('QV', srcNCPath, ssI)
                QVncf.loadValues()
                qv = QVncf.vals
                Tncf = ncField.ncField('T', srcNCPath, ssI)
                Tncf.loadValues()
                T = Tncf.vals
                Pncf = ncField.ncField('P', srcNCPath, ssI)
                Pncf.loadValues()
                P = Pncf.vals

                tempFactor = qv*0.622 + 1 - hydrotot 
                Tdens = T*tempFactor 
                Rd = 287.1
                RHO = P/(Tdens*Rd)

                
                RHOncf = QVncf.copy() 
                RHOncf.fieldName = 'RHO'
                RHOncf.vals = RHO
                RHOncf.addVarToExistingNC(srcNCPath)
Exemplo n.º 6
0
def calc_fqv(ncFileName):
    print(ncFileName)
    for res in ress:
        for mode in modes:
            print('\t'+res+mode)
            srcNCPath = inpPath + res + mode + '/' + ncFileName

            l_already_done = False
            try:
                fqvfield = ncField.ncField(var, srcNCPath, ssI)
                l_already_done = True
            except:
                pass

            if not l_already_done:
                ncf = ncField.ncField('QV', srcNCPath, ssI)
                ncf.loadValues()
                qv = ncf.vals
                FQVncf = ncf.copy() 
                FQVncf.fieldName = var

                ncf = ncField.ncField('RHO', srcNCPath, ssI)
                ncf.loadValues()
                rho = ncf.vals
                
                if (var == 'FQV') or (var == 'FQVx'):
                    ncf = ncField.ncField('U', srcNCPath, ssI)
                    ncf.loadValues()
                    u = ncf.vals

                if (var == 'FQV') or (var == 'FQVy'):
                    ncf = ncField.ncField('V', srcNCPath, ssI)
                    ncf.loadValues()
                    v = ncf.vals

                if (var == 'FQV'):
                    uv = np.sqrt(np.power(u,2) + np.power(v,2))
                    fqv = rho*uv*qv
                elif (var == 'FQVx'):
                    fqv = rho*u*qv
                elif (var == 'FQVy'):
                    fqv = rho*v*qv

                FQVncf.vals = fqv
                FQVncf.addVarToExistingNC(srcNCPath)
Exemplo n.º 7
0
        A = np.power(dx, 2)

        for mode in modes:
            print('###### ' + res + mode + ' ######')

            out[res + mode] = np.full(len(out['time']), np.nan)

            for tCount in range(0, len(dts)):
                ncFileName = 'lffd{0:%Y%m%d%H}z.nc'.format(
                    dts[tCount].astype(datetime))
                if tCount % 24 == 0:
                    print('\t\t' + ncFileName)
                #print('\t\t'+ncFileName)

                srcNCPath = inpPath + res + mode + '/' + ncFileName

                RHOncf = ncField.ncField('RHO', srcNCPath, ssI[res])
                RHOncf.loadValues()
                rho = RHOncf.vals

                # CALCULATE VOL AV DENSITY WEIGHT
                Mtot = np.nansum(rho * dz * A)
                NCF = ncField.ncField(fieldName[1:], srcNCPath, ssI[res])
                NCF.loadValues()
                vals = NCF.vals
                out[res + mode][tCount] = np.nansum(vals * rho * dz * A) / Mtot
                out['units'] = NCF.units

    name = fieldName
    saveObj(out, folder, name)
Exemplo n.º 8
0
# Altitude arrays
altI = np.asarray(altInds)
alts = np.asarray(altInds)
alts[altI <= 60] = altI[altI <= 60] * 100
alts[altI > 60] = (altI[altI > 60] - 60) * 1000 + 6000
#altsu = np.nan

#dt0 = datetime(2006,7,12,0)
#dt1 = datetime(2006,7,12,1)
#dts = np.arange(dt0,dt1,timedelta(hours=1))
inpPath = '../01_rawData/topocut/'
res = '4.4'
mode = ''
srcNCPath = inpPath + res + mode + '/' + 'lffd2006071508z.nc'

RHOncf = ncField.ncField('RHO', srcNCPath, ssI[res])
RHOncf.loadValues()
rho = RHOncf.vals.squeeze()
Wncf = ncField.ncField('W', srcNCPath, ssI[res])
Wncf.loadValues()
w = Wncf.vals.squeeze()
QVncf = ncField.ncField('QV', srcNCPath, ssI[res])
QVncf.loadValues()
qv = QVncf.vals.squeeze()
AQVT_ZADVncf = ncField.ncField('AQVT_ZADV', srcNCPath, ssI[res])
AQVT_ZADVncf.loadValues()
aqvtz = AQVT_ZADVncf.vals.squeeze()

dA = np.power(4400, 2)
dz = 100
dV = dz * dA
Exemplo n.º 9
0
            for tCount in range(0, len(dts)):
                ncFileName = 'lffd{0:%Y%m%d%H}z.nc'.format(
                    dts[tCount].astype(datetime))
                if tCount % 1 == 0:
                    print('\t\t' + ncFileName)

                calc_src_path = inpPath + mode + res + '/calc/'

                #RHOncf = ncField.ncField('RHO', srcNCPath, ssI[res])
                #RHOncf.loadValues()
                #rho = RHOncf.vals
                #rhou = unstaggerZ_4D(rho)
                if i_wall in ['E', 'W']:
                    ncf = ncField.ncField(
                        'FQVX', os.path.join(calc_src_path, 'FQVX',
                                             ncFileName), ssI[res])
                elif i_wall in ['S', 'N']:
                    ncf = ncField.ncField(
                        'FQVY', os.path.join(calc_src_path, 'FQVY',
                                             ncFileName), ssI[res])
                elif i_wall in ['bottom', 'top']:
                    ncf = ncField.ncField(
                        'FQVZ', os.path.join(calc_src_path, 'FQVZ',
                                             ncFileName), ssI[res])
                ncf.loadValues()

                if i_wall in ['E', 'W', 'S', 'N']:
                    flx = ncf.vals * dx * 100 * normVec
                elif i_wall in ['bottom', 'top']:
                    flx = ncf.vals * dx**2 * normVec
Exemplo n.º 10
0
dt0 = datetime(2006,7,11,0)
dt1 = datetime(2006,7,20,1)
#dt1 = datetime(2006,7,11,1)
dts = np.arange(dt0,dt1,timedelta(hours=1))
inpPath = '../01_rawData/topocut/'

for i in range(0,len(dts)):
    ncFileName = 'lffd{0:%Y%m%d%H}z.nc'.format(dts[i].astype(datetime))
    print(ncFileName)

    for res in ress:
        for mode in modes:
            #print('\t'+res+mode)
            srcNCPath = inpPath + res + mode + '/' + ncFileName

            NCF = ncField.ncField('P', srcNCPath, ssI)
            NCF.loadValues()
            p = NCF.vals

            NCF = ncField.ncField('T', srcNCPath, ssI)
            NCF.loadValues()
            t = NCF.vals

            pott = t*(100000/p)**0.286
            
            POTTncf = NCF.copy() 
            POTTncf.fieldName = 'POTT'
            POTTncf.vals = pott
            POTTncf.addVarToExistingNC(srcNCPath)
Exemplo n.º 11
0
from ncClasses.subdomains import setSSI
import matplotlib.pyplot as plt
import numpy as np
os.chdir('00_newScripts/')

i_resolutions = 3
i_subdomain = 0

ssI, domainName = setSSI(i_subdomain, {})

inpPath = '../01_rawData/topocut/'
#inpPath = '../01_rawData/'
res = '4.4'
mode = ''
ncFileName = 'lffd2006071515z.nc'
#ncFileName = 'constantParams.nc'

#inpPath = '../02_fields/topocut/'
#res = '4.4'
#mode = ''
#ncFileName = 'zQV.nc'

srcNCPath = inpPath + res + mode + '/' + ncFileName
print(srcNCPath)
qc = ncField.ncField('QC', srcNCPath, ssI)
#qc.saveToNewNC('../uTest.nc')
qc.addVarToExistingNC('../uTest.nc')
#plt.contourf(qc.vals[0,10,:,:].squeeze())
#plt.colorbar()
#plt.show()
Exemplo n.º 12
0
#dt0 = datetime(2006,7,15,15)
dt1 = datetime(2006,7,20,1)
#dt1 = datetime(2006,7,15,16)
dts = np.arange(dt0,dt1,timedelta(hours=1))
inpPath = '../01_rawData/topocut/'

for i in range(0,len(dts)):
    ncFileName = 'lffd{0:%Y%m%d%H}z.nc'.format(dts[i].astype(datetime))
    print(ncFileName)

    for res in ress:
        for mode in modes:
            #print('\t'+res+mode)
            srcNCPath = inpPath + res + mode + '/' + ncFileName

            NCF = ncField.ncField('QR', srcNCPath, ssI)
            NCF.loadValues()
            qr = NCF.vals

            NCF = ncField.ncField('QG', srcNCPath, ssI)
            NCF.loadValues()
            qg = NCF.vals

            NCF = ncField.ncField('QS', srcNCPath, ssI)
            NCF.loadValues()
            qs = NCF.vals

            pw = qr + qg + qs
            
            PWncf = NCF.copy() 
            PWncf.fieldName = 'PW'
    print(ncFileName)

    out['times'].append(dts[i].astype(datetime))

    for aI, alt_ind in enumerate(alt_inds):
        for res in ress:
            for mode in modes:
                #print('\t'+res+mode)
                srcNCPath = inpPath + res + mode + '/' + ncFileName

                res_ssI = {}
                res_ssI['altitude'] = [alt_ind]
                for key in ['rlon', 'rlat']:
                    res_ssI[key] = ssI[res][key]

                NCF = ncField.ncField('QC', srcNCPath, res_ssI)
                NCF.loadValues()
                qc = NCF.vals

                NCF = ncField.ncField('QI', srcNCPath, res_ssI)
                NCF.loadValues()
                qi = NCF.vals

                NCF = ncField.ncField('W', srcNCPath, res_ssI)
                NCF.loadValues()
                w = NCF.vals

                NCF = ncField.ncField('RHO', srcNCPath, res_ssI)
                NCF.loadValues()
                rho = NCF.vals
Exemplo n.º 14
0
dt0 = datetime(2006, 7, 11, 0)
#dt0 = datetime(2006,7,15,15)
dt1 = datetime(2006, 7, 20, 1)
#dt1 = datetime(2006,7,15,16)
dts = np.arange(dt0, dt1, timedelta(hours=1))
inpPath = '../01_rawData/topocut/'

for i in range(0, len(dts)):
    ncFileName = 'lffd{0:%Y%m%d%H}z.nc'.format(dts[i].astype(datetime))
    print(ncFileName)

    for res in ress:
        for mode in modes:
            #print('\t'+res+mode)
            srcNCPath = inpPath + res + mode + '/' + ncFileName

            NCF = ncField.ncField('RHO', srcNCPath, ssI)
            NCF.loadValues()
            rho = NCF.vals

            NCF = ncField.ncField('QV', srcNCPath, ssI)
            NCF.loadValues()
            qv = NCF.vals

            wvm = rho * qv

            WVMncf = NCF.copy()
            WVMncf.fieldName = 'WV_mass'
            WVMncf.vals = wvm
            WVMncf.addVarToExistingNC(srcNCPath)
Exemplo n.º 15
0
        for var in vars:
            out[var] = np.full(len(dts), np.nan)
        out['Mtot'] = np.full(len(dts), np.nan)
        out['time'] = dts
        out['alts'] = alts
        out['domainName'] = domainName

        for tCount in range(0, len(dts)):
            ncFileName = 'lffd{0:%Y%m%d%H}z.nc'.format(
                dts[tCount].astype(datetime))
            if tCount % 24 == 0:
                print('\t\t' + ncFileName)

            srcNCPath = inpPath + res + mode + '/' + ncFileName

            RHOncf = ncField.ncField('RHO', srcNCPath, ssI[res])
            RHOncf.loadValues()
            rho = RHOncf.vals
            rhou = unstaggerZ_4D(rho)

            nt, nzs, ny, nx = rho.shape

            # TOTAL MASS
            Mtot = 0
            for i in range(0, nx):
                for j in range(0, ny):
                    Mtot = Mtot + np.nansum(rhou[0, :, j, i] * dz * A)
            out['Mtot'][tCount] = Mtot

            # CALCULATE TENDENCIES
            for var in vars:
Exemplo n.º 16
0
for hr in hours:
    print(hr)
    #hr = 12
    dts = list()
    for day in days:
        dts.append(datetime(2006, 7, day, hr))

    MFsum = 0
    #MFsumSlab = 0
    for dt in dts:
        #print(dt)
        ncFileName = 'lffd{0:%Y%m%d%H}z.nc'.format(dt)
        srcNCPath = inpPath + res + mode + '/' + ncFileName

        # LOAD RHO
        RHOncf = ncField.ncField('RHO', srcNCPath, ssI[res])
        RHOncf.loadValues()
        rho = RHOncf.vals

        #srcNCPath = inpPathNoTopocut + res + mode + '/' + ncFileName
        NCF = ncField.ncField(var, srcNCPath, ssI[res])
        NCF.loadValues()
        vals = NCF.vals

        MF = np.nansum(vals * rho * 100 * A)
        #MF = np.nanmean(vals)
        MFsum = MFsum + MF
        #print(MF)

        ## slabs
        #ncf = ncField.ncField('W', srcNCPath, ssI[res])
Exemplo n.º 17
0
        out = {}
        out['Fqv'] = np.full(len(dts), np.nan)
        out['time'] = dts
        out['alts'] = alts
        #out['altsu'] = altsu
        out['domainName'] = domainName

        for tCount in range(0, len(dts)):
            ncFileName = 'lffd{0:%Y%m%d%H}z.nc'.format(
                dts[tCount].astype(datetime))
            if tCount % 24 == 0:
                print('\t\t' + ncFileName)

            srcNCPath = inpPath + res + mode + '/' + ncFileName

            RHOncf = ncField.ncField('RHO', srcNCPath, ssI[res])
            RHOncf.loadValues()
            rho = RHOncf.vals
            Wncf = ncField.ncField('W', srcNCPath, ssI[res])
            Wncf.loadValues()
            w = Wncf.vals
            QVncf = ncField.ncField('QV', srcNCPath, ssI[res])
            QVncf.loadValues()
            qv = QVncf.vals

            nt, nz, ny, nx = rho.shape
            A = np.power(dx, 2)

            Fqv = A * w * qv * rho
            sumFqv = np.nansum(Fqv)
            #print(sumFqv/1000)
Exemplo n.º 18
0
dt0 = datetime(2006, 7, 11, 0)
dt1 = datetime(2006, 7, 20, 1)
dts = np.arange(dt0, dt1, timedelta(hours=1))
inpPath = '../01_rawData/topocut/'

for i in range(0, len(dts)):
    ncFileName = 'lffd{0:%Y%m%d%H}z.nc'.format(dts[i].astype(datetime))
    print(ncFileName)

    for res in ress:
        for mode in modes:
            #print('\t'+res+mode)
            srcNCPath = inpPath + res + mode + '/' + ncFileName

            RHOncf = ncField.ncField('RHO', srcNCPath, ssI)
            RHOncf.loadValues()
            rho = RHOncf.vals
            Uncf = ncField.ncField('U', srcNCPath, ssI)
            Uncf.loadValues()
            u = Uncf.vals
            Vncf = ncField.ncField('V', srcNCPath, ssI)
            Vncf.loadValues()
            v = Vncf.vals

            uv = np.sqrt(np.power(u, 2) + np.power(v, 2))
            MFL = uv * rho

            MFLncf = RHOncf.copy()
            MFLncf.fieldName = 'MFL'
            MFLncf.vals = MFL
Exemplo n.º 19
0
dt0 = datetime(2006, 7, 20, 0)
dt1 = datetime(2006, 7, 20, 1)
dts = np.arange(dt0, dt1, timedelta(hours=1))
inpPath = '../01_rawData/topocut/'

for i in range(0, len(dts)):
    ncFileName = 'lffd{0:%Y%m%d%H}z.nc'.format(dts[i].astype(datetime))
    print(ncFileName)

    for res in ress:
        for mode in modes:
            #print('\t'+res+mode)
            srcNCPath = inpPath + res + mode + '/' + ncFileName

            QVncf = ncField.ncField('QV', srcNCPath, ssI)
            QVncf.loadValues()
            Pncf = ncField.ncField('P', srcNCPath, ssI)
            Pncf.loadValues()
            Tncf = ncField.ncField('T', srcNCPath, ssI)
            Tncf.loadValues()

            RHncf = QVncf.copy()
            RHncf.fieldName = 'RH'

            qv = QVncf.vals
            p = Pncf.vals
            T = Tncf.vals
            TC = T - 273.15

            eps = 0.622