Skip to content
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

refactor: calculate marginal cost via linearized quadratic #603

Merged
merged 1 commit into from
Mar 16, 2022

Conversation

danielolsen
Copy link
Contributor

Pull Request doc

Purpose

When exporting a Scenario/Grid to a PyPSA Network, calculate the generators' marginal cost using a linearized quadratic (from Pmin to Pmax), rather than just the linear component of the quadratic curve.

What the code is doing

For generators where Pmin != Pmax, the expression [(a*Pmax^2 + b*Pmax + c) - (a*Pmin^2 + b*Pmin + c)]/(Pmax - Pmin) simplifies to b + a * (Pmax + Pmin), so we build the marginal_cost column based on this expression. For the edge case where Pmin = Pmax (e.g. if we've scaled generators down to 0), the existing linear term will still be used (since pandas.Series.combine_first only fills null values or values that aren't present in the first Series' index).

Testing

Tested manually:

from powersimdata import Scenario
from powersimdata.input.export_data import export_to_pypsa
scenario = Scenario()
scenario.set_grid("usa_tamu", "Texas")
scenario.set_base_profile("demand", "vJan2021")
scenario.set_base_profile("hydro", "vJan2021")
scenario.set_base_profile("solar", "vJan2021")
scenario.set_base_profile("wind", "vJan2021")
scenario.set_time("2016-01-01 00:00", "2016-01-01 23:00", "24H")
network = export_to_pypsa(scenario)
network.lopf(solver_name="gurobi", pyomo=False)

Time estimate

10 minutes.

@danielolsen danielolsen self-assigned this Mar 15, 2022
Copy link
Collaborator

@rouille rouille left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants