-
Notifications
You must be signed in to change notification settings - Fork 47
doc/refactor: improve documentation and usability of investment costs #465
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2ab8049
doc: update documentation of calculate_ac_inv_costs
danielolsen 380d088
doc: update documentation of calculate_dc_inv_costs
danielolsen 615c64e
doc: update documentation of calculate_gen_inv_costs
danielolsen 91cf3e1
refactor: change return type to Series for generators
danielolsen 281101a
refactor: change return type to Series for branches
danielolsen ba12bef
test: refactor tests to expect new return type
danielolsen 97f38d6
refactor: change cost prioritization to match new call signature
danielolsen 6b664a6
doc: fix ac inv costs docstring to account for new return
danielolsen dfcdcc5
doc: update sum_results info in AC cost docstring
danielolsen ee73750
doc: update sum_results info in DC cost docstring
danielolsen cb1b1cb
doc: update sum_results info in gen cost docstring
danielolsen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,8 +45,11 @@ def calculate_ac_inv_costs(scenario, sum_results=True, exclude_branches=None): | |
| NEEM regions are used to find regional multipliers. | ||
|
|
||
| :param powersimdata.scenario.scenario.Scenario scenario: scenario instance. | ||
| :param bool sum_results: sum data frame for each branch type. | ||
| :return: (*dict*) -- cost of upgrading branches in $2010. | ||
| :param bool sum_results: whether to sum data frame for each branch type. Defaults to | ||
| True. | ||
| :return: (*dict*) -- keys are {'line_cost', 'transformer_cost'}, values are either | ||
| float if ``sum_results``, or pandas Series indexed by branch ID. | ||
| Whether summed or not, values are $USD, inflation-adjusted to today. | ||
| """ | ||
|
|
||
| base_grid = Grid(scenario.info["interconnect"].split("_")) | ||
|
|
@@ -72,8 +75,11 @@ def _calculate_ac_inv_costs(grid_new, sum_results=True): | |
| as a transformer. | ||
|
|
||
| :param powersimdata.input.grid.Grid grid_new: grid instance. | ||
| :param bool sum_results: sum data frame for each branch type. | ||
| :return: (*dict*) -- cost of upgrading branches in $2010. | ||
| :param bool sum_results: whether to sum data frame for each branch type. Defaults to | ||
| True. | ||
| :return: (*dict*) -- keys are {'line_cost', 'transformer_cost'}, values are either | ||
| float if ``sum_results``, or pandas Series indexed by branch ID. | ||
| Whether summed or not, values are $USD, inflation-adjusted to today. | ||
| """ | ||
|
|
||
| def select_mw(x, cost_df): | ||
|
|
@@ -211,7 +217,7 @@ def get_branch_mult(x, bus_reg, ac_reg_mult, branch_lookup_alerted=set()): | |
| lines.loc[:, "MWmi"] = lines["lengthMi"] * lines["rateA"] | ||
|
|
||
| # calculate cost of each line | ||
| lines.loc[:, "Cost"] = lines["MWmi"] * lines["costMWmi"] * lines["mult"] | ||
| lines.loc[:, "cost"] = lines["MWmi"] * lines["costMWmi"] * lines["mult"] | ||
|
|
||
| # calculate transformer costs | ||
| if len(transformers) > 0: | ||
|
|
@@ -234,27 +240,30 @@ def get_branch_mult(x, bus_reg, ac_reg_mult, branch_lookup_alerted=set()): | |
| transformers["per_MW_cost"] = [] | ||
| transformers["mult"] = [] | ||
|
|
||
| transformers["Cost"] = ( | ||
| transformers["cost"] = ( | ||
| transformers["rateA"] * transformers["per_MW_cost"] * transformers["mult"] | ||
| ) | ||
|
|
||
| lines.Cost *= calculate_inflation(2010) | ||
| transformers.Cost *= calculate_inflation(2020) | ||
| lines.cost *= calculate_inflation(2010) | ||
| transformers.cost *= calculate_inflation(2020) | ||
| if sum_results: | ||
| return { | ||
| "line_cost": lines.Cost.sum(), | ||
| "transformer_cost": transformers.Cost.sum(), | ||
| "line_cost": lines.cost.sum(), | ||
| "transformer_cost": transformers.cost.sum(), | ||
| } | ||
| else: | ||
| return {"line_cost": lines, "transformer_cost": transformers} | ||
| return {"line_cost": lines.cost, "transformer_cost": transformers.cost} | ||
|
|
||
|
|
||
| def calculate_dc_inv_costs(scenario, sum_results=True): | ||
| """Calculate cost of upgrading HVDC lines in a scenario. | ||
|
|
||
| :param powersimdata.scenario.scenario.Scenario scenario: scenario instance. | ||
| :param bool sum_results: sum series to return total cost. | ||
| :return: (*pandas.Series/float*) -- cost of upgrading HVDC lines in $2015. | ||
| :param bool sum_results: whether to sum series to return total cost. Defaults to | ||
| True. | ||
| :return: (*pandas.Series/float*) -- cost of upgrading HVDC lines, in $USD, | ||
| inflation-adjusted to today. If ``sum_results``, a float is returned, otherwise | ||
| a Series. | ||
| """ | ||
| base_grid = Grid(scenario.info["interconnect"].split("_")) | ||
| grid = scenario.state.get_grid() | ||
|
|
@@ -274,8 +283,11 @@ def _calculate_dc_inv_costs(grid_new, sum_results=True): | |
| """Calculate cost of upgrading HVDC lines. | ||
|
|
||
| :param powersimdata.input.grid.Grid grid_new: grid instance. | ||
| :param bool sum_results: sum series to return total cost. | ||
| :return: (*pandas.Series/float*) -- cost of upgrading HVDC lines in $2015. | ||
| :param bool sum_results: whether to sum series to return total cost. Defaults to | ||
| True. | ||
| :return: (*pandas.Series/float*) -- cost of upgrading HVDC lines, in $USD, | ||
| inflation-adjusted to today. If ``sum_results``, a float is returned, otherwise | ||
|
Contributor
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. Same as above regarding the hardcoded "today" year in |
||
| a Series. | ||
| """ | ||
|
|
||
| def _calculate_single_line_cost(line, bus): | ||
|
|
@@ -321,8 +333,13 @@ def calculate_gen_inv_costs(scenario, year, cost_case, sum_results=True): | |
| :param int/str year: building year. | ||
| :param str cost_case: ATB cost case of data. *'Moderate'*: mid cost case, | ||
| *'Conservative'*: generally higher costs, *'Advanced'*: generally lower costs | ||
| :return: (*pandas.DataFrame*) -- total generation investment cost summed by | ||
| technology. | ||
| :param bool sum_results: whether to sum data frame for plant costs. Defaults to | ||
| True. | ||
| :return: (*pandas.Series*) -- Overnight generation investment cost. | ||
| If ``sum_results``, indices are technologies and values are total cost. | ||
| Otherwise, indices are IDs of plants (including storage, which is given | ||
| pseudo-plant-IDs), and values are individual generator costs. | ||
| Whether summed or not, values are $USD, inflation-adjusted to today. | ||
|
|
||
| .. todo:: it currently uses one (arbitrary) sub-technology. The rest of the costs | ||
| are dropped. Wind and solar will need to be fixed based on the resource supply | ||
|
|
@@ -364,11 +381,16 @@ def _calculate_gen_inv_costs(grid_new, year, cost_case, sum_results=True): | |
| *'Conservative'*: generally higher costs, *'Advanced'*: generally lower costs. | ||
| :raises ValueError: if year not 2020 - 2050, or cost case not an allowed option. | ||
| :raises TypeError: if year not int/str or cost_case not str. | ||
| :return: (*pandas.Series*) -- total generation investment cost, summed by | ||
| technology. | ||
| :param bool sum_results: whether to sum data frame for plant costs. Defaults to | ||
| True. | ||
| :return: (*pandas.Series*) -- Overnight generation investment cost. | ||
| If ``sum_results``, indices are technologies and values are total cost. | ||
| Otherwise, indices are IDs of plants (including storage, which is given | ||
| pseudo-plant-IDs), and values are individual generator costs. | ||
| Whether summed or not, values are $USD, inflation-adjusted to today. | ||
|
|
||
| .. note:: the function computes the total capital cost as: | ||
| CAPEX_total = CAPEX ($/MW) * Pmax (MW) * regional multiplier | ||
| CAPEX_total = overnight CAPEX ($/MW) * Power capacity (MW) * regional multiplier | ||
| """ | ||
|
|
||
| def load_cost(year, cost_case): | ||
|
|
@@ -501,13 +523,13 @@ def load_cost(year, cost_case): | |
| ) | ||
|
|
||
| # multiply all together to get summed CAPEX ($) | ||
| plants.loc[:, "CAPEX_total"] = ( | ||
| plants.loc[:, "cost"] = ( | ||
| plants["CAPEX"] * plants["Pmax"] * plants["reg_cap_cost_mult"] | ||
| ) | ||
|
|
||
| # sum cost by technology | ||
| plants.loc[:, "CAPEX_total"] *= calculate_inflation(2018) | ||
| plants.loc[:, "cost"] *= calculate_inflation(2018) | ||
| if sum_results: | ||
| return plants.groupby(["Technology"])["CAPEX_total"].sum() | ||
| return plants.groupby(["Technology"])["cost"].sum() | ||
| else: | ||
| return plants | ||
| return plants["cost"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If we're calculating inflation to "today", do we want to update this to 2021? Or better yet, get the current year?
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.
The first parameter of
calculate_inflationis thestart_year, and if theend_yearis not specified then we automatically use the latest year for which we have data inpowersimdata.design.investment.const.inflation_rate_pct.