def retrieving_max_shift():
    ref = gdx_to_df(gdx_file, 'DEM_RES_FP')
    new = gdx_to_df(gdx_file, 'demand_new_res')
    old_indexr = ref.index.names
    old_indexn = new.index.names
    ref['C'] = [zone_dict[z] for z in ref.index.get_level_values('Z')]
    new['C'] = [zone_dict[z] for z in new.index.get_level_values('Z')]
    ref.set_index('C', append=True, inplace=True)
    new.set_index('C', append=True, inplace=True)
    ref = ref.reorder_levels(['C'] + old_indexr)
    new = new.reorder_levels(['C'] + old_indexn)
    shiftedtot=0
    for i in ref.index:
        value1 = float(ref.get_value(i,'DEM_RES_FP'))
        value2 = float(new.get_value((i[0],i[1],i[2],i[3],'L'),'demand_new_res'))
        shifted = (value1-value2)
        # shifted = abs(shifted)
        # print value1,value2,shifted
        ref.set_value(i,'DEM_RES_FP',shifted)
        shiftedtot = shiftedtot + shifted
    ref.reset_index(inplace=True)
    new.reset_index(inplace=True)
    maxshift = pivot_table(ref, 'DEM_RES_FP', index=['Z'], columns=['C'], aggfunc=np.max)
    # print shiftedtot
    return maxshift
def retrieving_stor_cap_c():
    stor = gdx_to_df(gdx_file, 'p_cap_c')
    old_index = stor.index.names
    stor['C'] = [zone_dict[z] for z in stor.index.get_level_values('Z')]
    stor.set_index('C', append=True, inplace=True)
    stor = stor.reorder_levels(['C'] + old_index)
    stor = pivot_table(stor.reset_index(), 'p_cap_c', index=['Y','Z','S'], columns=['C'], aggfunc=np.sum)
    return stor
def retrieving_cap():
    cap = gdx_to_df(gdx_file, 'cap')
    old_index = cap.index.names
    cap['C'] = [zone_dict[z] for z in cap.index.get_level_values('Z')]
    cap.set_index('C', append=True, inplace=True)
    cap = cap.reorder_levels(['C'] + old_index)
    cap.reset_index(inplace=True)
    cap = pivot_table(cap, 'cap', index=['Y', 'Z', 'G'], columns=['C'], aggfunc=np.sum)
    return cap
def retrieving_edr_cost():
    costgDR = gdx_to_df(gdx_file, 'costgDR')
    old_index = costgDR.index.names
    costgDR['C'] = [zone_dict[z] for z in costgDR.index.get_level_values('Z')]
    costgDR.set_index('C', append=True, inplace=True)
    costgDR = costgDR.reorder_levels(['C'] + old_index)
    costgDR.reset_index(inplace=True)
    costgDR = pivot_table(costgDR, 'costgDR', index=['Z'], columns=['C'], aggfunc=np.sum)
    return costgDR
def retrieving_res_s():
    res_s = gdx_to_df(gdx_file, 'res_s')
    old_index = res_s.index.names
    # print old_index
    res_s['C'] = [storage[z] for z in res_s.index.get_level_values('Z')]
    res_s.set_index('C', append=True, inplace=True)
    res_s = res_s.reorder_levels(['C'] + old_index)
    for i in res_s.index:
        value = float(res_s.get_value(i,'res_s'))
        res_s.set_value(i,'res_s',value)
    res_s = pivot_table(res_s.reset_index(), 'res_s', index=['Y','R'], columns=['C'], aggfunc=np.sum)
    return res_s
def retrieving_stor_d():
    stord = gdx_to_df(gdx_file, 'p_d')
    old_index = stord.index.names
    stord['C'] = [zone_dict[z] for z in stord.index.get_level_values('Z')]
    stord.set_index('C', append=True, inplace=True)
    stord = stord.reorder_levels(['C'] + old_index)
    for i in stord.index:
        value = float(stord.get_value(i,'p_d'))*weight[i[2]-1]
        stord.set_value(i,'p_d',value)
    stord.reset_index(inplace=True)
    stord = pivot_table(stord, 'p_d', index=['Y'], columns=['C'], aggfunc=np.sum)
    return stord
def retrieving_gen():
    gen = gdx_to_df(gdx_file, 'gen')
    old_index = gen.index.names
    gen['C'] = [zone_dict[z] for z in gen.index.get_level_values('Z')]
    gen.set_index('C', append=True, inplace=True)
    gen = gen.reorder_levels(['C'] + old_index)
    for i in gen.index:
        value = float(gen.get_value(i,'gen'))*weight[i[2]-1]
        gen.set_value(i,'gen',value)
    gen.reset_index(inplace=True)
    gen = pivot_table(gen, 'gen', index=['Y', 'G'], columns=['C'], aggfunc=np.sum)
    return gen
def retrieving_res_DR():
    res_DR = gdx_to_df(gdx_file, 'res_DR')
    old_index = res_DR.index.names
    # print old_index
    res_DR['C'] = [resDR[z] for z in res_DR.index.get_level_values('Z')]
    res_DR.set_index('C', append=True, inplace=True)
    res_DR = res_DR.reorder_levels(['C'] + old_index)
    for i in res_DR.index:
        value = float(res_DR.get_value(i,'res_DR'))*weight[i[2]-1]
        res_DR.set_value(i,'res_DR',value)
    res_DR = pivot_table(res_DR.reset_index(), 'res_DR', index=['Y','R'], columns=['C'],aggfunc=np.sum)
    return res_DR
