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 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 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 turn_data_to_dict(data, upstream_dict): module_logger.debug( f"Turning flows from {data.name} into dictionaries") cols_for_exchange_dict = [ "internalId", "@type", "avoidedProduct", "flow", "flowProperty", "input", "quantitativeReference", "baseUncertainty", "provider", "amount", "amountFormula", "unit", "pedigreeUncertainty", "dqEntry", "uncertainty", "comment", ] year = ",".join(data["Year"].astype(str).unique()) datasources = ",".join(data["source_string"].astype(str).unique()) data["Maximum"] = data["uncertaintyMax"] data["Minimum"] = data["uncertaintyMin"] data["uncertainty"] = "" data["internalId"] = "" data["@type"] = "Exchange" data["avoidedProduct"] = False data["flowProperty"] = "" data["input"] = False input_filter = ( (data["Compartment"].str.lower().str.contains("input")) | (data["Compartment"].str.lower().str.contains("resource")) | (data["Compartment"].str.lower().str.contains("technosphere"))) data.loc[input_filter, "input"] = True data["baseUncertainty"] = "" data["provider"] = "" data["unit"] = data["Unit"] # data["ElementaryFlowPrimeContext"] = data["Compartment"] # default_unit = unit("kg") # data["unit"] = [default_unit] * len(data) data["FlowType"] = "ELEMENTARY_FLOW" product_filter = ( (data["Compartment"].str.lower().str.contains("technosphere")) | (data["Compartment"].str.lower().str.contains("valuable"))) data.loc[product_filter, "FlowType"] = "PRODUCT_FLOW" waste_filter = (( data["Compartment"].str.lower().str.contains("technosphere"))) data.loc[waste_filter, "FlowType"] = "WASTE_FLOW" data["flow"] = "" provider_filter = data["stage_code"].isin(upstream_dict.keys()) for index, row in data.loc[provider_filter, :].iterrows(): provider_dict = { "name": upstream_dict[getattr(row, "stage_code")]["name"], "categoryPath": upstream_dict[getattr(row, "stage_code")]["category"], "processType": "UNIT_PROCESS", "@id": upstream_dict[getattr(row, "stage_code")]["uuid"], } data.at[index, "provider"] = provider_dict data.at[index, "unit"] = unit(upstream_dict[getattr( row, "stage_code")]["q_reference_unit"]) data.at[index, "FlowType"] = "PRODUCT_FLOW" for index, row in data.iterrows(): data.at[index, "uncertainty"] = uncertainty_table_creation( data.loc[index:index, :]) data.at[index, "flow"] = flow_table_creation(data.loc[index:index, :]) data["amount"] = data["Emission_factor"] data["amountFormula"] = "" data["quantitativeReference"] = False data["dqEntry"] = ( "(" + str(round(data["ReliabilityScore"].iloc[0], 1)) + ";" + str(round(data["TemporalCorrelation"].iloc[0], 1)) + ";" + str(round(data["GeographicalCorrelation"].iloc[0], 1)) + ";" + str(round(data["TechnologicalCorrelation"].iloc[0], 1)) + ";" + str(round(data["DataCollection"].iloc[0], 1)) + ")") data["pedigreeUncertainty"] = "" data["comment"] = f"{datasources} - {year}" data_for_dict = data[cols_for_exchange_dict] data_for_dict = data_for_dict.append(ref_exchange_creator(), ignore_index=True) data_dict = data_for_dict.to_dict("records") return data_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