Relative position of minimum value using window


Good morning,

I have a 2D array with a single numeric attribute. From this array I neeed to produce a new array containing the minimum value of the 8 surrounding cells and also the minimum’s realtive position. I know the minimum value can be obtained using the “window” function but I do not know how to get the relative position. By relative position I mean two integers which I can add to the current dimensions in order to obtain the dimensions of the minimum value respect to the current cell.

For example, the 2D array is something like this:

1     2     3
4     5     6
7     8     9

And the expected results are (min, rel_row, rel_col):

(2,  0, +1)     (1, +0, -1)     (2,  0, -1)
(1, -1, +0)     (1, -1, -1)     (2, -1, -1)
(4, -1, +0)     (4, -1, -1)     (5, -1, -1)

What is the best way to do this in SciDB?




Yes this is an interesting case for position-aware aggregates; an idea that’s been in the back of our minds for some time. We’ve seen some use cases for this in some recent finance projects. In order to get this to work, we’ll need to add positional information to the SciDB aggregate API. I can see that happening eventually, but no plans in the immediate future.

For your request, the desired window calculation is special in excluding the central cell. That’s also not something SciDB’s window does at the moment.

I think the best case workaround for this would be to define your own datatype that combines [x,y,value] into a triplet, then define a custom aggregate over that type (might as well also return a triplet) and then run this aggregate in window(). Storing data in the triplet form wouldn’t be efficient - so just apply the triplet type as part of the query…