Owa-epanet python wrapper setcurve() issue

Hi!

I’m using the SWIG generated python wrapper from the OWA repository. It is awesome, but I’m kind of stuck with the setcurve() method, which always ends up in the following unhandled exception raised by the SWIG generated method:

in method ‘setcurve’, argument 3 of type ‘double *’

I tried to pass directly the c_double_array object and the ctypes pointer to it (LP_c_double). Still no success.

Here is the code snippet about the conversion of my list of values (Xvalues and Yvalues) and the curve setting.

for curve in curves:
    Xvalues_dblptr = np.asarray(curve.Xvalues).ctypes.data_as(ctypes.POINTER(ctypes.c_double))
    Yvalues_dblptr = np.asarray(curve.Yvalues).ctypes.data_as(ctypes.POINTER(ctypes.c_double))
    idx = en.getcurveindex(ph=proj,id=curve.EpanetID)

    en.setcurve(ph=proj,index=idx,xValues=Xvalues_dblptr,yValues=Yvalues_dblptr,nPoints=len(curve.Xvalues))

I’m not familiar with SWIG typemaps, so I might have misunderstood something… Any ideas where did I go wrong?

Regards,
Attila Bibok

I have also run into this issue when using the setpattern method where a argument of ‘double *’ is required. I have found that using the setpatternvalue method instead and looping through each value works as it only requires an argument of type ‘double’.
You could try something similar with the setcurvevalue method.

Thanks for the answer! I did the same with the setcurvevalue() method to find a workaround, but I had to “initialize” my curves with placeholder values to have enough points to work with. It works but still…

This sounds like a simple issue with the SWIG type mapping. I would suggest opening an Issue on the repository to document this and discuss a fix.

I’ve gone ahead and fixed this - though I have not pushed the latest version to Pypi yet. Turned out to be a fairly simple access pattern that SWIG expects us to use, so I’ve added wrapper classes for int and double types.

Thank you for resolving that! Pypi is not an issue because I’m currently using it on windows, so I build it locally anyway.