예제 #1
0
def test_focal_stats_dask_numpy(data_focal_stats):
    data, kernel, expected_result = data_focal_stats
    dask_numpy_agg = create_test_raster(data, backend='dask')
    dask_numpy_focalstats = focal_stats(dask_numpy_agg, kernel)
    general_output_checks(dask_numpy_agg,
                          dask_numpy_focalstats,
                          verify_attrs=False,
                          expected_results=expected_result)
예제 #2
0
def test_focal_stats_gpu(data_focal_stats):
    data, kernel, expected_result = data_focal_stats
    cupy_agg = create_test_raster(data, backend='cupy')
    cupy_focalstats = focal_stats(cupy_agg, kernel)
    general_output_checks(cupy_agg,
                          cupy_focalstats,
                          verify_attrs=False,
                          expected_results=expected_result)
예제 #3
0
def test_focal_stats_cpu():
    data = np.arange(16).reshape(4, 4)
    numpy_agg = xr.DataArray(data)
    dask_numpy_agg = xr.DataArray(da.from_array(data, chunks=(3, 3)))

    cellsize = (1, 1)
    kernel = circle_kernel(*cellsize, 1.5)

    expected_results = np.asarray([
        # mean
        [[1.66666667, 2., 3., 4.], [4.25, 5., 6., 6.75],
         [8.25, 9., 10., 10.75], [11., 12., 13., 13.33333333]],
        # max
        [[4., 5., 6., 7.], [8., 9., 10., 11.], [12., 13., 14., 15.],
         [13., 14., 15., 15.]],
        # min
        [[0., 0., 1., 2.], [0., 1., 2., 3.], [4., 5., 6., 7.],
         [8., 9., 10., 11.]],
        # range
        [[4., 5., 5., 5.], [8., 8., 8., 8.], [8., 8., 8., 8.],
         [5., 5., 5., 4.]],
        # std
        [[1.69967317, 1.87082869, 1.87082869, 2.1602469],
         [2.86138079, 2.60768096, 2.60768096, 2.86138079],
         [2.86138079, 2.60768096, 2.60768096, 2.86138079],
         [2.1602469, 1.87082869, 1.87082869, 1.69967317]],
        # var
        [[2.88888889, 3.5, 3.5, 4.66666667], [8.1875, 6.8, 6.8, 8.1875],
         [8.1875, 6.8, 6.8, 8.1875], [4.66666667, 3.5, 3.5, 2.88888889]],
        # sum
        [[5., 8., 12., 12.], [17., 25., 30., 27.], [33., 45., 50., 43.],
         [33., 48., 52., 40.]]
    ])

    numpy_focalstats = focal_stats(numpy_agg, kernel)
    general_output_checks(numpy_agg,
                          numpy_focalstats,
                          verify_attrs=False,
                          expected_results=expected_results)
    assert numpy_focalstats.ndim == 3

    dask_numpy_focalstats = focal_stats(dask_numpy_agg, kernel)
    general_output_checks(dask_numpy_agg,
                          dask_numpy_focalstats,
                          verify_attrs=False,
                          expected_results=expected_results)
예제 #4
0
def test_focal_stats_numpy(data_focal_stats):
    data, kernel, expected_result = data_focal_stats
    numpy_agg = create_test_raster(data)
    numpy_focalstats = focal_stats(numpy_agg, kernel)
    general_output_checks(numpy_agg,
                          numpy_focalstats,
                          verify_attrs=False,
                          expected_results=expected_result)
    assert numpy_focalstats.ndim == 3
예제 #5
0
 def time_focal_stats(self, nx, kernelsize, type):
     focal_stats(self.agg, self.kernel)