# Random grids#

Because sometimes you just want some random data.

This module implements 2D fractal noise, combining one or more octaves of Perlin noise.

import gio

g = gio.generate_random_surface(200, res=3, octaves=3)

g

<xarray.DataArray (i: 204, j: 204)>
array([[ 0.        , -0.05736413, -0.11728367, ..., -0.11920205,
-0.08226758, -0.04223049],
[ 0.01317427, -0.04415499, -0.10391634, ..., -0.1535234 ,
-0.11710962, -0.07728829],
[ 0.0252488 , -0.03198195, -0.09153055, ..., -0.18582673,
-0.14969093, -0.10998765],
...,
[ 0.05144513,  0.04374787,  0.03244042, ...,  0.06511937,
0.06545176,  0.06280169],
[ 0.03661664,  0.02913997,  0.01798883, ...,  0.04790077,
0.04768927,  0.04426351],
[ 0.01900629,  0.01164235,  0.00067529, ...,  0.0296427 ,
0.0290597 ,  0.02524733]])
Coordinates:
* i        (i) int64 0 1 2 3 4 5 6 7 8 ... 195 196 197 198 199 200 201 202 203
* j        (j) int64 0 1 2 3 4 5 6 7 8 ... 195 196 197 198 199 200 201 202 203
Attributes:
source:   gio.random

We can plot this thing:

g.plot()

<matplotlib.collections.QuadMesh at 0x7f3114fe9700>


The noise does not have to be isotropic:

g = gio.generate_random_surface(200, res=(2, 5), octaves=3)

g.plot()

<matplotlib.collections.QuadMesh at 0x7f31104a16d0>


Note that the size and res can both be tuples.

The size will be ‘at least’ the specified size in that dimension: it might have to be larger for the algorithm to work.