def add_instance(self, N, F, FC): inst={} inst['alphas'] = [n.alpha for n in N] inst['gammas'] = [n.gamma for n in N] length_of_timeseries = len(N[0].balancing) # save data, that requires a Flowcalculation object for specification inst['FlowCalculation'] = FC if FC.capacities!='zerotrans': inst['BE'] = [np.sum(n.balancing)/\ length_of_timeseries for n in N] inst['BC'] = [au.get_q(n.balancing, 0.99) for n in N] # Save flow histograms of all the flow along the links flow_histograms = [] for link in xrange(F.shape[0]): flow, count = myhist(F[link], bins=200) flow_histograms.append(np.array([flow, count])) inst['flowhists'] = flow_histograms if FC.hourly_flowhist: # flow histograms, of flow along the links, conditioned # on the hour. hourly_flow_histograms = [] for link in xrange(F.shape[0]): hour_hist_list = [] for hour in range(24): hour_indices = [i for i in xrange(F.shape[1]) \ if np.mod(i, 24)==hour] hour_flows = F[link][hour_indices] flow, count = myhist(hour_flows, bins=200) hour_hist_list.append(np.array([flow, count])) hourly_flow_histograms.append(hour_hist_list) inst['hourly_flowhists'] = hourly_flow_histograms if FC.capacities[-3:len(FC.capacities)] == "q99": inst['Total_TC'] = TC_from_FC(FC)[0] inst['TC'] = TC_from_FC(FC)[1] elif FC.capacities == 'copper': h0 = au.get_quant_caps(F=F) inst['TC'] = h0 inst['Total_TC'] = np.sum(au.biggestpair(h0)) else: # that is if this is a zero transmission case inst['Total_TC'] = 0 balancing_timeseries = [] for n in N: balancing_timeseries.append(-au.get_negative(n.mismatch)) inst['BE'] = [np.sum(bal)/length_of_timeseries\ for bal in balancing_timeseries] inst['BC'] = [au.get_q(bal, 0.99) for bal in balancing_timeseries] self.cache.append(inst)
def BC_vs_region_data(): linNodes = world_Nodes(load_filename="w_aHE_copper_lin.npz") BC99_lin = [] labels = [] for n in linNodes: BC99_lin.append(au.get_q(n.balancing, 0.99)/n.mean) labels.append(str(n.label)) sqrNodes = world_Nodes(load_filename="w_aHE_copper_sqr.npz") BC99_sqr = au.get_q(sqrNodes[4].balancing, 0.99)/sqrNodes[4].mean np.savez('./results/w_BC_regions.npz', BClin = BC99_lin, labels = labels, BCsqr = BC99_sqr)
def get_zerotrans_data(alpha, ydatalabel, fc): """ If ydatalabel is 'BE' it returns the normalized total backup energy in the layout specified in the Flowcalculation object fc, in a homogenous mixing layout with mixing alpha. If 'BC' the backup capacity is retured. """ admat = "./settings/" + fc.layout + "admat.txt" N = nh_Nodes(admat=admat, alphas=alpha) total_mean_load = np.sum([n.mean for n in N]) length_of_timeseries = len(N[0].mismatch) for n in N: n.balancing = -au.get_negative(n.mismatch) if ydatalabel=='BE': result = np.sum([np.sum(n.balancing) for n in N])\ /(length_of_timeseries*total_mean_load) elif ydatalabel=='BC': result = np.sum([au.get_q(n.balancing, 0.99) for n in N])\ /total_mean_load else: print "ydatalabel must be 'BE' or 'BC'" return return result
def bal_vs_cap_data(): number_of_nodes = 8 length_of_timeseries = 280512 hours_per_year = length_of_timeseries/32 modes = ['lin', 'sqr'] scalefactors = np.linspace(0, 2, 41) #scalefactors = [0.1, 1.45] for mode in modes: balancing_energy = [] # this is for saving the balancing energy total_capacity = [] max_balancing = [] # this is for saving the balancing capacity balancing_caps99 = [] # this is for saving the balancing capacity, # found as the 99% quantile of the balancing # energy if mode == 'lin': h0 = au.get_quant_caps(filename=\ './results/w_aHE_copper_lin_flows.npy') if mode == 'sqr': h0 = au.get_quant_caps(filename=\ './results/w_aHE_copper_sqr_flows.npy') total_caps_q99 = np.sum(au.biggestpair(h0)) print total_caps_q99 for a in scalefactors: flow_calc = fc.FlowCalculation('w', 'aHE', ''.join([str(a), 'q99']), mode) filename = ''.join([str(flow_calc), '.npz']) nodes = world_Nodes(load_filename = filename) total_balancing_power = sum([sum(n.balancing) for n in nodes]) total_mean_load = np.sum([n.mean for n in nodes]) normalized_BE = total_balancing_power/\ (length_of_timeseries*total_mean_load) balancing_energy.append(normalized_BE) max_balancing.append(np.sum(np.max(n.balancing) for n in nodes)\ /total_mean_load) balancing_caps99.append(np.sum(au.get_q(n.balancing,0.99) for n in nodes)/total_mean_load) total_capacity.append(a*total_caps_q99) if mode == 'lin': TC_lin = total_capacity BE_lin = balancing_energy BC_lin = max_balancing BC99_lin = balancing_caps99 if mode == 'sqr': TC_sqr = total_capacity BE_sqr = balancing_energy BC_sqr = max_balancing BC99_sqr = balancing_caps99 np.savez('./results/w_bal_vs_cap_data99.npz', TC_lin=TC_lin,\ BE_lin=BE_lin, BC_lin=BC_lin, BC99_lin=BC99_lin,\ TC_sqr=TC_sqr, BE_sqr=BE_sqr, BC_sqr=BC_sqr, BC99_sqr=BC99_sqr)
def extract_BC_vs_TC_data(solvermode, TCscalefactors, savefilename=None): """ This function returns the a dataset with total balancing capacity (normalized to the total mean load) of the world along with the total transmission capacity of the world. The balancing capacity found as the maximum balancing over a timeseries, as well as the 99% quantile is returned. """ h0 = au.get_quant_caps(filename =\ ''.join(['./results/w_aHE_copper_', solvermode, '_flows.npy'])) total_TC_q99 = np.sum(au.biggestpair(h0)) BC_max = [] BC_q99 = [] TC = [] for a in TCscalefactors: flow_calc = fc.FlowCalculation('w', 'aHE',\ ''.join([str(a), 'q99']), solvermode) filename = ''.join([str(flow_calc), '.npz']) nodes = world_Nodes(load_filename = filename) total_mean_load = np.sum([n.mean for n in nodes]) BC_max.append(np.sum(np.max(n.balancing) for n in nodes)\ /total_mean_load) BC_q99.append(np.sum(au.get_q(n.balancing, 0.99) for n in nodes)\ /total_mean_load) TC.append(a*total_TC_q99) if not savefilename: savefilename = ''.join(['./results/BC_TC_data', solvermode, '.npz']) np.savez(savefilename, TC=TC, BC_max=BC_max, BC_q99=BC_q99)
BE = [] BC = [] BC_sqr = [] TC = [] TC_sqr = [] layouts = ['EU_RU_NA_ME', 'US_EU_RU_NA_ME', 'eurasia', 'US_eurasia_closed'] flowcalcs = [FlowCalculation(layout, 'aHE', '1.5q99', 'lin')\ for layout in layouts] print [str(fc) for fc in flowcalcs] N = nh_Nodes() EU = N[0] EU_bal = -au.get_negative(EU.mismatch) EU_BE = np.sum(EU_bal)/(EU.mean*len(EU.mismatch)) BE.append(EU_BE) EU_BC = au.get_q(EU_bal, 0.99)/EU.mean BC.append(EU_BC) TC.append(1e-8) TC_sqr.append(1e-8) for fc in flowcalcs: fc_sqr = FlowCalculation(fc.layout, 'aHE', '1.5q99', 'sqr') print fc.layout admat = "./settings/" + fc.layout + "admat.txt" N = nh_Nodes(admat=admat) total_mean_load = np.sum([n.mean for n in N]) print total_mean_load filename = str(fc) + '.pkl' filename_sqr = str(fc_sqr) + '.pkl' flowfilename = './results/' + fc.layout + '_aHE_copper_lin_flows.npy'