Exemple #1
0
def test_mean_transfer_function_cpu():
    # numpy case
    numpy_agg = xr.DataArray(data_random)
    numpy_mean = mean(numpy_agg)
    general_output_checks(numpy_agg, numpy_mean)

    # dask + numpy case
    dask_numpy_agg = xr.DataArray(da.from_array(data_random, chunks=(3, 3)))
    dask_numpy_mean = mean(dask_numpy_agg)
    general_output_checks(dask_numpy_agg, dask_numpy_mean)

    # both output same results
    np.testing.assert_allclose(numpy_mean.data,
                               dask_numpy_mean.data.compute(),
                               equal_nan=True)
Exemple #2
0
def test_mean_transfer_function_cpu():
    # numpy case
    numpy_agg = xr.DataArray(data_random)
    numpy_mean = mean(numpy_agg)
    assert isinstance(numpy_mean.data, np.ndarray)

    # dask + numpy case
    dask_numpy_agg = xr.DataArray(da.from_array(data_random, chunks=(3, 3)))
    dask_numpy_mean = mean(dask_numpy_agg)
    assert isinstance(dask_numpy_mean.data, da.Array)

    # both output same results
    assert np.isclose(
        numpy_mean, dask_numpy_mean.compute(), equal_nan=True
    ).all()
    assert numpy_agg.shape == numpy_mean.shape
def test_mean_transfer_function():
    da = xr.DataArray(data_random)

    # add crs for tests
    da = _add_EPSG4326_crs_to_da(da)

    da_mean = mean(da)
    assert da.shape == da_mean.shape

    # crs tests
    assert da_mean.attrs == da.attrs
    for coord in da.coords:
        assert np.all(da_mean[coord] == da[coord])

    # Overall mean value should be the same as the original array.
    # Considering the default behaviour to 'mean' is to pad the borders
    # with zeros, the mean value of the filtered array will be slightly
    # smaller (considering 'data_random' is positive).
    assert da_mean.mean() <= data_random.mean()

    # And if we pad the borders with the original values, we should have a
    # 'mean' filtered array with _mean_ value very similar to the original one.
    da_mean[0, :] = data_random[0, :]
    da_mean[-1, :] = data_random[-1, :]
    da_mean[:, 0] = data_random[:, 0]
    da_mean[:, -1] = data_random[:, -1]
    assert abs(da_mean.mean() - data_random.mean()) < 10**-3
Exemple #4
0
def test_mean_transfer_function_gpu_equals_cpu():

    import cupy

    # cupy case
    cupy_agg = xr.DataArray(cupy.asarray(data_random))
    cupy_mean = mean(cupy_agg)
    assert isinstance(cupy_mean.data, cupy.ndarray)

    # numpy case
    numpy_agg = xr.DataArray(data_random)
    numpy_mean = mean(numpy_agg)

    assert np.isclose(numpy_mean, cupy_mean.data.get(), equal_nan=True).all()

    # dask + cupy case not implemented
    dask_cupy_agg = xr.DataArray(
        da.from_array(cupy.asarray(data_random), chunks=(3, 3))
    )
    with pytest.raises(NotImplementedError) as e_info:
        mean(dask_cupy_agg)
        assert e_info
Exemple #5
0
def test_mean_transfer_function_gpu_equals_cpu():

    import cupy

    # cupy case
    cupy_agg = xr.DataArray(cupy.asarray(data_random))
    cupy_mean = mean(cupy_agg)
    general_output_checks(cupy_agg, cupy_mean)

    # numpy case
    numpy_agg = xr.DataArray(data_random)
    numpy_mean = mean(numpy_agg)

    np.testing.assert_allclose(numpy_mean.data,
                               cupy_mean.data.get(),
                               equal_nan=True)

    # dask + cupy case not implemented
    dask_cupy_agg = xr.DataArray(
        da.from_array(cupy.asarray(data_random), chunks=(3, 3)))
    with pytest.raises(NotImplementedError) as e_info:
        mean(dask_cupy_agg)
        assert e_info
Exemple #6
0
trees += bump(W,
              H,
              count=T // 3,
              height_func=partial(heights,
                                  src=src,
                                  src_range=(1700, 2000),
                                  height=5))

tree_colorize = trees.copy()
tree_colorize.data[tree_colorize.data == 0] = np.nan

LAND_CONSTANT = 50.0

water = terrain.copy()
water.data = np.where(water.data > 0, LAND_CONSTANT, 0)
water = mean(water, passes=50, excludes=[LAND_CONSTANT])
water.data[water.data == LAND_CONSTANT] = np.nan


def create_map(azimuth):

    global cvs
    global terrain
    global water
    global trees

    img = stack(
        shade(terrain, cmap=Elevation, how='linear'),
        shade(water, cmap=['aqua', 'white']),
        shade(hillshade(terrain + trees, azimuth=azimuth),
              cmap=['black', 'white'],