Esempio n. 1
0
 def setUp(self):
     self.N = europe_plus_Nodes()
     self.testlapse = range(200)
     self.h0_sqr = au.get_quant_caps(\
             filename='./results/Europe_aHE_copper_sqr_flows.npy')
     self.h0_lin = au.get_quant_caps(\
                     filename='./results/Europe_aHE_copper_lin_flows.npy')
 def setUp(self):
     self.N = europe_plus_Nodes()
     self.mean_loads = [n.mean for n in self.N]
     self.mode = 'linear'
     self.network_constr, self.sum_of_squared_flows_constr \
                                  = DCs.build_DC_network(self.N, b=1e3)
     self.network_copper, self.sum_of_squared_flows_copper\
                               = DCs.build_DC_network(self.N, copper=True)
     self.Nlinks = len(au.AtoKh(self.N)[-1])
     self.Nnodes = len(self.N)
     self.testtimesteps = [52094, 52095, 52096, \
                           0, 7, 50, 100, 1434, 32049, 198391]
def PhitoF(Phi, K=None):
    """ This function assumes that Phi is a single N vector,
        and is intended to convert a principal component of
        and injection pattern into a principal flow component.

        """

    assert(sum(Phi)<= 1e-8), 'Phi is not a consistent flow pattern.'
    if K!=None:
        N = europe_plus_Nodes()
        K = common_tools.AtoKh_old(N)[0]
    L = np.dot(K, K.T)
    Lplus = np.linalg.pinv(L)
    KTLplus = np.dot(K.T, Lplus)
    F = np.dot(KTLplus, Phi)

    return F
Esempio n. 4
0
def FtoPhi(F, K=None):
    """ This function takes a L x T array (time dependent flow vector)
        and converts it into an N x T array, of the corresponding
        injection pattern.

        """

    if K==None:
        N = europe_plus_Nodes()
        K = au.AtoKh_old(N)[0]

    length_of_timeseries = F.shape[1]
    Phi = np.empty((K.shape[0], length_of_timeseries))

    for t in xrange(length_of_timeseries):
        Phi[:,t] = np.dot(K, F[:,t])

    return Phi, K
Esempio n. 5
0
def solve_flow(flow_calc):
    admat = ''.join(['./settings/', flow_calc.layout, 'admat.txt'])
    filename = str(flow_calc)

    copperflow_filename = ''.join(['./results/', flow_calc.layout, '_',
        flow_calc.alphas, '_copper_', flow_calc.solvermode, '_flows.npy'])

    if flow_calc.alphas=='aHE':
        if flow_calc.basisnetwork == 'europeplus':
            nodes = europe_plus_Nodes(admat=admat)
        else:
            sys.stderr.write('The object has a basisnetwork that\
                          is not accounted for. Use "europeplus".')
    elif flow_calc.alphas.startswith('aHO'):
        alpha = float(flow_calc.alphas[3:]) # expects alphas on the form aHO0.4
        if flow_calc.basisnetwork == 'europeplus':
            nodes = europe_plus_Nodes(admat=admat, alphas=alpha)
            if flow_calc.mismatch_path != None:
                nodes = set_mismatches(nodes, flow_calc.mismatch_path)

        else:
            sys.stderr.write('The object has a basisnetwork that\
                          is not accounted for. Use "europeplus".')
    else:
        sys.stderr.write('The object has an distribution of mixes that\
                          is not accounted for.')

    mode_str_list = []
    if 'lin' in flow_calc.solvermode:
        mode_str_list.append('linear ')
    elif 'sqr' in flow_calc.solvermode:
        mode_str_list.append('square ')
    else:
        sys.stderr.write('The solver mode must be "lin", "sqr"')
    if 'imp' in flow_calc.solvermode:
        mode_str_list.append('impedance ')

    mode = ''.join(mode_str_list)

    flowfilename = ''.join(['./results/', filename, '_flows.npy'])

    if 'DC' in flow_calc.solvermode:
        solver = DCs.DC_solve
    else:
        solver = au.solve

    if flow_calc.capacities=='copper':
        solved_nodes, flows = solver(nodes, mode=''.join([mode, ' copper']),\
                                msg=str(flow_calc))
    elif flow_calc.capacities=='q99':
        h0 = au.get_quant_caps(filename=copperflow_filename)
        solved_nodes, flows = solver(nodes, h0=h0, mode=mode, \
                                         msg=str(flow_calc))
    elif flow_calc.capacities=='hq99': # corresponds to half the capacities
                                         # of the 99% quantile layout
        h0 = 0.5*au.get_quant_caps(filename=copperflow_filename)
        solved_nodes, flows = solver(nodes, h0=h0, mode=mode, \
                                        msg=str(flow_calc))
    elif flow_calc.capacities.endswith('q99'):
        scale = float(flow_calc.capacities[0:-3])
        h0 = au.get_quant_caps(filename=copperflow_filename)
        solved_nodes, flows = solver(nodes, h0=h0, b=scale, mode=mode,\
                                        msg=str(flow_calc))
    else:
        sys.stderr.write('The capacities must be either "copper", "q99",\
                            "hq99", or on the form "<number>q99"')

    if flow_calc.savemode == 'full':
        solved_nodes.save_nodes(filename)
        try:
            flows
            np.save('./results/' + filename + '_flows', flows)
        except NameError:
            print "Flows not defined."

    elif 'FCResult' in flow_calc.savemode:
        result = FCResult(filename+'.pkl')
        result.add_instance(solved_nodes, flows, flow_calc)
        result.save_results(filename+'.pkl')
        if 'flows' in flow_calc.savemode:
            try:
                flows
                np.save('./results/' + filename + '_flows', flows)
            except NameError:
                print "Flows not defined."

    else:
        print "Results not saved, invalid savemode provided"
