xrspatial.bump.bump

xrspatial.bump.bump(width: int, height: int, count: Optional[int] = None, height_func=None, spread: int = 1)xarray.core.dataarray.DataArray[source]

Generate a simple bump map to simulate the appearance of land features. Using a user-defined height function, determines at what elevation a specific bump height is acceptable. Bumps of number “count” are applied over the area “width” x “height”.

width: int

Total width in pixels of the image.

height: int

Total height, in pixels, of the image.

count: int (defaults: w * h / 10)

Number of bumps to generate.

height_func: function which takes x, y and returns a height value

Function used to apply varying bump heights to different elevations.

spread: tuple boundaries (default = 1)

xarray.DataArray, 2D DataArray of calculated bump heights.

Algorithm References:

Imports >>> import numpy as np >>> import datashader as ds >>> from datashader.transfer_functions import shade

Generate Terrain >>> from xrspatial import generate_terrain

>>> W = 800
>>> H = 600
>>> cvs = ds.Canvas(plot_width = W, plot_height = H,
                        x_range = (-20e6, 20e6), y_range = (-20e6, 20e6))
>>> terrain = generate_terrain(canvas=cvs)

Create Height Function >>> from functools import partial >>> from xrspatial import bump

>>> def heights(locations, src, src_range, height=20):
>>>     num_bumps = locations.shape[0]
>>>     out = np.zeros(num_bumps, dtype=np.uint16)
>>>     for r in range(0, num_bumps):
>>>         loc = locations[r]
>>>         x = loc[0]
>>>         y = loc[1]
>>>         val = src[y, x]
>>>         if val >= src_range[0] and val < src_range[1]:
>>>             out[r] = height
>>>    return out

Create Bump Map >>> bump_count = 10000 >>> src = terrain.data >>> bumps = bump(W, H, count = bump_count,

height_func = partial(heights,

src = src, src_range = (1000, 1300), height = 5))

>>> bumps += bump(W, H, count = bump_count//2,
                 height_func = partial(heights,
                                       src = src,
                                       src_range = (1300, 1700),
                                       height = 20))
>>> print(bumps)
<xarray.DataArray (y: 600, x: 800)>
array([[0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.],
       ...,
       [0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.]])
Dimensions without coordinates: y, x
.. attribute:: res

1

Terrrain Example: