susantoj / PYPOWER-Dynamics

Python-based transient stability simulation program
BSD 3-Clause "New" or "Revised" License
57 stars 31 forks source link

Integer indices #15

Closed SanPen closed 6 years ago

SanPen commented 6 years ago

Hi I have been trying to use pypower dynamics in python3.

So far I have found the following error: IndexError: only integers, slices (:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices

This happens becase the indices are floats instead of integers. The affected function (there might be more) is

def mod_Ybus(Ybus, elements, bus, gen, baseMVA):
    # Add equivalent generator and grid admittances to Ybus matrix
    for element in elements.values():
        Ye = 0

        # 4th/6th order machines and converters
        if element.__module__ in ['pydyn.sym_order4', 'pydyn.sym_order6a', 'pydyn.sym_order6b', 'pydyn.vsc_average']:
            i = gen[element.gen_no,0]
            Ye = element.Yg

        # External grid
        if element.__module__ == 'pydyn.ext_grid':
            i = gen[element.gen_no,0]
            Ye = 1 / (1j * element.params['Xdp'])

        if Ye != 0:
            Ybus[i,i] = Ybus[i,i] + Ye

    # Add equivalent load admittance to Ybus matrix    
    Pl, Ql = bus[:, PD], bus[:, QD]
    for i in range(len(Pl)):
        S_load = (Pl[i] - 1j * Ql[i]) / baseMVA
        y_load = S_load / (bus[i, VM] ** 2)
        Ybus[i,i] = Ybus[i,i] + y_load

    return Ybus
susantoj commented 6 years ago

Hi Santiago, could you send through the model that you are trying to run? I've been using the WinPython 3.3 stack and PYPOWER 4.1.2. There may well be some forward compatibility problems, but I just want to first check if your model works on my stack.

SanPen commented 6 years ago

Hi,

I'm trying to run the default case 9. Nothing new.

The problem is solved by doing i = gen[element.gen_no,0].astype(int)

In general, every time an index is gathered, it shall be converted to integer so that the newer numpy versions accept it.

susantoj commented 6 years ago

Great, thanks for that.

liu2bao commented 5 years ago

Same issues. The index 'source_bus' in run_sim() is recognized as float