Breakthrough-Energy / SwitchWrapper

Wrapper for Switch
MIT License
1 stars 2 forks source link

feat: add function to create data frame for fuel_cost #32

Closed danielolsen closed 3 years ago

danielolsen commented 3 years ago

Purpose

Create data frame to populate the gen_build_costs.csv file. Closes #6.

What is the code doing

Testing

Manual, based on the mvp_empty_dataframe branch. For one year:

>>> from powersimdata import Grid
>>> from switchwrapper.grid_to_switch import grid_to_switch
>>> grid = Grid("Western")
Reading bus.csv
Reading plant.csv
Reading gencost.csv
Reading branch.csv
Reading dcline.csv
Reading sub.csv
Reading bus2sub.csv
Reading zone.csv
>>> grid_to_switch(grid, "output")
Please enter base study year (normally PowerSimData scenario year): 2030
Please enter the number of investment stages: 1
Single stage expansion identified.
Please enter investment period year, separate by space: 2030
Please enter start year for each period, separate by space: 2030
Please enter end year for each period, separate by space: 2030

For multiple years:

>>> from powersimdata import Grid
>>> from switchwrapper.grid_to_switch import grid_to_switch
>>> grid = Grid("Western")
Reading bus.csv
Reading plant.csv
Reading gencost.csv
Reading branch.csv
Reading dcline.csv
Reading sub.csv
Reading bus2sub.csv
Reading zone.csv
>>> grid_to_switch(grid, "output2")
Please enter base study year (normally PowerSimData scenario year): 2030
Please enter the number of investment stages: 2
Multi stage expansion identified.
Please enter investment period year, separate by space: 2030 2031
Please enter start year for each period, separate by space: 2030 2031
Please enter end year for each period, separate by space: 2030 2031

Output files are as expected.

Time to review

15-30 minutes. There's nothing too fancy in here, but we do have a few interesting pandas dataframe method calls.

danielolsen commented 3 years ago

I moved the calculation of average fuel cost by bus into its own separate function, since it will be required for https://github.com/Breakthrough-Energy/SwitchWrapper/issues/1. Manual testing on the mvp_empty_dataframe branch confirms that everything still works as expected:

>>> from switchwrapper.grid_to_switch import grid_to_switch
>>> from powersimdata import Grid
>>> grid = Grid("Western")
Reading bus.csv
Reading plant.csv
Reading gencost.csv
Reading branch.csv
Reading dcline.csv
Reading sub.csv
Reading bus2sub.csv
Reading zone.csv
>>> grid_to_switch(grid, "output3")
Please enter base study year (normally PowerSimData scenario year): 2030
Please enter the number of investment stages: 1
Single stage expansion identified.
Please enter investment period year, separate by space: 2030
Please enter start year for each period, separate by space: 2030
Please enter end year for each period, separate by space: 2030
>>>
danielolsen commented 3 years ago

@YifanLi86 there is one thing that makes the code in the current state of the PR not robust to non-Western grids: we don't have a translation from our dfo and other types to Switch fuels. I think we can still merge this in and get started on testing for Western grids, but we will need to come up with mappings before we can successfully run on Eastern grids.