Breakthrough-Energy / SwitchWrapper

Wrapper for Switch
MIT License
1 stars 2 forks source link

feat: add logic to build_variable_capacity_factors function #64

Closed danielolsen closed 3 years ago

danielolsen commented 3 years ago

Pull Request doc

Purpose

This addresses the generation of the variable_capacity_factors.csv file as described in #55.

What the code is doing

Profiles are combined with plant capacities from the Grid to get normalized profiles. Timestamps are aggregated to timepoints as in #61. Columns are re-ordered to match the example outputs, and then all data are duplicated (with different entries in the GENERATION_PROJECT column) as we assume the same capacity factors for existing and hypothetical plants.

Testing

Manual testing, spot-checked against values in the example outputs since the ordering is different. Could be more fully verified by setting GENERATION_PROJECT and timepoint as indices and comparing values that way.

import pandas as pd
from powersimdata import Scenario
from switchwrapper.profiles_to_switch import profiles_to_switch
scenario = Scenario(599)
grid = scenario.get_grid()
profiles = {
    "demand": scenario.get_demand(),
    "hydro": scenario.get_hydro(),
    "solar": scenario.get_solar(),
    "wind": scenario.get_wind(),
}
timestamps_to_timepoints = pd.read_csv("slicing_recovery.csv", index_col=0).squeeze()
profiles_to_switch(grid, profiles, None, None, timestamps_to_timepoints, "profiles_output")

Time estimate

15-30 minutes.

danielolsen commented 3 years ago

Based on conversations in https://github.com/Breakthrough-Energy/SwitchWrapper/pull/64#discussion_r637243778, I've added a new module helpers.py, with a single function make_indices, which standardizes the building of IDs for Switch from an iterable of plant IDs (either all plants for grid_to_switch, or the subset of variable plants for profiles_to_switch). That should reduce the risk of these two drifting apart. Tested successfully with:

import pandas as pd
from powersimdata import Scenario
from switchwrapper.grid_to_switch import grid_to_switch
from switchwrapper.profiles_to_switch import profiles_to_switch
scenario = Scenario(599)
grid = scenario.get_grid()
profiles = {
    "demand": scenario.get_demand(),
    "hydro": scenario.get_hydro(),
    "solar": scenario.get_solar(),
    "wind": scenario.get_wind(),
}
timestamps_to_timepoints = pd.read_csv("slicing_recovery.csv", index_col=0).squeeze()
profiles_to_switch(grid, profiles, None, None, timestamps_to_timepoints, "profiles_output")
grid_to_switch(grid, "outputs")

Note that this usage example still includes the current timepoints/timeseries inputs to profiles_to_switch, which will be consolidated once #63 is merged.