AttributeError: 'DataFrame' object has no attribute 'obj'

451 views
Skip to first unread message

Karamanlis Konstantinos

unread,
Feb 16, 2017, 11:46:36 AM2/16/17
to pypsa
Hi everyone,

I am new in pypsa and I would like to ask you for some guidelines. I have ran scigrid for the region of cologne. Attached you can find links.csv and vertices.csv. When I m running this :

vertices = pd.read_csv("vertices.csv",index_col=0)
vertices.rename(columns={"lon":"x","lat":"y","name":"osm_name"},inplace=True)

links = pd.read_csv("C:/Users/Konstantinos Karaman.GRANAZIS/Documents/csv/links.csv",index_col=0)
links.rename(columns={"v_id_1":"bus0","v_id_2":"bus1","name":"osm_name"},inplace=True)

links["cables"].fillna(3,inplace=True)
links["wires"].fillna(2,inplace=True)
links["length"] = links["length_m"]/1000.

network = pypsa.Network()
pypsa.io.import_components_from_dataframe(network,vertices,"Bus")
pypsa.io.import_components_from_dataframe(network,links,"Line")

for sn in network.sub_networks.obj:
    buses = sn.buses().index
    branches = sn.branches().index
   
    if len(buses) < 5:
        print("Dropping Sub-Network {} because it only has {} buses".format(sn,len(buses)))
        #print(buses.index)
        #print(len(branches),branches.index)
        for bus in buses:
            network.remove("Bus",bus)
        for branch in branches:
            network.remove("Line",branch[1])
    else:
        print("Keeping Sub-Network {} because it has {} buses".format(sn,len(buses)))



I get the error :

AttributeError                            Traceback (most recent call last)
<ipython-input-48-6dea747309bc> in <module>()
----> 1 for sn in network.sub_networks.obj:
      2     buses = sn.buses().index
      3     branches = sn.branches().index
      4 
      5     if len(buses) < 5:

C:\Users\Konstantinos Karaman.GRANAZIS\Anaconda3\envs\py34\lib\site-packages\pandas\core\generic.py in __getattr__(self, name)
   2742             if name in self._info_axis:
   2743                 return self[name]
-> 2744             return object.__getattribute__(self, name)
   2745 
   2746     def __setattr__(self, name, value):

AttributeError: 'DataFrame' object has no attribute 'obj'


Any help please? Thanks in advance

links.csv
vertices.csv

Tom Brown

unread,
Feb 16, 2017, 12:06:09 PM2/16/17
to py...@googlegroups.com
Hi Karamanlis,

The problem is that the sub-networks are defined as the connected
sub-networks within the network. To determine what they are, you have to
call

network.determine_network_topology()

first (i.e. before the for loop in your example). Otherwise PyPSA
doesn't know what's connected and what's not. See the example:

https://pypsa.org/examples/add_load_gen_trafos_to_scigrid.html

Best,

Tom
> <ipython-input-48-6dea747309bc> in <module>() ----> 1for sn in
> network.sub_networks.obj:2 buses = sn.buses().index3 branches =
> sn.branches().index4 5 if len(buses) < 5:C:\Users\Konstantinos
> Karaman.GRANAZIS\Anaconda3\envs\py34\lib\site-packages\pandas\core\generic.py
> in __getattr__(self, name) 2742 if name in self._info_axis:2743 return
> self[name]-> 2744return object.__getattribute__(self, name)2745 2746 def
> __setattr__(self, name, value):AttributeError: 'DataFrame' object has no
> attribute 'obj'
>
>
> Any help please? Thanks in advance
>
> --
> You received this message because you are subscribed to the Google
> Groups "pypsa" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to pypsa+un...@googlegroups.com
> <mailto:pypsa+un...@googlegroups.com>.
> To post to this group, send email to py...@googlegroups.com
> <mailto:py...@googlegroups.com>.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/pypsa/5a2539c6-6a9e-4f0f-9d7a-ce3b282095b7%40googlegroups.com
> <https://groups.google.com/d/msgid/pypsa/5a2539c6-6a9e-4f0f-9d7a-ce3b282095b7%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

