def surplus_pool_dictionary(nerc_region, surplus_pool_trade_in, trade_matrix, gen_quantity, eGRID_region, nerc_region2): surplus_dict = dict() for i in range(0, len(nerc_region2)): region = nerc_region2[i][0].value exchanges_list = [] exchange(ref_exchange_creator(), exchanges_list) #y = len(trade_matrix[0]) #chk=0; for j in range(0, 34): input_region_surplus_amount = trade_matrix[i + 1][j].value if input_region_surplus_amount != None and input_region_surplus_amount != 0: #name = 'Electricity; at region '+trade_matrix[0][j].value+'; Trade Mix' input_region_acronym = trade_matrix[0][j].value exchange( exchange_table_creation_input_con_mix( input_region_surplus_amount, input_region_acronym), exchanges_list) #exchange(exchange_table_creation_input_con_mix(trade_matrix[i+1][j].value,trade_matrix[0][j].value),exchanges_list) #chk = 1; final = process_table_creation_surplus(region, exchanges_list) print(region + ' NERC Surplus Process Created') surplus_dict['SurplusPool' + region] = final return surplus_dict
def distribution_mix_dictionary(): distribution_dict = dict() for reg in egrid_subregions: exchanges_list = [] exchange(ref_exchange_creator(electricity_at_user_flow), exchanges_list) exchange( exchange_table_creation_input_con_mix( 1 / model_specs.efficiency_of_distribution_grid, reg, ref_to_consumption=True), exchanges_list) final = process_table_creation_distribution(reg, exchanges_list) distribution_dict['Distribution' + reg] = final return distribution_dict
def consumption_mix_dictionary(nerc_region, surplus_pool_trade_in, trade_matrix, generation_quantity, egrid_regions, nerc_region2): surplus_dict = surplus_pool_dictionary(nerc_region, surplus_pool_trade_in, trade_matrix, generation_quantity, egrid_regions, nerc_region2) #global region consumption_dict = dict() for reg in range(0, len(egrid_regions)): region = egrid_regions[reg][0].value exchanges_list = [] exchange(ref_exchange_creator(), exchanges_list) y = len(trade_matrix[0]) chk = 0 for nerc in range(0, len(nerc_region2)): if nerc_region[reg][0].value == nerc_region2[nerc][0].value: if surplus_pool_trade_in[reg][0].value != 0: for j in range(0, y): #name = surplus_dict[nerc_region[reg][0].value]['name'] if trade_matrix[nerc + 1][j].value != None and trade_matrix[ nerc + 1][j].value != 0: print(nerc_region[reg][0].value) exchange( exchange_table_creation_input_con_mix( surplus_pool_trade_in[reg][0].value, nerc_region[reg][0].value), exchanges_list) chk = 1 break #name = 'Electricity from generation mix '+eGRID_region[reg][0].value #fuelname = if chk == 1: exchange( exchange_table_creation_input_con_mix( generation_quantity[reg][0].value, region), exchanges_list) else: exchange(exchange_table_creation_input_con_mix(1, region), exchanges_list) final = process_table_creation_con_mix(region, exchanges_list) print(region + ' Consumption Mix Process Created') consumption_dict['Consumption' + region] = final return consumption_dict
def olca_schema_distribution_mix(td_by_region, cons_mix_dict, subregion="BA"): from electricitylci.process_dictionary_writer import ( exchange_table_creation_ref, exchange, ref_exchange_creator, electricity_at_user_flow, electricity_at_grid_flow, process_table_creation_distribution, ) distribution_mix_dict = {} if subregion == "all": aggregation_column = "Subregion" region = list(pd.unique(td_by_region[aggregation_column])) elif subregion == "NERC": aggregation_column = "NERC" region = list(pd.unique(td_by_region[aggregation_column])) elif subregion == "BA": aggregation_column = "Balancing Authority Name" region = list(pd.unique(td_by_region[aggregation_column])) elif subregion == "FERC": aggregation_column = "FERC_Region" region = list(pd.unique(td_by_region[aggregation_column])) else: aggregation_column = None region = ["US"] for reg in region: if aggregation_column is None: database_reg = td_by_region else: database_reg = td_by_region.loc[td_by_region[aggregation_column] == reg, :] exchanges_list = [] # Creating the reference output exchange( ref_exchange_creator(electricity_flow=electricity_at_user_flow), exchanges_list, ) exchange( ref_exchange_creator(electricity_flow=electricity_at_grid_flow), exchanges_list, ) exchanges_list[1]["input"] = True exchanges_list[1]["quantitativeReference"] = False exchanges_list[1]["amount"] = 1 + database_reg["t_d_losses"].values[0] matching_dict = None for cons_mix in cons_mix_dict: if (cons_mix_dict[cons_mix]["name"] == "Electricity; at grid; consumption mix - " + reg): matching_dict = cons_mix_dict[cons_mix] break if matching_dict is None: logging.warning(f"Trouble matching dictionary for {reg}") else: exchanges_list[1]["provider"] = { "name": matching_dict["name"], "@id": matching_dict["uuid"], "category": matching_dict["category"].split("/"), } # Writing final file final = process_table_creation_distribution(reg, exchanges_list) final["name"] = "Electricity; at user; consumption mix - " + reg distribution_mix_dict[reg] = final return distribution_mix_dict
def olca_schema_consumption_mix(database, gen_dict, subregion="BA"): import numpy as np import pandas as pd from electricitylci.generation import eia_facility_fuel_region from electricitylci.globals import data_dir, output_dir from electricitylci.process_dictionary_writer import ( exchange_table_creation_ref, exchange, ref_exchange_creator, electricity_at_user_flow, electricity_at_grid_flow, process_table_creation_con_mix, exchange_table_creation_input_con_mix ) import logging # DELETE NEXT LINE # database = cons_mix_df # database = database.drop(columns = ['value', 'total']) # dist_dict = dist_mix_dict # DELETE ABOVE consumption_mix_dict = {} if subregion == "FERC": aggregation_column = "import ferc region" region = list(pd.unique(database[aggregation_column])) export_column = 'export_name' elif subregion == "BA": aggregation_column = "import_name" # "import BAA" region = list(pd.unique(database[aggregation_column])) export_column = "export_name" # 'export BAA' elif subregion == "US": export_column = "export_name" region=["US"] for reg in region: if subregion =="US": database_reg = database else: database_reg = database.loc[database[aggregation_column] == reg, :] exchanges_list = [] database_filt = database['fraction'] > 0 database_reg = database_reg[database_filt] exchange(exchange_table_creation_ref_cons(database_reg), exchanges_list) for export_region in list(database_reg[export_column].unique()): database_f1 = database_reg[ database_reg[export_column] == export_region ] if database_f1.empty != True: ra = exchange_table_creation_input_con_mix( database_f1, export_region ) ra["quantitativeReference"] = False ra['amount'] = database_reg.loc[database_reg[export_column] == export_region,'fraction'].values[0] matching_dict = None for gen in gen_dict: if ( gen_dict[gen]["name"] == 'Electricity; at grid; generation mix - ' + export_region ): matching_dict = gen_dict[export_region] break if matching_dict is None: logging.warning( f"Trouble matching dictionary for {export_region} - {reg}" ) else: ra["provider"] = { "name": matching_dict["name"], "@id": matching_dict["uuid"], "category": matching_dict["category"].split("/"), } exchange(ra, exchanges_list) # Writing final file final = process_table_creation_con_mix(reg, exchanges_list) final["name"] = f"Electricity; at grid; consumption mix - {reg} - {subregion}" consumption_mix_dict[f"{reg} - {subregion}"] = final return consumption_mix_dict