Smoothing data from within Python script

Hi,

I was hoping to use the lag CHOP to smooth some live data being manipulated inside a Python callback. So far I’ve tried writing to the lag CHOP like so op(‘lag’)[0] = jumpy_live_data, but I always get an “Object does not support item assignment” error.

-What would the correct way of generating an input for a CHOP and then reading its output from a Python script be?
-Is there a better way of smoothing live data from within a Python script in TD? I could always implement a moving average but figured there must be a faster more TD’esque way of doing this…

FWIW I’m calculating a TUIO ID’s heading by comparing its previous position to its current position. This works OK but the resulting angle value jumps around a lot and I’d like to smooth this out.

Thanks!

You can’t set vals in CHOPs sadly. You can however, set a val in a table, convert the table to CHOPs, and then apply your lag.

If it’s only a single val you could write this to a constant CHOP with:

op( 'your_constant_chop' ).par.value0

script way:

  • do your calculation in a Script CHOP, append a Lag CHOP, add another Script CHOP

CHOPs:

  • it sounds like you might be able to do most of the calculation in CHOPs? A Slope CHOP might come in handy here

Cheers
Markus