--
Tom Brown
Postdoctoral Researcher
Frankfurt Institute for Advanced Studies
https://fias.uni-frankfurt.de/physics/schramm/renewable-energy-system-and-network-analysis/
Personal site: https://www.nworbmot.org
Phone: +49 69 798 47693

Karamanlis Konstantinos

unread,
Feb 16, 2017, 1:30:10 PM2/16/17
to pypsa
Hi Tom,

thanks for the reply. Allow me a further question. Running network.consistency_check(), I m getting the following error:


WARNING:pypsa.components:The following lines have zero x, which could break the linear load flow:
Index(['34', '2', '4', '5', '6', '7', '8', '9', '11', '12', '13', '14', '15',
       '17', '18', '19', '20', '21', '22', '24', '25', '26', '27', '28', '29',
       '31', '32', '33', '35', '36', '37', '39', '1', '3', '10', '16', '23',
       '30', '38', '40', '41', '42', '43'],
      dtype='object')
WARNING:pypsa.components:The following lines have zero r, which could break the linear load flow:
Index(['34', '2', '4', '5', '6', '7', '8', '9', '11', '12', '13', '14', '15',
       '17', '18', '19', '20', '21', '22', '24', '25', '26', '27', '28', '29',
       '31', '32', '33', '35', '36', '37', '39', '1', '3', '10', '16', '23',
       '30', '38', '40', '41', '42', '43'],
      dtype='object')
WARNING:pypsa.components:The following lines have zero series impedance, which will break the load flow:
Index(['34', '2', '4', '5', '6', '7', '8', '9', '11', '12', '13', '14', '15',
       '17', '18', '19', '20', '21', '22', '24', '25', '26', '27', '28', '29',
       '31', '32', '33', '35', '36', '37', '39', '1', '3', '10', '16', '23',
       '30', '38', '40', '41', '42', '43'],
      dtype='object')
WARNING:pypsa.components:The following attributes of the dataframe transformer_types have the wrong dtype:
Index(['tap_side', 'tap_neutral', 'tap_min', 'tap_max'], dtype='object', name='attribute')
They are:
attribute
tap_side       int32
tap_neutral    int32
tap_min        int32
tap_max        int32
dtype: object
but should be:
attribute
tap_side       int64
tap_neutral    int64
tap_min        int64
tap_max        int64
Name: typ, dtype: object

Appart from one link (l_id =34), all the rest have non zero r,x,c. Could this drive the error?
Even though I set r,x,c of l_id=34 equal to some value, still I got the same error.

What am I missing? Thanks in advance!

Tom Brown

unread,
Feb 16, 2017, 1:38:18 PM2/16/17
to py...@googlegroups.com
Try checking network.lines[["x","r"]] to see if it's really zero. You
can also inspect the code to see what's going on.

The int32/int64 warning is not critical.

Tom
> > an email to pypsa+un...@googlegroups.com <javascript:>
> > <mailto:pypsa+un...@googlegroups.com <javascript:>>.
> > To post to this group, send email to py...@googlegroups.com
> <javascript:>
> > <mailto:py...@googlegroups.com <javascript:>>.
> <https://groups.google.com/d/msgid/pypsa/5a2539c6-6a9e-4f0f-9d7a-ce3b282095b7%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/optout>.
> --
> You received this message because you are subscribed to the Google
> Groups "pypsa" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to pypsa+un...@googlegroups.com
> <mailto:pypsa+un...@googlegroups.com>.
> To post to this group, send email to py...@googlegroups.com
> <mailto:py...@googlegroups.com>.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/pypsa/0fc9b87f-6b8b-400a-8827-4637cc3e320e%40googlegroups.com
> <https://groups.google.com/d/msgid/pypsa/0fc9b87f-6b8b-400a-8827-4637cc3e320e%40googlegroups.com?utm_medium=email&utm_source=footer>.
Reply all
Reply to author
Forward
0 new messages