bordado.rescale_coordinates

bordado.rescale_coordinates#

bordado.rescale_coordinates(coordinates, region)[source]#

Rescale the coordinate values to fit the given region.

Linearly transforms the input coordinates so that their minimum and maximum values match the lower and upper bounds of the provided region. The scaling is applied independently to each coordinate.

Parameters:
coordinatestuple = (easting, northing, …)

Tuple of arrays with the coordinates of each point. Should be in an order compatible with the order of boundaries in region. Arrays can be Python lists. Arrays can be of any shape but must all have the same shape.

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

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

Returns:
rescaled_coordinatestuple

A tuple of arrays containing the rescaled coordinates. The returned arrays will have the same shape as the input coordinate arrays.

Examples

Let’s demonstrate first using a single coordinate array. The coordinates must be specified as a tuple of arrays.

>>> import bordado as bd
>>> coordinates = ([0, 5, 10],)

These values can be stretched to a new range by providing a region like so:

>>> rescaled_coordinates = rescale_coordinates(coordinates, [0, 100])
>>> print(rescaled_coordinates)
(array([  0.,  50., 100.]),)

We can also translate coordinates. Note that if the original and new regions share the same length, the rescaling simply acts as a pure translation of the points:

>>> region = [10, 20]
>>> rescaled_coordinates = rescale_coordinates(coordinates, region)
>>> print(rescaled_coordinates)
(array([10., 15., 20.]),)

This also works for 2D coordinate arrays (or any number of dimensions). Let’s generate coordinates for a 2D grid:

>>> coordinates = bd.grid_coordinates(region=(0, 10, 0, 20), shape=(3, 3))
>>> print(coordinates[0])
[[ 0.  5. 10.]
 [ 0.  5. 10.]
 [ 0.  5. 10.]]
>>> print(coordinates[1])
[[ 0.  0.  0.]
 [10. 10. 10.]
 [20. 20. 20.]]

Rescale the generated coordinates to a new target region happens for each coordinate independently:

>>> rescaled = rescale_coordinates(coordinates, (0, 100, 0, 50))
>>> print(rescaled[0])
[[  0.  50. 100.]
 [  0.  50. 100.]
 [  0.  50. 100.]]
>>> print(rescaled[1])
[[ 0.  0.  0.]
 [25. 25. 25.]
 [50. 50. 50.]]