Exemple #1
0
        dimsv = ('time', 'scen', anames[i] + '_index')

    for j in range(nvars):
        avev = f.createVariable(ivars[j] + '_' + anames[i], 'f4', dimsv, fill_value = 1e20, zlib = True, complevel = 9)
        avev.units = vunits[j]
        avev.long_name = 'average ' + anames[i] + ' ' + ivars[j]

        slicer = [slice(0, n) for n in var[j].shape]
        dimslist = list(dims[j])
        dimslist.remove('scen')
        timeidx, latidx, lonidx = dimslist.index('time'), dimslist.index('lat'), dimslist.index('lon')

        for k in range(len(scensel)):
            slicer[dims[j].index('scen')] = k
            data = var[j][slicer].transpose((timeidx, latidx, lonidx))

            if yieldvar:
                yld = yieldv[slicer].transpose((timeidx, latidx, lonidx))
                yldmask = getyieldmask(yld, yieldthr1, yieldthr2)
            else:
                yldmask = None

            data = avobj.av(data, adata[i], lats, weights, calcarea = calcarea, mask = yldmask, numchunks = numchunks)

            if leaddim == 'scen':
                avev[k, :, :] = data.transpose((1, 0))
            else:
                avev[:, k, :] = data.transpose((1, 0))

f.close()
Exemple #2
0
        dimsv = ('time', 'scen', anames[i] + '_index')

    for j in range(nvars):
        avev = f.createVariable(ivars[j] + '_' + anames[i], 'f4', dimsv, fill_value = 1e20, zlib = True, complevel = 9)
        avev.units = vunits[j]
        avev.long_name = 'average ' + anames[i] + ' ' + ivars[j]

        slicer = [slice(0, n) for n in var[j].shape]
        dimslist = list(dims[j])
        dimslist.remove('scen')
        timeidx, latidx, lonidx = dimslist.index('time'), dimslist.index('lat'), dimslist.index('lon')

        for k in range(len(scensel)):
            slicer[dims[j].index('scen')] = k
            data = var[j][slicer].transpose((timeidx, latidx, lonidx))

            if yieldvar:
                yld = yieldv[slicer].transpose((timeidx, latidx, lonidx))
                yldmask = getyieldmask(yld, yieldthr1, yieldthr2)
            else:
                yldmask = None

            data = avobj.av(data, adata[i], lats, weights, calcarea = calcarea, mask = yldmask, numchunks = numchunks)

            if leaddim == 'scen':
                avev[k, :, :] = data.transpose((1, 0))
            else:
                avev[:, k, :] = data.transpose((1, 0))

f.close()
Exemple #3
0
        var[i] = v[:]
        var[i] = masked_where(isnan(var[i]), var[i])  # mask out NaNs
        var[i].mask = resize(var[i].mask,
                             var[i].shape)  # resize mask if necessary
        vunits[i] = v.units if 'units' in v.ncattrs() else ''

createAggFile(options.output, time, tunits, audata, anames, aunits, alongnames)
f = nc(options.output, 'a')  # open file for appending

if options.type == 'mean':  # averager instance
    avobj = MeanAverager()
else:
    avobj = SumAverager()

for i in range(nmasks):
    dims = (anames[i] + '_index', 'time')
    for j in range(nvars):
        avev = f.createVariable(ivars[j] + '_' + anames[i],
                                'f4',
                                dims,
                                fill_value=1e20,
                                zlib=True,
                                complevel=9)
        avev[:] = avobj.av(var[j],
                           adata[i],
                           lats,
                           weights,
                           calcarea=options.calcarea)
        avev.units = vunits[j]
        avev.long_name = ' '.join([options.type, anames[i], ivars[j]])
f.close()
Exemple #4
0
ivars = [v.strip() for v in ivars.split(',')]
nvars = len(ivars)
var = [0] * nvars; vunits = [0] * nvars
with nc(ifile) as f:
    lats = f.variables['lat'][:]
    t = f.variables['time']
    time = t[:]
    tunits = t.units if 'units' in t.ncattrs() else ''
    for i in range(nvars):
        v = f.variables[ivars[i]]
        var[i] = v[:]
        var[i] = masked_where(isnan(var[i]), var[i]) # mask out NaNs
        var[i].mask = resize(var[i].mask, var[i].shape) # resize mask if necessary
        vunits[i] = v.units if 'units' in v.ncattrs() else ''

createAggFile(options.output, time, tunits, audata, anames, aunits, alongnames)
f = nc(options.output, 'a') # open file for appending

if options.type == 'mean': # averager instance
    avobj = MeanAverager()
else:
    avobj = SumAverager()

for i in range(nmasks):
    dims = (anames[i] + '_index', 'time')
    for j in range(nvars):
        avev = f.createVariable(ivars[j] + '_' + anames[i], 'f4', dims, fill_value = 1e20, zlib = True, complevel = 9)
        avev[:] = avobj.av(var[j], adata[i], lats, weights, calcarea = options.calcarea)
        avev.units = vunits[j]
        avev.long_name = ' '.join([options.type, anames[i], ivars[j]])
f.close()