Ejemplo n.º 1
0
with nc(files[0]) as f:
    lats, lons = f.variables['lat'][:], f.variables['lon'][:]
    irr = f.variables['irr'].long_name.split(', ')
    vunits = f.variables[vname].units
    vlname = f.variables[vname].long_name

sh = (len(time), len(lats), len(lons), len(irr))
yld = masked_array(zeros(sh), mask=ones(sh))

for i in range(nuniq):
    with nc(files[i]) as f:
        timef = f.variables['time'][:]
        timef += int(findall(r'\d+', f.variables['time'].units)[0])
        yldf = f.variables[vname][:]  # yield(time, lat, lon, irr)

    tmin = max(time.min(), timef.min())
    tmax = min(time.max(), timef.max())
    tidx = logical_and(time >= tmin, time <= tmax)
    tidxf = logical_and(timef >= tmin, timef <= tmax)
    print "NC file %s" % files[i]

    for j in range(len(uaggs[i])):
        print "Using country %s" % uaggs[i][j]
        latidx, lonidx = where(aggmap == uaggs[i][j])
        ytmp = yld[:, latidx, lonidx, :].copy()
        ytmp[tidx] = yldf[:, latidx, lonidx, :][tidxf]
        yld[:, latidx, lonidx, :] = ytmp

fout = RescaledFile(outfile, time, lats, lons, irr)
fout.append(vname, yld, ('time', 'lat', 'lon', 'irr'), vunits, vlname)
Ejemplo n.º 2
0
    if len(var) != len(ftime):  # happens with epic-test
        ftime = f.variables['time'][:] + int(
            findall(r'\d+', f.variables['time'].units)[0]) - 1

    varr[:, :, :, 0] = var[logical_and(ftime >= time[0], ftime <= time[-1])]

if isfile(rffile):
    with nc(rffile) as f:
        varr[:, :, :,
             1] = f.variables[vname][logical_and(ftime >= time[0],
                                                 ftime <= time[-1])]

varr[isnan(varr)] = 0.

for i in range(len(aggs)):
    latidx, lonidx = where(aggmap == aggs[i])
    aidx1 = where(ain == aggs[i])[0][0]
    aidx2 = where(aref == aggs[i])[0][0]
    for j in range(len(latidx)):
        varr[:, latidx[j], lonidx[j],
             0] *= yield_ref[aidx2, :] / yield_in[aidx1, :]
        varr[:, latidx[j], lonidx[j],
             1] *= yield_ref[aidx2, :] / yield_in[aidx1, :]

varr[:, :, :,
     2] = (areair * varr[:, :, :, 0] + arearf * varr[:, :, :, 1]) / areatot

fout = RescaledFile(outfile, time, lat, lon, ['ir', 'rf', 'sum'])
fout.append(vname, varr, ('time', 'lat', 'lon', 'irr'), units, lname)
Ejemplo n.º 3
0
    irr = f.variables['irr'].long_name.split(', ')

    vunits = f.variables[vname].units
    vlname = f.variables[vname].long_name

sh = (len(time), len(lats), len(lons), len(irr))
yld = masked_array(zeros(sh), mask = ones(sh))

for i in range(nuniq):
    with nc(files[i]) as f:
        timef  = f.variables['time'][:]
        timef += int(findall(r'\d+', f.variables['time'].units)[0])

        yldf = f.variables[vname][:] # yield(time, lat, lon, irr)

    tmin = max(time.min(), timef.min())
    tmax = min(time.max(), timef.max())

    tidx  = logical_and(time  >= tmin, time  <= tmax)
    tidxf = logical_and(timef >= tmin, timef <= tmax)

    for j in range(len(uaggs[i])):
        latidx, lonidx = where(aggmap == uaggs[i][j])

        ytmp       = yld[:,  latidx, lonidx, :].copy()
        ytmp[tidx] = yldf[:, latidx, lonidx, :][tidxf]

        yld[:, latidx, lonidx, :] = ytmp

fout = RescaledFile(outfile, time, lats, lons, irr)
fout.append(vname, yld, ('time', 'lat', 'lon', 'irr'), vunits, vlname)
Ejemplo n.º 4
0
with nc(irfile) as f:
    var = f.variables[vname]

    units = var.units     if 'units'     in var.ncattrs() else ''
    lname = var.long_name if 'long_name' in var.ncattrs() else ''

    if len(var) != len(ftime): # happens with epic-test
        ftime = f.variables['time'][:] + int(findall(r'\d+', f.variables['time'].units)[0]) - 1

    varr[:, :, :, 0] = var[logical_and(ftime >= time[0], ftime <= time[-1])]

if isfile(rffile):
    with nc(rffile) as f:
        varr[:, :, :, 1] = f.variables[vname][logical_and(ftime >= time[0], ftime <= time[-1])]

varr[isnan(varr)] = 0.

for i in range(len(aggs)):
    latidx, lonidx = where(aggmap == aggs[i])
    aidx1 = where(ain  == aggs[i])[0][0]
    aidx2 = where(aref == aggs[i])[0][0]
    for j in range(len(latidx)):
        varr[:, latidx[j], lonidx[j], 0] *= yield_ref[aidx2, :] / yield_in[aidx1, :]
        varr[:, latidx[j], lonidx[j], 1] *= yield_ref[aidx2, :] / yield_in[aidx1, :]

varr[:, :, :, 2] = (areair * varr[:, :, :, 0] + arearf * varr[:, :, :, 1]) / areatot

fout = RescaledFile(outfile, time, lat, lon, ['ir', 'rf', 'sum'])
fout.append(vname, varr, ('time', 'lat', 'lon', 'irr'), units, lname)