verde.line_coordinates

Contents

verde.line_coordinates#

verde.line_coordinates(start, stop, size=None, spacing=None, adjust='spacing', pixel_register=False)[source]#

Generate evenly spaced points between two values.

Able to handle either specifying the number of points required (size) or the size of the interval between points (spacing). If using size, the output will be similar to using numpy.linspace. When using spacing, if the interval is not divisible by the desired spacing, either the interval or the spacing will have to be adjusted. By default, the spacing will be rounded to the nearest multiple. Optionally, the stop value can be adjusted to fit the exact spacing given.

Parameters:
startfloat

The starting value of the sequence.

stopfloat

The end value of the sequence.

numint or None

The number of points in the sequence. If None, spacing must be provided.

spacingfloat or None

The step size (interval) between points in the sequence. If None, size must be provided.

adjust{‘spacing’, ‘region’}

Whether to adjust the spacing or the interval/region if required. Ignored if size is given instead of spacing. Defaults to adjusting the spacing.

pixel_registerbool

If True, the points will refer to the center of each interval (pixel) instead of the boundaries. In practice, this means that there will be one less element in the sequence if spacing is provided. If size is provided, the requested number of elements is respected. Default is False.

Returns:
sequencearray

The generated sequence of values.

Examples

>>> values = line_coordinates(0, 5, spacing=2.5)
>>> print(values.shape)
(3,)
>>> print(values)
[0.  2.5 5. ]
>>> print(line_coordinates(0, 10, size=5))
[ 0.   2.5  5.   7.5 10. ]
>>> print(line_coordinates(0, 10, spacing=2.5))
[ 0.   2.5  5.   7.5 10. ]

The spacing is adjusted to fit the interval by default but this can be changed to adjusting the interval/region instead:

>>> print(line_coordinates(0, 10, spacing=2.4))
[ 0.   2.5  5.   7.5 10. ]
>>> print(line_coordinates(0, 10, spacing=2.4, adjust="region"))
[0.  2.4 4.8 7.2 9.6]
>>> print(line_coordinates(0, 10, spacing=2.6))
[ 0.   2.5  5.   7.5 10. ]
>>> print(line_coordinates(0, 10, spacing=2.6, adjust="region"))
[ 0.   2.6  5.2  7.8 10.4]

Optionally, return values at the center of the intervals instead of their boundaries:

>>> print(line_coordinates(0, 10, spacing=2.5, pixel_register=True))
[1.25 3.75 6.25 8.75]

Notice that this produces one value less than the non-pixel registered version. If using size instead of spacing, the number of values will be size regardless and the spacing will therefore be different from the non-pixel registered version:

>>> print(line_coordinates(0, 10, size=5, pixel_register=True))
[1. 3. 5. 7. 9.]