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]) variables = list(set(variables)) variables.sort()
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') for j in range(nvars): avev = f.createVariable(ivars[j] + '_' + anames[i], 'f4', dimsv, fill_value = 1e20, zlib = True, complevel = 9)
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') ir = 'noirr' else:
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)): if leaddim == 'scen': dimsv = ('scen', 'time', anames[i] + '_index')