def test_concatenate_chunks(): """Test chunk concatenation for correct results.""" from pyresample.gradient import _concatenate_chunks # 1-band image chunks = { (0, 0): [np.ones((1, 5, 4)), np.zeros((1, 5, 4))], (1, 0): [np.zeros((1, 5, 2))], (1, 1): [np.full((1, 3, 2), 0.5)], (0, 1): [np.full((1, 3, 4), -1)] } res = _concatenate_chunks(chunks).compute(scheduler='single-threaded') assert np.all(res[:5, :4] == 1.0) assert np.all(res[:5, 4:] == 0.0) assert np.all(res[5:, :4] == -1.0) assert np.all(res[5:, 4:] == 0.5) assert res.shape == (8, 6) # 3-band image chunks = { (0, 0): [np.ones((3, 5, 4)), np.zeros((3, 5, 4))], (1, 0): [np.zeros((3, 5, 2))], (1, 1): [np.full((3, 3, 2), 0.5)], (0, 1): [np.full((3, 3, 4), -1)] } res = _concatenate_chunks(chunks).compute(scheduler='single-threaded') assert np.all(res[:, :5, :4] == 1.0) assert np.all(res[:, :5, 4:] == 0.0) assert np.all(res[:, 5:, :4] == -1.0) assert np.all(res[:, 5:, 4:] == 0.5) assert res.shape == (3, 8, 6)
def test_concatenate_chunks_stack_calls(dask_da): """Test that stacking is called the correct times in chunk concatenation.""" from pyresample.gradient import _concatenate_chunks chunks = { (0, 0): [np.ones((1, 5, 4)), np.zeros((1, 5, 4))], (1, 0): [np.zeros((1, 5, 2))], (1, 1): [np.full((1, 3, 2), 0.5)], (0, 1): [np.full((1, 3, 4), -1)] } _ = _concatenate_chunks(chunks) dask_da.stack.assert_called_once_with(chunks[(0, 0)], axis=-1) dask_da.nanmax.assert_called_once() assert 'axis=2' in str(dask_da.concatenate.mock_calls[-1])