regrid

The regrid operator selects non-overlapping subarrays and performs aggregation on them.

Synopsis

regrid(array,grid_1 [, grid_2,...,grid_N],
           aggregate_call_1 [, aggregate_call_2,...,aggregate_call_N])

Summary

The regrid operator partitions the cells in the input array into blocks. For each block, regrid applies a specific aggregate operation over the value(s) of some attribute in each block.

Note that the chunk size does not have to be a multiple of the grid size, and the grids may span array chunks. However, processing is most efficient if chunk size is a multiple of the grid size, and grids do not span array chunks.

Inputs

The regrid operator takes the following arguments:

  • array: A source array with one or more attributes and one or more dimensions.
  • grid_n: A list of block sizes, one per dimension.
  • aggregate_call_n: One or more aggregate calls.

Example

To divide a 4×4 array into 4 equal partitions and calculates the average of each one, do the following. This process is known as spatial averaging.

  1. Create an array m4x4:

    AFL% CREATE ARRAY m4x4 <val:double>[i=0:3; j=0:3];


    The output is:

    Query was executed successfully
  2. Run this command, which increments val from 0 to 15:

    AFL% store(build (m4x4, i*4+j), m4x4);  


    The output is:

    {i,j} val
    {0,0} 0
    {0,1} 1
    {0,2} 2
    {0,3} 3
    {1,0} 4
    {1,1} 5
    {1,2} 6
    {1,3} 7
    {2,0} 8
    {2,1} 9
    {2,2} 10
    {2,3} 11
    {3,0} 12
    {3,1} 13
    {3,2} 14
    {3,3} 15
  3. Regrid m4x4 into four (2*2) partitions and find the average of each partition.

    AFL% regrid(m4x4, 2,2, avg(val) as Average); 


    The output is:

    {i,j} Average
    {0,0} 2.5
    {0,1} 4.5
    {1,0} 10.5
    {1,1} 12.5
  4. The regrid of 2x2 causes the following shape:

    0123
    4567
    891011
    12131415

    and the averages are computed as:

    (0 + 1 + 4 + 5) / 4  = 2.5

    (2 + 3 +  6 + 7) / 4 = 4.5

    (8 + 9 + 12 + 13) / 4 = 10.5

    (10 + 11 + 14 + 15) / 4 =  12.5

    which results in:

    2.54.5
    10.512.5


  5. Remove the m4x4 array

    AFL% remove(m4x4); 


    The output is:

    Query was executed successfully