Skip to content

feat: add component data xarray view#1076

Closed
lkstrp wants to merge 13 commits intonew-optfrom
xarray-view
Closed

feat: add component data xarray view#1076
lkstrp wants to merge 13 commits intonew-optfrom
xarray-view

Conversation

@lkstrp
Copy link
Copy Markdown
Member

@lkstrp lkstrp commented Nov 7, 2024

Adding up on #1075 and in preparation for #1037

Changes proposed in this Pull Request

  • Add xarray view of component data via c.ds.
    • Should be treated as immutable and probably only internally. Better setter checks and caching will be added.
  • Merge static and dynamic data
  • Handles timestep, period and scenario dimensions
  • Removes arbitrary naming of snapshot index (e.g. snapshot if not multi horizon, ['timestep', 'period'])
    • Rename snapshot -> `timestep
    • If people are somehow working with index names, this will break

Todos

  • Caching
  • Immutable checks

Example

Create network with investment periods

n = pypsa.examples.ac_dc_meshed()
n.snapshots = pd.MultiIndex.from_product([[2013], n.snapshots])
n.investment_periods = [2013]
gens_i = n.generators.index
rng = np.random.default_rng()
n.generators_t.p[gens_i] = rng.random(size=(len(n.snapshots), len(gens_i)))

then you can run:

>>> n.components.generators.ds
<xarray.Dataset> Size: 10kB
Dimensions:                  (Generator: 6, timestep: 10, period: 1)
Coordinates:
  * Generator                (Generator) object 48B 'Manchester Wind' ... 'Fr...
  * timestep                 (timestep) datetime64[ns] 80B 2015-01-01 ... 201...
  * period                   (period) int64 8B 2013
Data variables: (12/45)
    bus                      (Generator) object 48B 'Manchester' ... 'Frankfurt'
    control                  (Generator) object 48B 'PQ' 'PQ' 'PQ' ... 'PQ' 'PQ'
    type                     (Generator) object 48B '' '' '' '' '' ''
    p_nom                    (Generator) float64 48B 80.0 5e+04 ... 110.0 8e+04
    p_nom_mod                (Generator) float64 48B 0.0 0.0 0.0 0.0 0.0 0.0
    p_nom_extendable         (Generator) bool 6B True True True True True True
    ...                       ...
    status                   (Generator, timestep, period) float64 480B nan ....
    mu_upper                 (Generator, timestep, period) float64 480B nan ....
    mu_lower                 (Generator, timestep, period) float64 480B nan ....
    mu_p_set                 (Generator, timestep, period) float64 480B nan ....
    mu_ramp_limit_up         (Generator, timestep, period) float64 480B nan ....
    mu_ramp_limit_down       (Generator, timestep, period) float64 480B nan ....

With scenarios it could look something like this:

<xarray.Dataset> Size: 29kB
Dimensions:                  (Generator: 6, timestep: 10, scenario: 3, period: 1)
Coordinates:
  * Generator                (Generator) object 48B 'Frankfurt Gas' ... 'Norw...
  * timestep                 (timestep) datetime64[ns] 80B 2015-01-01 ... 201...
  * scenario                 (scenario) object 24B 'A' 'B' 'C'
  * period                   (period) int64 8B 2013
Data variables: (12/45)
    bus                      (scenario, Generator) object 144B 'Frankfurt' .....
    control                  (scenario, Generator) object 144B 'PQ' ... 'PQ'
    type                     (scenario, Generator) object 144B '' '' ... '' ''
    p_nom                    (scenario, Generator) float64 144B 8e+04 ... 100.0
    p_nom_mod                (scenario, Generator) float64 144B 0.0 0.0 ... 0.0
    p_nom_extendable         (scenario, Generator) bool 18B True True ... True
    ...                       ...
    status                   (Generator, timestep, scenario, period) float64 1kB ...
    mu_upper                 (Generator, timestep, scenario, period) float64 1kB ...
    mu_lower                 (Generator, timestep, scenario, period) float64 1kB ...
    mu_p_set                 (Generator, timestep, scenario, period) float64 1kB ...
    mu_ramp_limit_up         (Generator, timestep, scenario, period) float64 1kB ...
    mu_ramp_limit_down       (Generator, timestep, scenario, period) float64 1kB ...

@lkstrp lkstrp requested a review from Irieo November 7, 2024 14:45
@lkstrp lkstrp changed the title feat: add component data view feat: add component data xarray view Nov 7, 2024
@Irieo Irieo mentioned this pull request Nov 20, 2024
45 tasks
Base automatically changed from component-class to master December 9, 2024 15:55
@lkstrp lkstrp marked this pull request as draft January 28, 2025 14:48
@lkstrp lkstrp removed the feature label Feb 17, 2025
@FabianHofmann FabianHofmann mentioned this pull request Mar 2, 2025
4 tasks
@lkstrp lkstrp changed the base branch from master to new-opt March 5, 2025 08:43
@lkstrp
Copy link
Copy Markdown
Member Author

lkstrp commented Mar 5, 2025

Closing as this is a dev branch into #1154 and already squashed in there

@lkstrp lkstrp closed this Mar 5, 2025
@lkstrp lkstrp added the optimization Feature related to new variables, constraints in standard optimization label Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

optimization Feature related to new variables, constraints in standard optimization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant