Skip to content

Base grid should not be used when scaling profile #260

@rouille

Description

@rouille

The base grid is used in the TransformProfile class to obtain the list of plant id for a given resource and a given zone when we want to scale the base profile. If the base grid has generators that were added to the TAMU plant.csv after the scenario was produced then the id of these generators won't be in the base profile and the scaling procedure will fail.

I tried to get the solar profile for scenario 462 and got the following error:

Python 3.8.3 (default, Jul 17 2020, 11:03:54) 
[Clang 11.0.3 (clang-1103.0.32.62)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from powersimdata.scenario.scenario import Scenario
>>> s = Scenario("462")
SCENARIO: base | USABase_2016_new_HVDC_2
--> State
analyze
--> Loading grid
Loading bus
Loading plant
Loading heat_rate_curve
Loading gencost_before
Loading gencost_after
Loading branch
Loading dcline
Loading sub
Loading bus2sub
--> Loading ct
>>> solar = s.state.get_solar()
Reading bus.csv
Reading plant.csv
Reading gencost.csv
Reading branch.csv
Reading dcline.csv
Reading sub.csv
Reading bus2sub.csv
Reading zone.csv
--> Loading solar
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/brdo/CEM/PowerSimData/powersimdata/scenario/analyze.py", line 302, in get_solar
    return profile.get_profile("solar")
  File "/Users/brdo/CEM/PowerSimData/powersimdata/input/transform_profile.py", line 128, in get_profile
    return self._get_renewable_profile(name)
  File "/Users/brdo/CEM/PowerSimData/powersimdata/input/transform_profile.py", line 47, in _get_renewable_profile
    power_output = self._scale_plant_profile(power_output, resource)
  File "/Users/brdo/CEM/PowerSimData/powersimdata/input/transform_profile.py", line 92, in _scale_plant_profile
    profile.loc[:, plant_id] *= f
  File "/Users/brdo/.local/share/virtualenvs/PowerSimData-MpUK62nT/lib/python3.8/site-packages/pandas/core/indexing.py", line 1762, in __getitem__
    return self._getitem_tuple(key)
  File "/Users/brdo/.local/share/virtualenvs/PowerSimData-MpUK62nT/lib/python3.8/site-packages/pandas/core/indexing.py", line 1289, in _getitem_tuple
    retval = getattr(retval, self.name)._getitem_axis(key, axis=i)
  File "/Users/brdo/.local/share/virtualenvs/PowerSimData-MpUK62nT/lib/python3.8/site-packages/pandas/core/indexing.py", line 1954, in _getitem_axis
    return self._getitem_iterable(key, axis=axis)
  File "/Users/brdo/.local/share/virtualenvs/PowerSimData-MpUK62nT/lib/python3.8/site-packages/pandas/core/indexing.py", line 1595, in _getitem_iterable
    keyarr, indexer = self._get_listlike_indexer(key, axis, raise_missing=False)
  File "/Users/brdo/.local/share/virtualenvs/PowerSimData-MpUK62nT/lib/python3.8/site-packages/pandas/core/indexing.py", line 1552, in _get_listlike_indexer
    self._validate_read_indexer(
  File "/Users/brdo/.local/share/virtualenvs/PowerSimData-MpUK62nT/lib/python3.8/site-packages/pandas/core/indexing.py", line 1654, in _validate_read_indexer
    raise KeyError(
KeyError: 'Passing list-likes to .loc or [] with any missing labels is no longer supported, see https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#deprecate-loc-reindex-listlike'
>>> 

It breaks when trying to scale the solar plants in zone id 209. One can see that the list of plant id in zone id 209 in the grid used for the scenario differs from the base grid:

Python 3.8.3 (default, Jul 17 2020, 11:03:54) 
[Clang 11.0.3 (clang-1103.0.32.62)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from powersimdata.scenario.scenario import Scenario
>>> s = Scenario("462")
SCENARIO: base | USABase_2016_new_HVDC_2
--> State
analyze
--> Loading grid
Loading bus
Loading plant
Loading heat_rate_curve
Loading gencost_before
Loading gencost_after
Loading branch
Loading dcline
Loading sub
Loading bus2sub
--> Loading ct
>>> g = s.state.get_grid()
>>> plant_id = g.plant.groupby(["zone_id", "type"]).get_group((209, 'solar')).index
>>> plant_id
Int64Index([12062, 12063, 12064, 12081, 12103, 12104, 12117, 12120, 12121,
            12122, 12123, 12124, 12129, 12130, 12131, 12132, 12133, 12134,
            12135, 12148, 12161, 12162, 12169, 12170, 12185, 12214, 12215,
            12216, 12233, 12234, 12245, 12252, 12253, 12260, 12264, 12265,
            12269, 12273, 12274],
           dtype='int64', name='plant_id')
>>> from powersimdata.input.grid import Grid
>>> g_base = Grid(['USA'])
Reading bus.csv
Reading plant.csv
Reading gencost.csv
Reading branch.csv
Reading dcline.csv
Reading sub.csv
Reading bus2sub.csv
Reading zone.csv
>>> plant_id_base = g_base.plant.groupby(["zone_id", "type"]).get_group((209, 'solar')).index
>>> plant_id_base
Int64Index([12062, 12063, 12064, 12081, 12103, 12104, 12117, 12120, 12121,
            12122, 12123, 12124, 12129, 12130, 12131, 12132, 12133, 12134,
            12135, 12148, 12161, 12162, 12169, 12170, 12185, 12214, 12215,
            12216, 12233, 12234, 12245, 12252, 12253, 12260, 12264, 12265,
            12269, 12273, 12274, 13974, 13983, 13986, 13990, 13991],
           dtype='int64', name='plant_id')

the additional plant id in the base grid comes from an update made May 21st. Plant id 13974, 13983, 13986, 13990, 13991 were added at that time (commit 8b76a68)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions