xrspatial.perlin.perlin#
- xrspatial.perlin.perlin(agg: xarray.core.dataarray.DataArray, freq: tuple = (1, 1), seed: int = 5, name: str = 'perlin') xarray.core.dataarray.DataArray [source]#
Generate perlin noise aggregate.
- Parameters
agg (xr.DataArray) – 2D array of size width x height, will be used to determine height/ width and which platform to use for calculation.
freq (tuple, default=(1,1)) – (x, y) frequency multipliers.
seed (int, default=5) – Seed for random number generator.
- Returns
perlin_agg – 2D array of perlin noise values.
- Return type
xarray.DataArray
References
Paul Panzer: https://stackoverflow.com/questions/42147776/producing-2d-perlin-noise-with-numpy # noqa
ICA: http://www.mountaincartography.org/mt_hood/pdfs/nighbert_bump1.pdf # noqa
Examples
>>> import numpy as np >>> import xarray as xr >>> from xrspatial import perlin >>> W = 4 >>> H = 3 >>> data = np.zeros((H, W), dtype=np.float32) >>> raster = xr.DataArray(data, dims=['y', 'x']) >>> perlin_noise = perlin(raster) >>> print(perlin_noise) <xarray.DataArray 'perlin' (y: 3, x: 4)> array([[0.39268944, 0.27577767, 0.01621884, 0.05518942], [1. , 0.8229485 , 0.2935367 , 0. ], [1. , 0.8715414 , 0.41902685, 0.02916668]], dtype=float32) # noqa Dimensions without coordinates: y, x