basic api approach, problem with C++ call signature

12 views
Skip to first unread message

John F. Burkhart

unread,
Feb 13, 2018, 10:13:01 AM2/13/18
to shyft
I'm trying to create a notebook following the test_region_model_stacks.py approach using the demo data from nea nidelva:

num_cells = cell_data.dimensions['cell'].size
for i in range(num_cells):
    print(i)
    gp = api.GeoPoint(x[i], y[i], z[i]) # recall, we extracted x,y,z above
#     gp = api.GeoPoint(500 + 1000.0 * i, 500.0, 500.0 * i / num_cells)
    cid = cell_data.variables['catchment_id'][i]
    cell_area = cell_data.variables['area'][i]
    # land fractions:
    glac = cell_data.variables['glacier-fraction'][i]
    lake = cell_data.variables['lake-fraction'][i]
    rsvr = cell_data.variables['reservoir-fraction'][i]
    frst = cell_data.variables['forest-fraction'][i]
    unsp = 1 - (glac + lake + rsvr + frst)
    
    land_cover_frac = api.LandTypeFractions(glac, lake, rsvr, frst, unsp)
    
    print(cid)
    print(cell_area)
    print(gp)
    print(glac, lake, rsvr, frst, unsp)
    print(type(land_cover_frac))
    rad_fx = 0.9
    geo_cell_data = api.GeoCellData(gp, cell_area, cid, rad_fx, land_cover_frac)
    cell_data_vector.append(geo_cell_data)
 I get the following error regarding the call signature when I try to instantiate the `api.GeoCellData` object, and I can't understand why. 

Any idea why the call signature is not correct? Is it the numpy.float64? vs. a plain float? Here is the output:

0
2305
209211.924181
GeoPoint(204843.73715373053,6994695.209048475,978.344970703125)
0.0 0.0 0.0 0.0 1.0
<class 'shyft.api._api.LandTypeFractions'>
---------------------------------------------------------------------------
ArgumentError                             Traceback (most recent call last)
<ipython-input-74-afaea9830170> in <module>()
     23     print(type(land_cover_frac))
     24     rad_fx = 0.9
---> 25     geo_cell_data = api.GeoCellData(gp, cell_area, cid, rad_fx, land_cover_frac)
     26 
     27     cell_data_vector.append(geo_cell_data)

ArgumentError: Python argument types in
    GeoCellData.__init__(GeoCellData, GeoPoint, numpy.float64, numpy.int32, float, LandTypeFractions)
did not match C++ signature:
    __init__(struct _object * __ptr64, struct shyft::core::geo_point mid_point, double area, int catchment_id)
    __init__(struct _object * __ptr64, struct shyft::core::geo_point mid_point, double area, int catchment_id, double radiation_slope_factor)
    __init__(struct _object * __ptr64, struct shyft::core::geo_point mid_point, double area, int catchment_id, double radiation_slope_factor, struct shyft::core::land_type_fractions land_type_fractions)
    __init__(struct _object * __ptr64, struct shyft::core::geo_point mid_point, double area, int catchment_id, double radiation_slope_factor, struct shyft::core::land_type_fractions land_type_fractions, struct shyft::core::routing_info routing_info)
    __init__(struct _object * __ptr64)


John F. Burkhart

unread,
Feb 13, 2018, 10:17:52 AM2/13/18
to shyft
Answering my own question. The issue is the use of a numpy.float64 and a numpy.int32. If I cast these to `float` and `int` when instantiating the `GeoCellData` class, all behaves as expected.

    geo_cell_data = api.GeoCellData(gp, float(cell_area), int(cid), rad_fx, land_cover_frac)
Reply all
Reply to author
Forward
0 new messages