Numerical tools
Generate all combinations of grid point coordinates from x and y axes
grid points defined by x and y axes. The x coordinate will vary the fastest to match the way 2D numpy arrays are laid out by default (‘C’ order). That way, the x and y coordinates will match a corresponding 2D array A when flattened (A.flat[:] or A.reshape(-1))
Example
x = [1, 2, 3] y = [10, 20]
Ensure that sequence is a numeric array.
unaltered If not, an attempt is made to convert it to a numeric array
that a 0-dim array DOES NOT HAVE A LENGTH UNDER numpy.
A: String. Array of ASCII values (numpy can’t handle this)
If not, let numeric package decide. typecode will always be one of num.float, num.int, etc.
that numpy.array(A, dtype) will sometimes copy. Use ‘copy=False’ to copy only when required.
This function is necessary as array(A) can cause memory overflow.
Approximation to ERF
from: http://www.cs.princeton.edu/introcs/21function/ErrorFunction.java.html Implements the Gauss error function. erf(z) = 2 / sqrt(pi) * integral(exp(-t*t), t = 0..z)
Fractional error in math formula less than 1.2 * 10 ^ -7. although subject to catastrophic cancellation when z in very close to 0 from Chebyshev fitting formula for erf(z) from Numerical Recipes, 6.2
Source: http://stackoverflow.com/questions/457408/ is-there-an-easily-available-implementation-of-erf-for-python
Convert geotransform to coordinate axes
top left y, rotation, n-s pixel resolution).
nx: Number of cells in the w-e direction
ny: Number of cells in the n-s direction
Return two vectors (longitudes and latitudes) representing the grid defined by the geotransform.
The values are offset by half a pixel size to correspond to pixel registration.
I.e. If the grid origin (top left corner) is (105, 10) and the resolution is 1 degrees in each direction, then the vectors will take the form
longitudes = [100.5, 101.5, ..., 109.5] latitudes = [0.5, 1.5, ..., 9.5]
Convert grid data to point data
Cumulative Log Normal Distribution Function
- Args:
- x: scalar or array of real numbers
- mu: Median (exp(mean of log(x)). Default 1
- sigma: Log normal standard deviation. Default 1
- Returns:
- An approximation of the cdf of the normal
- Note:
- CDF of the normal distribution is defined as
rac12 [1 + erf( rac{x - mu}{sigma sqrt{2}})], x in R
Numpy allclose function which allows NaN
Cumulative Normal Distribution Function
- Args:
- x: scalar or array of real numbers
- mu: Mean value. Default 0
- sigma: Standard deviation. Default 1
- Returns:
- An approximation of the cdf of the normal
- Note:
- CDF of the normal distribution is defined as
rac12 [1 + erf( rac{x - mu}{sigma sqrt{2}})], x in R
This module forms part of the InaSAFE tool.