Skip to content

feat: option to change components api#1235

Merged
lkstrp merged 4 commits intoPyPSA:masterfrom
lkstrp:legacy-comps
May 21, 2025
Merged

feat: option to change components api#1235
lkstrp merged 4 commits intoPyPSA:masterfrom
lkstrp:legacy-comps

Conversation

@lkstrp
Copy link
Copy Markdown
Member

@lkstrp lkstrp commented May 20, 2025

Closes #936

Changes proposed in this Pull Request

  • Adds the option to turn on the proposed new API for 1.0.
  • With 1.0, I would switch the default with a link to a migration guide, but the option also allows for backwards compatibility without migration with 1.x
  • Also adds a bit of quality of life for docs, code completion etc.

When setting

pypsa.options.api.legacy_components = True

n.generators (and _t) will yield the same as right now

>>> n.generators
                        bus control type    p_nom  p_nom_mod  p_nom_extendable  p_nom_min  p_nom_max  p_min_pu  p_max_pu  p_set  e_sum_min  ...  shut_down_cost  stand_by_cost  min_up_time min_down_time  up_time_before  down_time_before  ramp_limit_up  ramp_limit_down  ramp_limit_start_up  ramp_limit_shut_down  weight  p_nom_opt
Generator                                                                                                                                   ...                                                                                                                                                                                          
Manchester Wind  Manchester      PQ          80.0        0.0              True      100.0        inf       0.0       1.0    0.0       -inf  ...             0.0            0.0            0             0               1                 0            NaN              NaN                  1.0                   1.0     1.0        0.0
Manchester Gas   Manchester      PQ       50000.0        0.0              True        0.0        inf       0.0       1.0    0.0       -inf  ...             0.0            0.0            0             0               1                 0            NaN              NaN                  1.0                   1.0     1.0        0.0
Norway Wind          Norway      PQ         100.0        0.0              True      100.0        inf       0.0       1.0    0.0       -inf  ...             0.0            0.0            0             0               1                 0            NaN              NaN                  1.0                   1.0     1.0        0.0
Norway Gas           Norway      PQ       20000.0        0.0              True        0.0        inf       0.0       1.0    0.0       -inf  ...             0.0            0.0            0             0               1                 0            NaN              NaN                  1.0                   1.0     1.0        0.0
Frankfurt Wind    Frankfurt      PQ         110.0        0.0              True      100.0        inf       0.0       1.0    0.0       -inf  ...             0.0            0.0            0             0               1                 0            NaN              NaN                  1.0                   1.0     1.0        0.0
Frankfurt Gas     Frankfurt      PQ       80000.0        0.0              True        0.0        inf       0.0       1.0    0.0       -inf  ...             0.0            0.0            0             0               1                 0            NaN              NaN                  1.0                   1.0     1.0        0.0

[6 rows x 37 columns]

With

pypsa.options.api.legacy_components = False

you get the components class from n.components.<components_name> (where it sits right now). And then n.generators.static etc. to yield the same informations

>>> n.generators
'Generator' Components
----------------------
Attached to PyPSA Network 'AC-DC'
Components: 6

Checklist

  • Code changes are sufficiently documented; i.e. new functions contain docstrings and further explanations may be given in doc.
  • Unit tests for new features were added (if applicable).
  • A note for the release notes doc/release_notes.rst of the upcoming release is included.
  • I consent to the release of this PR's code under the MIT license.

@lkstrp lkstrp enabled auto-merge (squash) May 21, 2025 13:53
@lkstrp lkstrp merged commit bc8f77e into PyPSA:master May 21, 2025
22 checks passed
lkstrp added a commit to lkstrp/PyPSA that referenced this pull request Jun 6, 2025
* add more stable option check

* wip

* better warnings, setters and tests

* fix types
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.

Components Class

1 participant