mbedward / jaitools

Raster image processing for Java developers
17 stars 15 forks source link

Jiffle: enable list operations in scripts #109

Closed mbedward closed 11 years ago

mbedward commented 11 years ago

Original author: michael.bedward@gmail.com (June 15, 2011 12:34:14)

Jiffle has a number of stats functions such as mean, median, sdev, but they are pretty useless because there's no easy way at the moment of collecting values from an image to pass to the function (unless the number of values is small and you use a script variable for each value). It would be handy to support list operations in scripts.

Jiffle already has a list syntax used with one of the forms of foreach loops...

foreach ( z in { 1, 2, foo, bar } )

So it would be relatively easy to allow curly-bracket lists to be used in other contexts.

Original issue: http://code.google.com/p/jaitools/issues/detail?id=111

mbedward commented 11 years ago

From michael.bedward@gmail.com on June 15, 2011 12:34:15 Added list syntax to Jiffle grammar. Unit tests for assigning empty or initialized list to user var.

mbedward commented 11 years ago

From michael.bedward@gmail.com on June 15, 2011 12:34:16 Now have some unit tests where a list var is created with initial values and then passed to a stats function. Example: options { outside = 0; } z = [ src[0,-1], src, src[0,1] ]; dest = max(z);

Next we want a way of adding values to an existing list. I don't want to use class.member syntax. Could steal the "<<" operator from Ruby...

foo = []; foo << src; // appends value of src to list foo

Could also steal the c (concatenate) function from R... foo = c(foo, src);

Though perhaps it would be better to call it "concat"... foo = concat(foo, src); // appends value of src to list foo foo = concat(src, foo); // prepends value of src to list foo

Both concat and "<<" seem good to have, the latter being nicely concise. Example, 3x3 mean filter with Jiffle...

options { outside = null; } values = []; for ( dy in -1:1 ) { for ( dx in -1:1 ) { values << src[ dy, dx ]; } } dest = sum( values ) / 9;

mbedward commented 11 years ago

From michael.bedward@gmail.com on June 15, 2011 12:34:16 Append operator "<<" working. Unit test in jaitools.jiffle.runtime.ListTest, method appendWithOperator

On trunk (r1472)

mbedward commented 11 years ago

From michael.bedward@gmail.com on June 15, 2011 12:34:17 The "concat" function is working in unit tests. See aitools.jiffle.runtime.ListTest

On trunk (r1473)

mbedward commented 11 years ago

From michael.bedward@gmail.com on June 15, 2011 12:34:17 Basic lists are working well enough for pixel neighbourhood operations. Later we can add element indexing etc.

Closing this issue.