import aurespf.solvers as au
import figutils as fig
from FlowCalculation import FlowCalculation
from europe_plusgrid import europe_plus_Nodes

layouts = ['Europe_RU', 'Europe_NA', 'Europe_ME', 'Europe_RU_NA_ME']
modes = ['lin', 'sqr']

datapath = './results/Europeplus/'

Europe = europe_plus_Nodes(admat='./settings/Europeadmat.txt')
internal_links = [au.AtoKh(Europe)[-1][i][0]\
        for i in range(len(au.AtoKh(Europe)[-1]))]

for layout in layouts:
    admat = './settings/' + layout + 'admat.txt'
    print admat
    N = europe_plus_Nodes(admat=admat)
    for mode in modes:
        fc = FlowCalculation(layout, 'aHE', 'copper', mode)
        filename = str(fc) + '.pkl'
        internal_indices, external_indices = fig.get_internal_external_link_indices(N, internal_links)
        all_TC = au.biggestpair(fig.get_data(filename, 'TC', path=datapath))
        print fc.pretty_layout(), fc.pretty_solvermode()
        for link_index in external_indices:
            print au.AtoKh(N)[-1][link_index]
            print all_TC[link_index]


 def setUp(self):
     self.N = europe_plus_Nodes()
from europe_plusgrid import europe_plus_Nodes
from FlowCalculation import FlowCalculation


for flow in ['lin', 'sqr']:
    DC_filename = 'Europe_aHE_copper_DC_' + flow + '.npz'
    F2_filename = 'Europe_aHE_copper_' + flow + '.npz'
    DC_N = europe_plus_Nodes(load_filename=DC_filename)
    F2_N = europe_plus_Nodes(load_filename=F2_filename)


 def setUp(self):
     self.N = europe_plus_Nodes()
     self.model = DCs.build_DC_network(self.N)[0]
     self.Nlinks = len(au.AtoKh(self.N)[-1])
     self.Nnodes = len(self.N)
