pypsa-meets-earth / pypsa-earth-sec

GNU General Public License v3.0
19 stars 16 forks source link

Inconsistent usage of nodes and spatial.nodes from different sources #287

Closed davide-f closed 1 month ago

davide-f commented 4 months ago

Checklist

Describe the Bug

In prepare sector_network there is a wide usage of "nodes" and spatial.nodes that have 2 different sources:

  1. n.buses[AC carrier]
  2. pop_layout.index

When executing the workflow several issues appear due to the different indexing. I believe an alignment on the architecture may be needed to understand how to treat this issue.

As options, we may have:

  1. use the largest among the two (pop_layout if I get it right)
  2. keep the differences but handle that smartly. This means keeping double indexing and distinguish the to.

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.

Traceback (most recent call last):
  File "/data/davidef/git_sec/pypsa-earth-sec/scripts/prepare_sector_network.py", line 2457, in <module>
    h2_hc_conversions(n, costs)
  File "/data/davidef/git_sec/pypsa-earth-sec/scripts/prepare_sector_network.py", line 881, in h2_hc_conversions
    n.madd(
  File "/home/davidef/miniconda3/envs/pypsa-earth/lib/python3.10/site-packages/pypsa/components.py", line 1015, in madd
    pd.DataFrame(static, index=new_names), class_name
  File "/home/davidef/miniconda3/envs/pypsa-earth/lib/python3.10/site-packages/pandas/core/frame.py", line 767, in __init__
    mgr = dict_to_mgr(data, index, columns, dtype=dtype, copy=copy, typ=manager)
  File "/home/davidef/miniconda3/envs/pypsa-earth/lib/python3.10/site-packages/pandas/core/internals/construction.py", line 503, in dict_to_mgr
    return arrays_to_mgr(arrays, columns, index, dtype=dtype, typ=typ, consolidate=copy)
  File "/home/davidef/miniconda3/envs/pypsa-earth/lib/python3.10/site-packages/pandas/core/internals/construction.py", line 152, in arrays_to_mgr
    return create_block_manager_from_column_arrays(
  File "/home/davidef/miniconda3/envs/pypsa-earth/lib/python3.10/site-packages/pandas/core/internals/managers.py", line 2141, in create_block_manager_from_column_arrays
    raise_construction_error(len(arrays), arrays[0].shape, axes, e)
  File "/home/davidef/miniconda3/envs/pypsa-earth/lib/python3.10/site-packages/pandas/core/internals/managers.py", line 2167, in raise_construction_error
    raise e
  File "/home/davidef/miniconda3/envs/pypsa-earth/lib/python3.10/site-packages/pandas/core/internals/managers.py", line 2138, in create_block_manager_from_column_arrays
    blocks = _form_blocks(arrays, consolidate, refs)
  File "/home/davidef/miniconda3/envs/pypsa-earth/lib/python3.10/site-packages/pandas/core/internals/managers.py", line 2211, in _form_blocks
    values, placement = _stack_arrays(list(tup_block), dtype)
  File "/home/davidef/miniconda3/envs/pypsa-earth/lib/python3.10/site-packages/pandas/core/internals/managers.py", line 2253, in _stack_arrays
    stacked[i] = arr
ValueError: could not broadcast input array from shape (421,) into shape (424,)