Skip to content

Commit 9abafff

Browse files
committed
fix error w/ rsplit in ppc; addresses #202
1 parent 40c3862 commit 9abafff

File tree

2 files changed

+89
-30
lines changed

2 files changed

+89
-30
lines changed

electricitylci/main.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def main():
3434
upstream_df = electricitylci.get_upstream_process_df(
3535
config.model_specs.eia_gen_year)
3636
logger.info("write generation process to dict")
37+
# Where we left off. 2023-08-16; TWD
3738
upstream_dict = electricitylci.write_upstream_process_database_to_dict(
3839
upstream_df
3940
)
@@ -152,6 +153,17 @@ def main():
152153
# MAIN
153154
##############################################################################
154155
if __name__ == "__main__":
156+
# Define a logger
157+
root_logger = logging.getLogger()
158+
root_handler = logging.StreamHandler()
159+
rec_format = (
160+
"%(asctime)s.%(msecs)03d:%(levelname)s:%(name)s:%(funcName)s:"
161+
"%(message)s")
162+
formatter = logging.Formatter(rec_format, datefmt='%Y-%m-%d %H:%M:%S')
163+
root_handler.setFormatter(formatter)
164+
root_logger.addHandler(root_handler)
165+
root_logger.setLevel("INFO")
166+
155167
parser = argparse.ArgumentParser()
156168
parser.add_argument("-c", "--model_config", help="specify model configuration", default="")
157169
args=parser.parse_args()

electricitylci/power_plant_construction.py

Lines changed: 77 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@
55
66
@author: jamiesom
77
"""
8+
##############################################################################
9+
# REQUIRED MODULES
10+
##############################################################################
811
import pandas as pd
912

1013
from electricitylci.globals import data_dir
1114
from electricitylci.eia860_facilities import eia860_generator_info
1215

1316

17+
##############################################################################
18+
# FUNCTIONS
19+
##############################################################################
1420
def generate_power_plant_construction(year):
1521
"""
1622
Function uses an NETL study.
@@ -74,44 +80,85 @@ def generate_power_plant_construction(year):
7480
}
7581
gas_prime = ["GT","IC","OT","CT","CS","CE","CA","ST"]
7682
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]
7886
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)
101140
ngcc_inventory["FlowAmount"] = ngcc_inventory["FlowAmount"]/30/630
102141
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
105145
input_list=["resource" in x for x in inventory["Compartment"]]
106-
inventory["input"]=input_list
146+
inventory["input"] = input_list
107147
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)
111153
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)
113156
return construction_df
114157

158+
159+
##############################################################################
160+
# MAIN
161+
##############################################################################
115162
if __name__ == "__main__":
116163
year=2016
117164
df = generate_power_plant_construction(year)

0 commit comments

Comments
 (0)