コード例 #1
0
ファイル: aggregator.py プロジェクト: yz842614503/ggcmi
        weights = weights[:, logical_and(ltime >= y1, ltime <= y2)]  # restrict range
    else:
        ltime = years.copy()

# restrict to overlapping years
yrsinrange = logical_and(years >= min(ltime), years <= max(ltime))
years = years[yrsinrange]
t0 = min(years) - y1 + 1
time = arange(t0, t0 + len(years))

# load aggregation mask
afile, avar = [a.strip() for a in agg.split(':')]
aggloader = AggMaskLoader(afile, avar)
adata = aggloader.data()[0]
audata = aggloader.udata()[0]
aname = aggloader.names()[0]
aunits = aggloader.units()[0]
alongname = aggloader.longnames()[0]

# load growing season file
with Dataset(gsfile) as f:
    pdate = f.variables['planting_day'][:]
    hdate = f.variables['growing_season_length'][:]

# get variables and scenarios
variables = []

for i in range(len(files)):
    file_split = files[i].split('_')
    variables.append(file_split[3])
コード例 #2
0
ファイル: agg.out.py プロジェクト: RDCEP/ggcmi
        if hasscen: slicer[yieldv.dimensions.index('scen')] = scenidx
        yieldv = yieldv[slicer]

iridx, rfidx = irr.index('ir'), irr.index('rf')

if weightsf:
    with nc(weightsf) as f:
        rfweights = f.variables['rainfed'][:]
        irweights = f.variables['irrigated'][:]
else:
    rfweights = irweights = None

aggloader  = AggMaskLoader(aggf, lats = lats, lons = lons)
adata      = aggloader.data()
audata     = aggloader.udata()
anames     = aggloader.names()
aunits     = aggloader.units()
alongnames = aggloader.longnames()

createAggFile(outputf, time, tunits, audata, anames, aunits, alongnames, scensel, irr, leaddim, hasscen)
f = nc(outputf, 'a')

avobj = MeanAverager()
for i in range(len(audata)):
    if leaddim == 'scen':
        dimsv = ('scen', 'time', anames[i], 'irr')
    elif hasscen:
        dimsv = ('time', 'scen', anames[i], 'irr')
    else:
        dimsv = ('time', anames[i], 'irr')
コード例 #3
0
ファイル: aggregator.py プロジェクト: RDCEP/ggcmi
        weights = weights[:, logical_and(ltime >= y1, ltime <= y2)] # restrict range
    else:
        ltime = years.copy()

# restrict to overlapping years
yrsinrange = logical_and(years >= min(ltime), years <= max(ltime))
years      = years[yrsinrange]
t0         = min(years) - y1 + 1
time       = arange(t0, t0 + len(years))

# load aggregation mask
afile, avar = [a.strip() for a in agg.split(':')]
aggloader   = AggMaskLoader(afile, avar)
adata       = aggloader.data()[0]
audata      = aggloader.udata()[0]
aname       = aggloader.names()[0]
aunits      = aggloader.units()[0]
alongname   = aggloader.longnames()[0]

# load growing season file
with nc(gsfile) as f:
    pdate = f.variables['planting_day'][:]
    hdate = f.variables['growing_season_length'][:]

# get variables and scenarios
variables = []; scens = []; scens_full = []
for i in range(len(files)):
    fs = files[i].split('_')

    if 'noirr' in fs:
        fs.remove('noirr')
コード例 #4
0
        wlats, wlons = f.variables['lat'][:], f.variables['lon'][:]
        sellat = logical_and(wlats >= llat - tol, wlats <= ulat + tol)
        sellon = logical_and(wlons >= llon - tol, wlons <= ulon + tol)
        wlats, wlons = wlats[sellat], wlons[sellon]        

        if abs(lats - wlats).max() > tol:
            raise Exception('Latitudes in output file and weights mask do not agree!')
        if abs(lons - wlons).max() > tol:
            raise Exception('Longitudes in output file and weights mask do not agree!')

        weights = f.variables['weights'][sellat][:, sellon]

aggloader  = AggMaskLoader(aggf, lats = lats, lons = lons)
adata      = aggloader.data()
audata     = aggloader.udata()
anames     = aggloader.names()
aunits     = aggloader.units()
alongnames = aggloader.longnames()
alats      = aggloader.latitudes()
alons      = aggloader.longitudes()

if abs(lats - alats).max() > tol:
    raise Exception('Latitudes in output file and aggregation mask do not agree!')
if abs(lons - alons).max() > tol:
    raise Exception('Longitudes in output file and aggregation mask do not agree!')

createAggFile(outputf, time, tunits, audata, anames, aunits, alongnames, scensel, leaddim)
f = nc(outputf, 'a')

avobj = MeanAverager()
for i in range(len(audata)):