Skip to content

Getting started with PyPsa. AttributeError: 'tuple' object has no attribute 'bus0' #1

@BjoernLaemmerzahl

Description

@BjoernLaemmerzahl

Hello,

after successfully installing PyPsa on a clean Anaconda distribution I tried to run the first minimal example ("Build a minimal network for power flow"). However, already here I am running into problems.

Python 2.7.11 |Anaconda 2.5.0 (32-bit)| (default, Jan 29 2016, 15:36:56) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> """
... Created on Tue Mar 08 14:39:24 2016
... 
... @author: bjl
... """
'\nCreated on Tue Mar 08 14:39:24 2016\n\n@author: bjl\n'
>>> 
>>> import pypsa

import numpy as np

network = pypsa.Network()

for i in range(3):
    network.add("Bus","My bus {}".format(i))
>>> >>> >>> >>> >>> >>> ... ... 
Bus My bus 0
Bus My bus 1
Bus My bus 2
>>> 
>>> print(network.buses)
C:\Anaconda2\lib\site-packages\pandas\core\format.py:1995: RuntimeWarning: invalid value encountered in absolute
  abs_vals = np.abs(self.values)

         control sub_network  y  v_mag_pu_min current_type  v_nom  \
My bus 0      PQ              0             0           AC      1   
My bus 1      PQ              0             0           AC      1   
My bus 2      PQ              0             0           AC      1   

          v_mag_pu_max  x           obj  
My bus 0           NaN  0  Bus My bus 0  
My bus 1           NaN  0  Bus My bus 1  
My bus 2           NaN  0  Bus My bus 2  
C:\Anaconda2\lib\site-packages\pandas\core\format.py:1998: RuntimeWarning: invalid value encountered in greater
  has_large_values = (abs_vals > 1e8).any()
C:\Anaconda2\lib\site-packages\pandas\core\format.py:1999: RuntimeWarning: invalid value encountered in less
  has_small_values = ((abs_vals < 10 ** (-self.digits)) &
C:\Anaconda2\lib\site-packages\pandas\core\format.py:2000: RuntimeWarning: invalid value encountered in greater
  (abs_vals > 0)).any()
>>> >>> for i in range(3):
...     network.add("Line","My line {}".format(i),
...                 bus0="My bus {}".format(i),
...                 bus1="My bus {}".format((i+1)%3),
...                 x=0.0001)
... 
Line My line 0
Line My line 1
Line My line 2
>>> 
>>> print(network.lines)
           s_nom_min      bus0      bus1  capital_cost s_nom_extendable  \
My line 0          0  My bus 0  My bus 1             0            False   
My line 1          0  My bus 1  My bus 2             0            False   
My line 2          0  My bus 2  My bus 0             0            False   

           s_nom_opt  s_nom  s_nom_max sub_network  x_pu       ...        b  \
My line 0          0      0        NaN                 0       ...        0   
My line 1          0      0        NaN                 0       ...        0   
My line 2          0      0        NaN                 0       ...        0   

           g  v_ang_min  r_pu  terrain_factor  length  r       x  v_ang_max  \
My line 0  0        NaN     0               1       1  0  0.0001        NaN   
My line 1  0        NaN     0               1       1  0  0.0001        NaN   
My line 2  0        NaN     0               1       1  0  0.0001        NaN   

                      obj  
My line 0  Line My line 0  
My line 1  Line My line 1  
My line 2  Line My line 2  

[3 rows x 22 columns]
>>> 
>>> network.add("Generator","My gen",
...             bus="My bus 0",
...             p_set=100)
Generator My gen
>>> 
>>> print(network.generators)
             bus  sign control  p_min_pu_fixed  capital_cost p_nom_extendable  \
My gen  My bus 0     1      PQ               0             0            False   

        dispatch  p_nom_max  p_nom  p_nom_opt  p_nom_min  p_max_pu_fixed  \
My gen  flexible        NaN      0          0          0               1   

        efficiency source  marginal_cost               obj  
My gen           1                     0  Generator My gen  
>>> 
>>> print(network.generators_t.p_set)
     My gen
now     100
>>> 
>>> network.add("Load","My load",
...             bus="My bus 1",
...             p_set=100)
Load My load
>>> 
>>> print(network.loads)
              bus  sign           obj
My load  My bus 1    -1  Load My load
>>> 
>>> print(network.loads_t.p_set)
     My load
now      100
>>> 
>>> network.pf()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Anaconda2\lib\site-packages\pypsa\pf.py", line 78, in network_pf
    network.build_graph()
  File "C:\Anaconda2\lib\site-packages\pypsa\components.py", line 697, in build_graph
    for t in self.iterate_components(branch_types)
  File "C:\Anaconda2\lib\site-packages\networkx\classes\multigraph.py", line 403, in add_edges_from
    for e in ebunch:
  File "C:\Anaconda2\lib\site-packages\pypsa\components.py", line 698, in <genexpr>

    for branch in t.df.itertuples())
AttributeError: 'tuple' object has no attribute 'bus0'
>>> >>> print(network.lines_t.p0)
     My line 0  My line 1  My line 2
now          0          0          0
>>> 
>>> print(network.buses_t.v_ang*180/np.pi)
     My bus 0  My bus 1  My bus 2
now         0         0         0
>>> 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions