Exemplo n.º 1
0
        ltime = f.variables['time'][:]
        ltunits = f.variables['time'].units
        ltime += int(findall(r'\d+', ltunits)[0])
        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)):
Exemplo n.º 2
0
weights = None
if weightsf:
    with nc(weightsf) as f:
        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')