Esempio n. 10
0
def make_europeplus_barplot(ydatalabel, interactive=False,\
        barwidth=0.5):
    """ Creates a bar plot showing the property specified by
        ydatalabel in the five different layouts in the Europeplus
        configuration.

        """

    plt.close()
    plt.rcParams['axes.color_cycle'] = color_cycle
    if interactive:
        plt.ion()
    datapath = "./results/Europeplus/"
    savepath = "./results/figures/Europeplusfigs/"
    sqr_and_lin = False
    if ydatalabel != 'BE':
        sqr_and_lin = True

    layoutlist = ['Europe',\
                 'Europe-RU', 'Europe-NA', 'Europe-ME', 'Europe-RU-NA-ME']

    ydata_lin = []
    ydata_sqr = []
    ydata_lin_ext = []
    ydata_sqr_ext = []

    for l in layoutlist:
        layout = l.replace('-', '_')
        fc_string_lin = str(FlowCalculation(layout, 'aHE', 'copper', 'lin'))
        fc_string_sqr = str(FlowCalculation(layout, 'aHE', 'copper', 'sqr'))
        admat = "./settings/" + layout + "admat.txt"
        N = europe_plus_Nodes(admat=admat)
        if layout=='Europe':
            internal_links = [au.AtoKh(N)[-1][i][0] \
                    for i in range(len(au.AtoKh(N)[-1]))]

        total_mean_load = np.sum([n.mean for n in N])
        if ydatalabel == 'BE':
            unnormalized_data = get_data(fc_string_lin + '.pkl', \
                                         ydatalabel, path=datapath)
            ydata_lin.append(np.sum(unnormalized_data)/total_mean_load)
            ylabel = "Backup energy [normalized]"
        elif ydatalabel == 'BC':
            unnormalized_data_lin = get_data(fc_string_lin + '.pkl',\
                                             ydatalabel, path=datapath)
            unnormalized_data_sqr = get_data(fc_string_sqr + '.pkl',\
                                             ydatalabel, path=datapath)
            ydata_lin.append(np.sum(unnormalized_data_lin)/total_mean_load)
            ydata_sqr.append(np.sum(unnormalized_data_sqr)/total_mean_load)
            ylabel = "Backup capacity [normalized]"
        elif ydatalabel == 'TC':
            internal_indices, external_indices =\
                    get_internal_external_link_indices(N, internal_links)
            print internal_indices, external_indices
            all_lin_TC = au.biggestpair(\
                    get_data(fc_string_lin + '.pkl', 'TC', path=datapath))
            all_sqr_TC = au.biggestpair(\
                    get_data(fc_string_sqr + '.pkl', 'TC', path=datapath))
            ydata_lin.append(\
                    sum([all_lin_TC[i] for i in internal_indices])/1e3)
            ydata_lin_ext.append(\
                    sum([all_lin_TC[i] for i in external_indices])/1e3)
            ydata_sqr.append(\
                    sum([all_sqr_TC[i] for i in internal_indices])/1e3)
            ydata_sqr_ext.append(\
                    sum([all_sqr_TC[i] for i in external_indices])/1e3)
            ylabel = "Transmission capacity [GW]" ## note the unit, this was
                                                  ## obtained by /1e3

################# implement transmission capacity that only include internal european links######

    index = np.array([0, 1.5, 2.5, 3.5, 5])
    left = index + 0.5*barwidth
    left2 = index + barwidth
    ax = plt.subplot(1,1,1)

    if ydatalabel=='BE':
        plt.bar(left, ydata_lin, width=barwidth, color=blue)
    elif ydatalabel=='BC':
        plt.bar(left, ydata_lin, width=0.5*barwidth,\
                color=blue, label = 'Localized flow')
        plt.bar(left2, ydata_sqr, width=0.5*barwidth,\
                color=red, label = 'Synchronized flow')
        plt.legend()
    elif ydatalabel=='TC':
        plt.bar(left, np.array(ydata_lin)+np.array(ydata_lin_ext), \
                width=0.5*barwidth, color=darkblue,\
                label = 'External capacity: Localized flow')
        plt.bar(left, np.array(ydata_lin), width=0.5*barwidth,\
                color=blue, label = 'Internal capacity: Localized flow')
        plt.bar(left2, np.array(ydata_sqr)+np.array(ydata_sqr_ext), \
                width=0.5*barwidth, color=darkred,\
                label = 'External capacity: Synchronized flow')
        plt.bar(left2, np.array(ydata_sqr), width=0.5*barwidth,\
                color=red, label = 'Internal capacity: Synchronized flow')
        plt.legend(prop={'size':13}, loc=2)
    plt.xticks(left + 0.5*barwidth, layoutlist)
    plt.ylabel(ylabel)
    plt.title('Copper flow')

    figfilename = ydatalabel + "vslayout.pdf"
    if not interactive:
        plt.savefig(savepath + figfilename)
Esempio n. 11
0
from europe_plusgrid import europe_plus_Nodes
import DCsolvers as DCs
import numpy as np

N = europe_plus_Nodes()

h0 = np.load('./results/EuropeCopperh0.npy')
#copperNodes, copperFlow = DCs.DC_solve(N, mode='linear copper verbose', msg="Solving copper flows")
#copperNodes.save_nodes("copperNodes.npz")
#np.save("./results/copper_flows.npy", copperFlow)

constrNodes_lin, constrFlow_lin = DCs.DC_solve(N, mode='linear verbose', msg="Solving constrained flows lin", h0=h0, b=0.05)
constrNodes_lin.save_nodes("Europe_aHE_0.05q99_lin.npz")
np.save("./results/Europe_aHE_0.5q99_lin_flows.npy", constrFlow_lin)

copperNodes_sqr, copperFlow_sqr = DCs.DC_solve(N, mode='square copper verbose', msg="Solving copper flows square")
copperNodes_sqr.save_nodes("Europe_aHE_copper_sqr.npz")
np.save("./results/Europe_aHE_copper_sqr_flows.npy", copperFlow_sqr)