Question

Quick Test of Hub Transformer

  • 1 December 2017
  • 3 replies
  • 4 views

Userlevel 4
Badge +25

Hey folks,

If anyone has a couple of minutes to spare, could you do me a favour and test this transformer on the FME hub: https://hub.safe.com/transformers/spatialsorter

It should run to completion (and not fail in a Python error) and it should return output like this: https://www.screencast.com/t/kRP9ysTq3N (I ran it on the Parks training dataset, but it should work on any dataset).

Thanks. I've had problems where it works on one machine but not another. I thought I had it cracked, but the test workspace fails on the hub. I'd like to check if it's just the hub (or just linux) or if everyone has issues.

Mark


3 replies

Userlevel 2
Badge +17

Hi @Mark2AtSafe, with Python 3.x interpreter, it seems that the numeric values contained by a numpy.ndarray have to be cast to "int" or "float" values explicitly when you pass them to the FMEFeature.setAttribute method. Try this.

def processFeature(feature):
    curvenum = feature.getAttribute('SortPrecision')
    for i, s in enumerate(hilbert_curve(curvenum)):
        for j, v in enumerate(s):
            feature.setAttribute('_list2{%d}.sub{%d}' % (i, j), int(v))

In addition, the "numpy.ndenumerate" function could be used effectively here.

def processFeature(feature):
    curvenum = feature.getAttribute('SortPrecision')
    for (i, j), v in ndenumerate(hilbert_curve(curvenum)):
        feature.setAttribute('_list2{%d}.sub{%d}' % (i, j), int(v))

Hope this helps.

Userlevel 2
Badge +17

Hi @Mark2AtSafe, with Python 3.x interpreter, it seems that the numeric values contained by a numpy.ndarray have to be cast to "int" or "float" values explicitly when you pass them to the FMEFeature.setAttribute method. Try this.

def processFeature(feature):
    curvenum = feature.getAttribute('SortPrecision')
    for i, s in enumerate(hilbert_curve(curvenum)):
        for j, v in enumerate(s):
            feature.setAttribute('_list2{%d}.sub{%d}' % (i, j), int(v))

In addition, the "numpy.ndenumerate" function could be used effectively here.

def processFeature(feature):
    curvenum = feature.getAttribute('SortPrecision')
    for (i, j), v in ndenumerate(hilbert_curve(curvenum)):
        feature.setAttribute('_list2{%d}.sub{%d}' % (i, j), int(v))

Hope this helps.

For what it's worth, this implementation could increase the performance a bit.

 

spatialsorter-update-test-2.fmw

 

 

Userlevel 4
Badge +25

Hi @Mark2AtSafe, with Python 3.x interpreter, it seems that the numeric values contained by a numpy.ndarray have to be cast to "int" or "float" values explicitly when you pass them to the FMEFeature.setAttribute method. Try this.

def processFeature(feature):
    curvenum = feature.getAttribute('SortPrecision')
    for i, s in enumerate(hilbert_curve(curvenum)):
        for j, v in enumerate(s):
            feature.setAttribute('_list2{%d}.sub{%d}' % (i, j), int(v))

In addition, the "numpy.ndenumerate" function could be used effectively here.

def processFeature(feature):
    curvenum = feature.getAttribute('SortPrecision')
    for (i, j), v in ndenumerate(hilbert_curve(curvenum)):
        feature.setAttribute('_list2{%d}.sub{%d}' % (i, j), int(v))

Hope this helps.

Thank you Takashi! I implemented the int(v) part and it works fine now. I'm not going to try the other parts because now it is working I don't want to touch anything else!

 

Reply