|
5 | 5 |
|
6 | 6 | @author: jamiesom
|
7 | 7 | """
|
| 8 | +############################################################################## |
| 9 | +# REQUIRED MODULES |
| 10 | +############################################################################## |
8 | 11 | import pandas as pd
|
9 | 12 |
|
10 | 13 | from electricitylci.globals import data_dir
|
11 | 14 | from electricitylci.eia860_facilities import eia860_generator_info
|
12 | 15 |
|
13 | 16 |
|
| 17 | +############################################################################## |
| 18 | +# FUNCTIONS |
| 19 | +############################################################################## |
14 | 20 | def generate_power_plant_construction(year):
|
15 | 21 | """
|
16 | 22 | Function uses an NETL study.
|
@@ -74,44 +80,85 @@ def generate_power_plant_construction(year):
|
74 | 80 | }
|
75 | 81 | gas_prime = ["GT","IC","OT","CT","CS","CE","CA","ST"]
|
76 | 82 | coal_type = ["BIT","SUB","LIG","WC","RC"]
|
77 |
| - gen_df = gen_df.loc[gen_df["energy_source_1"].isin(energy_sources), gen_columns] |
| 83 | + |
| 84 | + gen_df = gen_df.loc[ |
| 85 | + gen_df["energy_source_1"].isin(energy_sources), gen_columns] |
78 | 86 | gen_df["plant_id"]=gen_df["plant_id"].astype(int)
|
79 |
| - groupby_cols=["plant_id","technology","energy_source_1","prime_mover"] |
80 |
| - gen_df_group = gen_df.groupby(by=groupby_cols,as_index=False)["nameplate_capacity_mw"].sum() |
81 |
| - prime_energy_combo=gen_df_group.groupby(by=["prime_mover","energy_source_1"]).size().reset_index().rename(columns={0:'count'}) |
82 |
| - prime_energy_combo["const_type"]="coal" |
83 |
| - gas_const_criteria=(prime_energy_combo["prime_mover"].isin(gas_prime))&(~prime_energy_combo["energy_source_1"].isin(coal_type)) |
84 |
| - prime_energy_combo.loc[gas_const_criteria,"const_type"]="ngcc" |
85 |
| - gen_df_group=gen_df_group.merge(prime_energy_combo[['prime_mover', 'energy_source_1', 'const_type']], |
86 |
| - on=["prime_mover","energy_source_1"], |
87 |
| - how="left") |
88 |
| - inventory = pd.read_csv(f"{data_dir}/plant_construction_inventory.csv",low_memory=False) |
89 |
| - inventory = pd.concat([inventory, inventory["Flow"].str.rsplit('/',1,expand=True)],axis=1).drop(columns=["Flow"]).rename(columns={0:"Flow",1:"Unit"}) |
90 |
| - inventory = pd.concat([inventory, inventory["Flow"].str.rsplit('/',1,expand=True)],axis=1).drop(columns=["Flow"]).rename(columns={0:"Compartment_path",1:"FlowName"}) |
91 |
| - inventory = pd.concat([inventory,inventory["Compartment_path"].str.split('/',n=1,expand=True)],axis=1).rename(columns={0:"Compartment",1:"delete"}).drop(columns="delete") |
92 |
| - scpc_inventory = inventory[['SCPC_550_MW', 'Unit', 'Compartment_path', 'FlowName','Compartment']] |
93 |
| - scpc_inventory["const_type"]="coal" |
94 |
| - scpc_inventory["stage_code"]="coal_const" |
95 |
| - scpc_inventory.rename(columns={"SCPC_550_MW":"FlowAmount"},inplace=True) |
96 |
| - scpc_inventory["FlowAmount"]=scpc_inventory["FlowAmount"]/30/550 |
97 |
| - ngcc_inventory = inventory[['NGCC_630_MW', 'Unit', 'Compartment_path', 'FlowName','Compartment']] |
98 |
| - ngcc_inventory["const_type"]="ngcc" |
99 |
| - ngcc_inventory["stage_code"]="ngcc_const" |
100 |
| - ngcc_inventory.rename(columns={"NGCC_630_MW":"FlowAmount"},inplace=True) |
| 87 | + groupby_cols=["plant_id", "technology", "energy_source_1", "prime_mover"] |
| 88 | + gen_df_group = gen_df.groupby( |
| 89 | + by=groupby_cols, as_index=False)["nameplate_capacity_mw"].sum() |
| 90 | + prime_energy_combo = gen_df_group.groupby( |
| 91 | + by=["prime_mover", "energy_source_1"]).size().reset_index().rename( |
| 92 | + columns={0: 'count'}) |
| 93 | + prime_energy_combo["const_type"] = "coal" |
| 94 | + gas_const_criteria = ( |
| 95 | + prime_energy_combo["prime_mover"].isin(gas_prime)) & ( |
| 96 | + ~prime_energy_combo["energy_source_1"].isin(coal_type)) |
| 97 | + prime_energy_combo.loc[gas_const_criteria, "const_type"] = "ngcc" |
| 98 | + gen_df_group = gen_df_group.merge( |
| 99 | + prime_energy_combo[['prime_mover', 'energy_source_1', 'const_type']], |
| 100 | + on=["prime_mover","energy_source_1"], |
| 101 | + how="left") |
| 102 | + |
| 103 | + inventory = pd.read_csv( |
| 104 | + f"{data_dir}/plant_construction_inventory.csv", low_memory=False) |
| 105 | + inventory = pd.concat( |
| 106 | + [ |
| 107 | + inventory, |
| 108 | + inventory["Flow"].str.rsplit("/", n=1, expand=True) |
| 109 | + ], |
| 110 | + axis=1 |
| 111 | + ).drop(columns=["Flow"]).rename(columns={0:"Flow", 1:"Unit"}) |
| 112 | + inventory = pd.concat( |
| 113 | + [ |
| 114 | + inventory, |
| 115 | + inventory["Flow"].str.rsplit('/', n=1, expand=True) |
| 116 | + ], |
| 117 | + axis=1 |
| 118 | + ).drop(columns=["Flow"]).rename( |
| 119 | + columns={0:"Compartment_path", 1:"FlowName"}) |
| 120 | + inventory = pd.concat( |
| 121 | + [ |
| 122 | + inventory, |
| 123 | + inventory["Compartment_path"].str.split('/', n=1, expand=True) |
| 124 | + ], |
| 125 | + axis=1 |
| 126 | + ).rename( |
| 127 | + columns={0:"Compartment", 1:"delete"}).drop(columns="delete") |
| 128 | + |
| 129 | + scpc_inventory = inventory[ |
| 130 | + ['SCPC_550_MW', 'Unit', 'Compartment_path', 'FlowName','Compartment']] |
| 131 | + scpc_inventory["const_type"] = "coal" |
| 132 | + scpc_inventory["stage_code"] = "coal_const" |
| 133 | + scpc_inventory.rename(columns={"SCPC_550_MW":"FlowAmount"}, inplace=True) |
| 134 | + scpc_inventory["FlowAmount"] = scpc_inventory["FlowAmount"]/30/550 |
| 135 | + ngcc_inventory = inventory[ |
| 136 | + ['NGCC_630_MW', 'Unit', 'Compartment_path', 'FlowName','Compartment']] |
| 137 | + ngcc_inventory["const_type"] = "ngcc" |
| 138 | + ngcc_inventory["stage_code"] = "ngcc_const" |
| 139 | + ngcc_inventory.rename(columns={"NGCC_630_MW":"FlowAmount"}, inplace=True) |
101 | 140 | ngcc_inventory["FlowAmount"] = ngcc_inventory["FlowAmount"]/30/630
|
102 | 141 | inventory = pd.concat([scpc_inventory,ngcc_inventory])
|
103 |
| - inventory["Compartment_path"]=inventory["Compartment_path"].map(compartment_mapping) |
104 |
| - inventory["input"]=False |
| 142 | + inventory["Compartment_path"] = inventory["Compartment_path"].map( |
| 143 | + compartment_mapping) |
| 144 | + inventory["input"] = False |
105 | 145 | input_list=["resource" in x for x in inventory["Compartment"]]
|
106 |
| - inventory["input"]=input_list |
| 146 | + inventory["input"] = input_list |
107 | 147 | construction_df = gen_df_group.merge(inventory,on="const_type",how="left")
|
108 |
| - construction_df["FlowAmount"]=construction_df["FlowAmount"]*construction_df["nameplate_capacity_mw"] |
109 |
| - construction_df.rename(columns={"nameplate_capacity_mw":"quantity"},inplace=True) |
110 |
| - construction_df.drop(columns=["const_type","energy_source_1","prime_mover"],inplace=True) |
| 148 | + construction_df["FlowAmount"] = construction_df["FlowAmount"] * construction_df["nameplate_capacity_mw"] |
| 149 | + construction_df.rename( |
| 150 | + columns={"nameplate_capacity_mw":"quantity"}, inplace=True) |
| 151 | + construction_df.drop( |
| 152 | + columns=["const_type","energy_source_1","prime_mover"], inplace=True) |
111 | 153 | construction_df["fuel_type"]="Construction"
|
112 |
| - construction_df["Unit"]=construction_df["Unit"].str.replace("mj","MJ", regex=False) |
| 154 | + construction_df["Unit"] = construction_df["Unit"].str.replace( |
| 155 | + "mj","MJ", regex=False) |
113 | 156 | return construction_df
|
114 | 157 |
|
| 158 | + |
| 159 | +############################################################################## |
| 160 | +# MAIN |
| 161 | +############################################################################## |
115 | 162 | if __name__ == "__main__":
|
116 | 163 | year=2016
|
117 | 164 | df = generate_power_plant_construction(year)
|
0 commit comments