Skip to content

Commit

Permalink
feat: clip and round values in curtailment data frames
Browse files Browse the repository at this point in the history
  • Loading branch information
rouille committed Sep 23, 2020
1 parent ffccaa3 commit 42d3342
Showing 1 changed file with 17 additions and 24 deletions.
41 changes: 17 additions & 24 deletions postreise/analyze/generation/curtailment.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import pandas as pd
from collections import defaultdict

import pandas as pd
from postreise.analyze.check import (
_check_scenario_is_in_analyze_state,
_check_grid,
_check_resources_are_renewable_and_format,
_check_resources_are_in_grid,
_check_areas_are_in_grid_and_format,
_check_curtailment,
_check_grid,
_check_resources_are_in_grid,
_check_resources_are_renewable_and_format,
_check_scenario_is_in_analyze_state,
)
from postreise.analyze.helpers import (
get_plant_id_for_resource_in_interconnect,
get_plant_id_for_resource_in_loadzone,
get_plant_id_for_resource_in_state,
get_plant_id_for_resource_in_interconnect,
summarize_plant_to_bus,
summarize_plant_to_location,
)
from powersimdata.network.usa_tamu.constants.plants import renewable_resources
from powersimdata.network.usa_tamu.constants import zones

from powersimdata.network.usa_tamu.constants.plants import renewable_resources

# What is the name of the function in scenario.state to get the profiles?
# The set of keys to in dict defines the set of possible curtailment resources.
Expand Down Expand Up @@ -56,7 +56,9 @@ def calculate_curtailment_time_series(scenario, resources=None):
curtailment = {}
for r in resources:
ren_plants = grid.plant.groupby("type").get_group(r).index
curtailment[r] = relevant_profiles[ren_plants] - pg[ren_plants]
curtailment[r] = (
(relevant_profiles[ren_plants] - pg[ren_plants]).clip(lower=0).round(6)
)

return curtailment

Expand All @@ -67,7 +69,7 @@ def calculate_curtailment_time_series_by_area(scenario, resources=None, areas=No
:param powersimdata.scenario.scenario.Scenario scenario: scenario instance.
:param str/tuple/list/set resources: names of resources to analyze. Default is
all resources which can be curtailed, defined in _resource_func.
:param dict areas: keys are area types ('*loadzone*', '*state*', '*state_abbr*' or
:param dict areas: keys are area types ('*loadzone*', '*state*', '*state_abv*' or
'*interconnect*'), values are a list of areas. Default is the interconnect of
the scenario.
:return: (*dict*) -- keys are areas, values are dictionaries whose keys are
Expand All @@ -85,7 +87,7 @@ def calculate_curtailment_time_series_by_area(scenario, resources=None, areas=No
raise TypeError("areas must be a dict")

curtailment = calculate_curtailment_time_series(scenario, resources)
curtailment_by_area = {}
curtailment_by_area = defaultdict(dict)
for count, r in enumerate(curtailment.keys()):
for k, v in areas.items():
if k == "interconnect":
Expand All @@ -95,30 +97,21 @@ def calculate_curtailment_time_series_by_area(scenario, resources=None, areas=No
r, i, scenario.state.get_grid()
)
name = "%s interconnect" % " - ".join(i.split("_"))
if count == 0:
curtailment_by_area[name] = {r: curtailment[r][plant_id]}
else:
curtailment_by_area[name].update({r: curtailment[r][plant_id]})
elif k == "state" or k == "state_abbr":
curtailment_by_area[name].update({r: curtailment[r][plant_id]})
elif k == "state" or k == "state_abv":
states = [v] if isinstance(v, str) else v
for s in states:
plant_id = get_plant_id_for_resource_in_state(
r, s, scenario.state.get_grid()
)
if count == 0:
curtailment_by_area[s] = {r: curtailment[r][plant_id]}
else:
curtailment_by_area[s].update({r: curtailment[r][plant_id]})
curtailment_by_area[s].update({r: curtailment[r][plant_id]})
elif k == "loadzone":
loadzones = [v] if isinstance(v, str) else v
for l in loadzones:
plant_id = get_plant_id_for_resource_in_loadzone(
r, l, scenario.state.get_grid()
)
if count == 0:
curtailment_by_area[l] = {r: curtailment[r][plant_id]}
else:
curtailment_by_area[l].update({r: curtailment[r][plant_id]})
curtailment_by_area[l].update({r: curtailment[r][plant_id]})
else:
raise ValueError("invalid area type")

Expand Down

0 comments on commit 42d3342

Please sign in to comment.