Beispiel #9
0
    def test_read_out_parameters(self):
        gdx_file = os.path.join(os.getcwd(), "tests", "test_database.gdx")
        create_test_database(gdx_file)

        df_param_s = ga.gdx_to_df(gdx_file, "Param_S")
        self.assertEqual(len(df_param_s), 10)
        self.assertEqual(sum(df_param_s["Param_S"]), 60.0)
        self.assertEqual(df_param_s.index.names, ["S"])
        self.assertEqual(df_param_s.columns, ["Param_S"])

        df_param_s_s = ga.gdx_to_df(gdx_file, "Param_S_S")
        self.assertEqual(len(df_param_s_s), 100)
        self.assertEqual(sum(df_param_s_s["Param_S_S"]), 0)
        self.assertEqual(df_param_s_s.index.names, ["S", "SS"])
        self.assertEqual(df_param_s_s.columns, ["Param_S_S"])

        df_param_s_i = ga.gdx_to_df(gdx_file, "Param_S_I")
        self.assertEqual(len(df_param_s_i), 100)
        self.assertEqual(sum(df_param_s_i["Param_S_I"]), 0)
        self.assertEqual(df_param_s_i.index.names, ["S", "I"])
        self.assertEqual(df_param_s_i.columns, ["Param_S_I"])
Beispiel #10
0
    def test_read_out_sets(self):
        gdx_file = os.path.join(os.getcwd(), "tests", "test_database.gdx")
        create_test_database(gdx_file)

        df_s = ga.gdx_to_df(gdx_file, "S")
        self.assertEqual(len(df_s), 10)

        df_subs = ga.gdx_to_df(gdx_file, "SubS")
        self.assertEqual(len(df_subs), 10)
        self.assertEqual(len(df_subs[df_subs["SubS"]]), 5)

        df_i = ga.gdx_to_df(gdx_file, "I")
        self.assertEqual(len(df_i), 10)

        df_subi = ga.gdx_to_df(gdx_file, "SubI")
        self.assertEqual(len(df_subi), 10)
        self.assertEqual(len(df_subi[df_subi["SubI"]]), 5)

        df_subsi = ga.gdx_to_df(gdx_file, "SubSI")
        self.assertEqual(len(df_subsi), 100)
        self.assertEqual(len(df_subsi[df_subsi["SubSI"]]), 25)

        df_subs_empty = ga.gdx_to_df(gdx_file, "SubSEmpty")
        self.assertEqual(len(df_subs_empty), 10)
        self.assertEqual(len(df_subs_empty[df_subs_empty["SubSEmpty"]]), 0)
def retrieving_curt():
    curt = gdx_to_df(gdx_file, 'curt')
    old_index = curt.index.names
    curt['C'] = [curtail[z] for z in curt.index.get_level_values('Z')]
    curt.set_index('C', append=True, inplace=True)
    curt = curt.reorder_levels(['C'] + old_index)
    # print curt.index.names
    for i in curt.index:
        value = float(curt.get_value(i,'curt'))*weight[i[2]-1]
        curt.set_value(i,'curt',value)
    curt.reset_index(inplace=True)
    curt = pivot_table(curt, 'curt', index=['Y'], columns=['C'], aggfunc=np.sum)
    return curt
def retrieving_demand():
    new = gdx_to_df(gdx_file, 'demand_unit')
    old_index = new.index.names
    new['C'] = [zone_dict[z] for z in new.index.get_level_values('Z')]
    new.set_index('C', append=True, inplace=True)
    new = new.reorder_levels(['C'] + old_index)
    print new.index.names
    for i in new.index:
        value = float(new.get_value(i,'demand_unit'))*weight[i[1]-1]
        new.set_value(i,'demand_unit',value)
    new.reset_index(inplace=True)
    new = pivot_table(new, 'demand_unit', index=['Z'], columns=['C'], aggfunc=np.sum)
    # print shiftedtot
    return new
from gams_addon import gdx_to_df, DomainInfo

from openpyxl.styles import Style, Border, Alignment, Protection, Font, colors


file = 'results\out_db_40_DR.gdx'
gdx_file = os.path.join(os.getcwd(), '%s' % file)
writefile = os.getcwd() + '\\' + 'excel\output_elasticity_model.xlsx'
writer = ExcelWriter(writefile)

print gdx_file
zone_dict = dict()
zone_dict['BEL_Z'] = 'BEL'

print 'Retrieving price_unit_clone'
price_unit = gdx_to_df(gdx_file, 'price_unit_clone')
old_index = price_unit.index.names
price_unit['C'] = [zone_dict[z] for z in price_unit.index.get_level_values('Z')]
price_unit.set_index('C', append=True, inplace=True)
price_unit = price_unit.reorder_levels(['C'] + old_index)
price_unit.reset_index(inplace=True)
price_unit = pivot_table(price_unit, 'price_unit_clone', index=['P', 'T','Z'], columns=['C'], aggfunc=np.sum)

print 'Retrieving demand_unit'
demand_unit = gdx_to_df(gdx_file, 'demand_unit')
old_index = demand_unit.index.names
demand_unit['C'] = [zone_dict[z] for z in demand_unit.index.get_level_values('Z')]
demand_unit.set_index('C', append=True, inplace=True)
demand_unit = demand_unit.reorder_levels(['C'] + old_index)
demand_unit.reset_index(inplace=True)
demand_unit = pivot_table(demand_unit, 'demand_unit', index=['P','T','Z'], columns=['C'], aggfunc=np.sum)