def test1_sum_one_moving_block(self): """ """ vol = np.asarray( [1, 3, 4] ) one_block = Block([ slice(0, 2) ]) block_set = spanning_blocks(array_shape=vol.shape, block_shape=one_block.shape, step=1) R, lags = sum_one_moving_block(vol, one_block, block_set) R_real = (2.0, 1.0) lags_real = ([0], [1]) self.assertEqual(R, R_real) self.assertEqual(lags, lags_real)
def test2_sum_one_moving_block(self): """ """ vol = np.asarray( [[1, 2, 3], [4, 5, 6], [7, 8, 9]] ) one_block = Block([slice(0,2), slice(0, 2)]) block_set = spanning_blocks(array_shape=vol.shape, block_shape=one_block.shape, step=1) R, lags = sum_one_moving_block(vol, one_block, block_set) R_real = (10.0, 10.0, 10.0, 10.0) lags_real = ([0, 0], [0, 1], [1, 0], [1, 1]) self.assertEqual(R, R_real) self.assertEqual(lags, lags_real)
def sum_one_moving_block(vol, center_block, block_set=None): """Find correlation between one block and all other spanning blocks for the array """ # set params for summation array_shape = vol.shape ndim = len(vol.shape) block_shape = center_block.shape step = 1 # Find spanning blocks if necessary if not block_set: block_set = spanning_blocks(array_shape=array_shape, block_shape=block_shape, step=1) # find correlation value and lag values for each R, lags = zip(*map(_sum_two_blocks, block_set, repeat(center_block, len(block_set)), repeat(vol, len(block_set)))) return R, lags