bordado.random_coordinates

bordado.random_coordinates#

bordado.random_coordinates(region, size, *, rng=None, non_dimensional_coords=None)[source]#

Generate the coordinates for a uniformly random scatter of points.

The points are drawn from a uniform distribution, independently for each dimension of the given region.

Parameters:
regiontuple = (W, E, S, N, …)

The boundaries of a given region in Cartesian or geographic coordinates. Should have a lower and an upper boundary for each dimension of the coordinate system.

sizeint

The number of points to generate.

rngnumpy.random.Generator or int

A random number generator (RNG) used to generate the coordinates. If an integer is given, it will be used as a seed for numpy.random.default_rng which will then be used as the generator. If a numpy.random.Generator is given, it will be used. If None is given, default_rng will be used with no seed to create a generator (resulting in different numbers with each run). Use a seed to make sure computations are reproducible. Default is None.

non_dimensional_coordsNone, scalar, or tuple of scalars

If not None, then value(s) of extra non-dimensional coordinates (coordinates that aren’t part of the sample dimensions, like height for a lat/lon grid). Will generate extra coordinate arrays from these values with the same shape of the final coordinates and the constant value given here. Use this to generate arrays of constant heights or times, for example, which might be needed to accompany a set of points.

Returns:
coordinatestuple of arrays

Arrays with coordinates of each point in the grid. Each array contains values for a dimension in an order compatible with region followed by any extra dimensions given in non_dimensional_coords. All arrays will have the specified size.

Examples

We’ll use a seed value to ensure that the same will be generated every time:

>>> easting, northing = random_coordinates((0, 10, -2, -1), 4, rng=0)
>>> print(', '.join(['{:.4f}'.format(i) for i in easting]))
6.3696, 2.6979, 0.4097, 0.1653
>>> print(', '.join(['{:.4f}'.format(i) for i in northing]))
-1.1867, -1.0872, -1.3934, -1.2705
>>> easting, northing, height = random_coordinates(
...     (0, 10, -2, -1), 4, rng=0, non_dimensional_coords=12
... )
>>> print(height)
[12. 12. 12. 12.]
>>> easting, northing, height, time = random_coordinates(
...     (0, 10, -2, -1), 4, rng=0, non_dimensional_coords=[12, 1986])
>>> print(height)
[12. 12. 12. 12.]
>>> print(time)
[1986. 1986. 1986. 1986.]

We’re not limited to 2 dimensions:

>>> easting, northing, up = random_coordinates(
...     (0, 10, -2, -1, 0.1, 0.2), 4, rng=0,
... )
>>> print(', '.join(['{:.4f}'.format(i) for i in easting]))
6.3696, 2.6979, 0.4097, 0.1653
>>> print(', '.join(['{:.4f}'.format(i) for i in northing]))
-1.1867, -1.0872, -1.3934, -1.2705
>>> print(', '.join(['{:.4f}'.format(i) for i in up]))
0.1544, 0.1935, 0.1816, 0.1003