Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sanitize_locations yields AttributeError for electricity only runs without stores or hydrogen pipelines #939

Closed
Edudiro opened this issue Feb 19, 2024 · 1 comment
Labels
Milestone

Comments

@Edudiro
Copy link

Edudiro commented Feb 19, 2024

Checklist

  • [x ] I am using the current master branch or the latest release. Please indicate.
  • [x ] I am running on an up-to-date pypsa-eur environment. Update via conda env update -f envs/environment.yaml.

Describe the Bug

Please provide a description of what the bug is and add a minimal example/command for reproducing the bug.

The issue resides in add_extra_components.py. The functions attach_stores and attach_hydrogen_pipelines create a location attribute in network.buses and consequently, sanitize_locations works perfectly.

However, if no stores or hydrogen pipelines are added in the config file, location attribute is never included in network.buses and sanitize_location yields AttributeError.

To reproduce, provide a config file without stores or hydrogen pipelines and run solve_elec_networks.

For further context, see the pypsa community discussion: https://groups.google.com/g/pypsa/c/iNGgnejQyz4

Error Message

If applicable, paste any terminal output to help illustrating your problem.
In some cases it may also be useful to share your list of installed packages: conda list.

[Mon Feb 19 12:23:56 2024]
rule add_extra_components:
    input: resources/2024-test/networks/elec_s_2.nc, data/costs_2030_mod.csv
    output: resources/2024-test/networks/elec_s_2_ec.nc
    log: logs/2024-test/add_extra_components/elec_s_2.log
    jobid: 3
    benchmark: benchmarks/2024-test/add_extra_components/elec_s_2_ec
    reason: Missing output files: resources/2024-test/networks/elec_s_2_ec.nc; Input files updated by another job: resources/2024-test/networks/elec_s_2.nc
    wildcards: simpl=, clusters=2
    resources: tmpdir=C:\Users\SE91723\AppData\Local\Temp, mem_mb=4000, mem_mib=3815

INFO:pypsa.io:Imported network elec_s_2.nc has buses, carriers, generators, links, loads, storage_units
WARNING:add_electricity:tech_colors for carriers ['AC', 'DC', ''] not defined in config.
ERROR:root:Uncaught exception
Traceback (most recent call last):
  File "C:\Users\SE91723\Modelos\pypsa\pypsa-eur\.snakemake\scripts\tmpiy4dkx1f.add_extra_components.py", line 269, in <module>
    sanitize_locations(n)
  File "C:\Users\SE91723\Modelos\pypsa\pypsa-eur\rules\..\scripts\add_electricity.py", line 185, in sanitize_locations
    print(n.buses.location)
  File "C:\Users\SE91723\Anaconda3\envs\pypsa-eur\lib\site-packages\pandas\core\generic.py", line 6293, in __getattr__
    return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'location'
[Mon Feb 19 12:24:06 2024]
Error in rule add_extra_components:
    jobid: 3
    input: resources/2024-test/networks/elec_s_2.nc, data/costs_2030_mod.csv
    output: resources/2024-test/networks/elec_s_2_ec.nc
    log: logs/2024-test/add_extra_components/elec_s_2.log (check log file(s) for error details)
    conda-env: C:\Users\SE91723\Modelos\pypsa\pypsa-eur\.snakemake\conda\3701581752c6e5590dda85748a41c931_
@Edudiro Edudiro added the bug label Feb 19, 2024
@Schneewittchen7001
Copy link

Schneewittchen7001 commented Feb 22, 2024

I'm having the same issue - I fixed it with an if statement:
Lines 247-249 in add_extra_components.py:

sanitize_carriers(n, snakemake.config)
if "location" in n.buses:
    sanitize_locations(n)

@fneum fneum added this to the v0.11.0 milestone May 12, 2024
@fneum fneum closed this as completed in cadd334 May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants