-
Notifications
You must be signed in to change notification settings - Fork 17
Add class set to model outputs #217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
640e164
92e9cc4
5c1a5e5
a7c08a5
250e101
b97a64c
8f3f31e
65735b2
d19892f
a31ff0d
701deec
d0cdb47
89f7e25
485daef
2f948ab
1bfc477
005e479
098e2a4
f5b2076
e5eff11
ea86ae1
550fbb0
56e65c2
a17e8bb
3036306
caa4fff
9860c76
d1d3c79
7ff1628
e92fd37
8a60ebf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -279,7 +279,7 @@ def get_preexisting_capacity(df_sc_in, tech, first_model_year=2009): | |
| # Find existing capacity by bin with raw supply curve. | ||
| # Consider existing capacity as investment in 2009 to use the | ||
| # same logic as inv_rsc when assigning to gid. | ||
| exist_columns = ["tech", "region", "year", "bin", "MW"] | ||
| exist_columns = ["tech", "class", "region", "year", "bin", "MW"] | ||
| if "existing_capacity" in df_sc_in: | ||
| if "online_year" not in df_sc_in: | ||
| raise KeyError( | ||
|
|
@@ -333,11 +333,9 @@ class that can be used to check capacity values at the end of disaggregation. | |
| # Get check for capacity | ||
| cap_chk = os.path.join(run_folder, "outputs", "cap.csv") | ||
| df_cap_chk = pd.read_csv( | ||
| cap_chk, low_memory=False, names=["tech", "region", "year", "MW"], header=0 | ||
| ) | ||
| df_cap_chk[["tech_cat", "class"]] = df_cap_chk["tech"].str.rsplit( | ||
| "_", n=1, expand=True | ||
| cap_chk, low_memory=False, names=["tech", "class", "region", "year", "MW"], header=0 | ||
| ) | ||
| df_cap_chk["tech_cat"] = df_cap_chk["tech"].str.rsplit("_", n=1).str[0] | ||
| df_cap_chk = df_cap_chk[df_cap_chk["tech_cat"] == tech].copy() | ||
| df_cap_chk = df_cap_chk[["year", "region", "class", "MW"]].dropna(subset=["class"]) | ||
| df_cap_chk["class"] = df_cap_chk["class"].astype("int") | ||
|
|
@@ -370,8 +368,8 @@ def get_new_investments(run_folder, tech): | |
| df_inv_rsc = pd.read_csv( | ||
| inv_rsc, | ||
| low_memory=False, | ||
| names=["tech", "vintage", "region", "year", "bin", "MW"], | ||
| usecols=["tech", "region", "year", "bin", "MW"], | ||
| names=["tech", "class", "vintage", "region", "year", "bin", "MW"], | ||
| usecols=["tech", "class", "region", "year", "bin", "MW"], | ||
| header=0, | ||
| ) | ||
| df_inv_rsc = df_inv_rsc[df_inv_rsc["tech"].str.startswith(tech)].copy() | ||
|
|
@@ -401,8 +399,6 @@ def combine_preexisting_and_new_investments(df_bin_exist, df_inv_rsc): | |
| """ | ||
| # Concatenate existing and inv_rsc | ||
| df_inv = pd.concat([df_bin_exist, df_inv_rsc], sort=False, ignore_index=True) | ||
| # Split tech from class | ||
| df_inv[["tech_cat", "class"]] = df_inv["tech"].str.rsplit("_", n=1, expand=True) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. got it, because 'class' is already part of the data upstream, right?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's right. |
||
| df_inv = df_inv[["year", "region", "class", "bin", "MW"]] | ||
| df_inv["class"] = df_inv["class"].astype("int") | ||
| df_inv["bin"] = df_inv["bin"].str.replace("bin", "", regex=False).astype("int") | ||
|
|
@@ -435,9 +431,9 @@ def get_input_refurbishments(run_folder, tech): | |
| df_inv_refurb_in = pd.read_csv( | ||
| inv_refurb, | ||
| low_memory=False, | ||
| names=["tech", "vintage", "region", "year", "MW"], | ||
| names=["tech", "class", "vintage", "region", "year", "MW"], | ||
| header=0, | ||
| usecols=["tech", "region", "year", "MW"], | ||
| usecols=["tech", "class", "region", "year", "MW"], | ||
| ) | ||
| df_inv_refurb_in = df_inv_refurb_in[ | ||
| df_inv_refurb_in["tech"].str.startswith(tech) | ||
|
|
@@ -462,14 +458,7 @@ def amend_refurbishments(df_inv_refurb_in): | |
| Returns refurbishments for the given technology, by year, region, and class. | ||
| Output columns include: ["year", "region", "class", "MW"] | ||
| """ | ||
| # Split tech from class | ||
| df_inv_refurb = df_inv_refurb_in.copy() | ||
| if df_inv_refurb.empty: | ||
| df_inv_refurb[["tech_cat", "class"]] = "" | ||
| else: | ||
| df_inv_refurb[["tech_cat", "class"]] = df_inv_refurb["tech"].str.split( | ||
| "_", n=1, expand=True | ||
| ) | ||
| df_inv_refurb = df_inv_refurb[["year", "region", "class", "MW"]] | ||
| df_inv_refurb["class"] = df_inv_refurb["class"].astype("int") | ||
| df_inv_refurb = df_inv_refurb.sort_values(by=["year", "region", "class"]) | ||
|
|
@@ -593,9 +582,9 @@ def get_exogenous_capacity(run_folder, tech): | |
| df_cap_exog = pd.read_csv( | ||
| cap_exog, | ||
| low_memory=False, | ||
| names=["tech", "vintage", "region", "year", "MW"], | ||
| names=["tech", "class", "vintage", "region", "year", "MW"], | ||
| header=0, | ||
| usecols=["tech", "region", "year", "MW"], | ||
| usecols=["tech", "class", "region", "year", "MW"], | ||
| ) | ||
| df_cap_exog = df_cap_exog[df_cap_exog["tech"].str.startswith(tech)].copy() | ||
|
|
||
|
|
@@ -1540,7 +1529,7 @@ def simultaneous_fill( | |
| break | ||
| # check to make sure inv_left isn't negative | ||
| if ret_left < 0: | ||
| print(f"ERROR at rcby={rcby}: ret_left is negative: {ret_left}") | ||
| print(f"ERROR at rcy={rcy}: ret_left is negative: {ret_left}") | ||
|
|
||
| if np.floor(ret_left * 100) / 100 != 0: | ||
| print( | ||
|
|
@@ -1607,7 +1596,7 @@ def simultaneous_fill( | |
| # check to make sure inv_left isn't negative | ||
| if refurb_left < 0: | ||
| print( | ||
| f"ERROR at rcby={rcby}: refurb_left is negative: {refurb_left}" | ||
| f"ERROR at rcy={rcy}: refurb_left is negative: {refurb_left}" | ||
| ) | ||
|
|
||
| if round(refurb_left, 2) != 0: | ||
|
|
@@ -2016,7 +2005,7 @@ def check_tech(run_folder, tech): | |
| """ | ||
| cap_chk = os.path.join(run_folder, "outputs", "cap.csv") | ||
| df_cap = pd.read_csv( | ||
| cap_chk, low_memory=False, names=["tech", "region", "year", "MW"], header=0 | ||
| cap_chk, low_memory=False, names=["tech", "class", "region", "year", "MW"], header=0 | ||
| ) | ||
| tech_included = df_cap["tech"].str.startswith(tech).any() | ||
|
|
||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks great programmatically. Conceptually, it might make sense to include the class in cap_energy_ivrt and/or cap_firm and cap_firm_iter?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it's necessary in cap_energy_ivrt because there are no class-relevant technologies for energy in the initial scope. It would make sense if PSH gets a class at some point. cap_firm, though, should get a class designation. We'll want to know exactly the capacity contribution of a technology. That will require making m_cc_mar adopt a class, which also needs to happen at some point. I've been focusing on stress periods, but I'll note this for follow-on work once I have a working stress-period formulation with collapsed classes. The output rename would also go along with that. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -588,6 +588,10 @@ def _fetch_cap_out(self, case: str) -> pd.DataFrame: | |
| columns={'Value': 'Capacity (GW)', 't': 'year', 'i': 'tech'}, | ||
| inplace=True, | ||
| ) | ||
|
|
||
| # Sum over resource class | ||
| df = df.groupby(['tech', 'r', 'year'], as_index=False)['Capacity (GW)'].sum() | ||
|
|
||
| return df | ||
|
|
||
|
|
||
|
|
@@ -973,7 +977,8 @@ def apply_transformations( | |
| items_map = Conventions.items_color_map[items_map_name][0] | ||
| if items_column == 'tech': | ||
| df['tech'] = df['tech'].str.lower().map(lambda x: items_map.get(x, x)) | ||
| df = df.groupby(['tech', 'r', 'year']).sum().reset_index() | ||
| valcols = df.select_dtypes('number').columns.difference(['year']) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a little less familiar with this part of ReEDS, so commenting just as a point to double-check... post-processing passed the checks, so we should be good
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I took another look and decided that summing over the resource would also help here. Reviewing these and reproducing outputs for ancillary scripts like this will be a key part of testing after the |
||
| df = df.groupby(['tech', 'r', 'year'])[valcols].sum().reset_index() | ||
|
|
||
| # Fill missing techs with 0 | ||
| idx = pd.MultiIndex.from_product( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Not related to this PR) I am also getting a suggested edit on line 1610: 'rcby' seems to be defined in line 1647... I wonder if it needs to be renamed to 'rcy' defined earlier, or move some code around?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reeds_to_rev.py isn't working right now, but this is a quick fix, so I can add it in here.