PyPSA / pypsa-usa

PyPSA-USA: An Open-Source Energy System Optimization Model for the United States
https://pypsa-usa.readthedocs.io
MIT License
35 stars 14 forks source link

Investment Period being dropped in Simplify Network #333

Open trevorb1 opened 1 month ago

trevorb1 commented 1 month ago

Checklist

Issue exisits on what branch

Develop

The Issue

If I run a muti-horizon model, but for only a subset of the year (ie. Jan and Feb) the workflow fails (I do acknowledge this is kinda an odd thing to run, haha)

Steps To Reproduce

Put this in the config file

# docs :
scenario:
  interconnect: ["western"] #"usa|texas|western|eastern"
  clusters: [80]
  opts: [Ep-Co2L0.2]
  ll: [v1.0]
  scope: "total" # "urban", "rural", or "total"
  sector: "" # G
  planning_horizons:
  - 2030
  - 2050 #(2030, 2040, 2050)

foresight:  # Only Single Stage Currently

# docs :
enable:
  build_cutout: false

snapshots:
  start: "2019-01-01"
  end: "2019-03-01"
  inclusive: "left"

Expected Behavior

No response

Error Message

INFO:pypsa.io:Imported network elec_s.nc has buses, carriers, generators, lines, links, loads, storage_units
Traceback (most recent call last):
  File "/home/trevor/repos/pypsa-usa/workflow/.snakemake/scripts/tmp7xtms1lm.cluster_network.py", line 512, in <module>
    n.snapshot_weightings.loc[n.investment_periods[0]].objective.sum() / 8760.0
                              ~~~~~~~~~~~~~~~~~~~~^^^
  File "/home/trevor/miniforge3/envs/pypsa-usa/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 5389, in __getitem__
    return getitem(key)
           ^^^^^^^^^^^^
IndexError: index 0 is out of bounds for axis 0 with size

Anything else?

No response

trevorb1 commented 1 month ago

Oh, this is failing with only a single horizon as well

trevorb1 commented 1 month ago

hmm... investment periods is not being assigned higher up in the workflow. This is in cluster network

image

trevorb1 commented 1 month ago

Its assigned correctly at the start and when writing out in add_electricity

ktehranchi commented 1 month ago

Sorry I noticed this and made fixes on my branch add this beneath 458 in cluster


    n = pypsa.Network(snakemake.input.network)
    n.set_investment_periods( 
        periods=snakemake.params.planning_horizons,
    )
ktehranchi commented 1 month ago

during simplify network the investment periods get dropped. I didn't look into the cause more, but it could be a bug in pypsa

trevorb1 commented 1 month ago

Error is in Simplify Network

image

trevorb1 commented 1 month ago

Reported to PyPSA here