raytools.translate

functions for translating between coordinate spaces and resolutions

raytools.translate.norm(v)[source]

normalize 2D array of vectors along last dimension

raytools.translate.norm1(v)[source]

normalize flat vector

raytools.translate.uv2xy(uv)[source]

translate from unit square (0,1),(0,1) to disk (x,y) http://psgraphics.blogspot.com/2011/01/improved-code-for-concentric -map.html.

raytools.translate.uv2xyz(uv, axes=(0, 1, 2), xsign=1)[source]

translate from 2 x unit square (0,2),(0,1) to unit sphere (x,y,z) http://psgraphics.blogspot.com/2011/01/improved-code-for-concentric -map.html.

raytools.translate.xyz2uv(xyz, normalize=False, axes=(0, 1, 2), flipu=False)[source]

translate from vector x,y,z (normalized) to u,v (0,2),(0,1) Shirley, Peter, and Kenneth Chiu. A Low Distortion Map Between Disk and Square. Journal of Graphics Tools, vol. 2, no. 3, Jan. 1997, pp. 45-52. Taylor and Francis+NEJM, doi:10.1080/10867651.1997.10487479.

raytools.translate.xyz2skybin(xyz, side, tol=0, normalize=False)[source]
raytools.translate.skybin2xyz(bn, side)[source]

generate source vectors from sky bins

Parameters:
  • bn (np.array) – bin numbers

  • side (int) – square side of discretization

Returns:

xyz – direction to center of sky patches

Return type:

np.array

raytools.translate.xyz2xy(xyz, axes=(0, 1, 2), flip=False)[source]

xyz coordinates to xy mapping of angular fisheye proejection

raytools.translate.tpnorm(thetaphi)[source]

normalize angular vector to 0-pi, 0-2pi

raytools.translate.tp2xyz(thetaphi, normalize=True)[source]

calculate x,y,z vector from theta (0-pi) and phi (0-2pi) RHS Z-up

raytools.translate.xyz2tp(xyz)[source]

calculate theta (0-pi), phi from x,y,z RHS Z-up

raytools.translate.aa2xyz(aa)[source]

calculate altitude (0-90), azimuth (-180,180) from xyz

raytools.translate.xyz2aa(xyz)[source]

calculate xyz from altitude (0-90), azimuth (-180,180)

raytools.translate.chord2theta(c)[source]

compute angle from chord on unit circle

Parameters:

c (float) – chord or euclidean distance between normalized direction vectors

Returns:

theta – angle captured by chord

Return type:

float

raytools.translate.theta2chord(theta)[source]

compute chord length on unit sphere from angle

Parameters:

theta (float) – angle

Returns:

c – chord or euclidean distance between normalized direction vectors

Return type:

float

raytools.translate.ctheta(a, b)[source]

cos(theta) (dot product) between a and b

raytools.translate.radians(a, b)[source]

angle in radians betweeen a and b

raytools.translate.degrees(a, b)[source]

angle in degrees betweeen a and b

raytools.translate.uv2ij(uv, side, aspect=2)[source]
raytools.translate.uv2bin(uv, side)[source]
raytools.translate.bin2uv(bn, side, offset=0.5)[source]
raytools.translate.resample(samps, ts=None, gauss=True, radius=None)[source]

simple array resampling. requires whole number multiple scaling.

Parameters:
  • samps (np.array) – array to resample along each axis

  • ts (tuple, optional) – shape of output array, should be multiple of samps.shape

  • gauss (bool, optional) – apply gaussian filter to upsampling

  • radius (float, optional) – when gauss is True, filter radius, default is the scale ratio - 1

Returns:

to resampled array

Return type:

np.array

raytools.translate.weighted_quantile(d, weights=None, q=0.5, t=0.0)[source]

calculate weighted quantiles on 1d data

Parameters:
  • d (np.array) – data (flattens array)

  • q (np.array) – quantiles (N,)

  • weights (np.array) – weights

  • t (float) – threshold for inclusion

Returns:

result – shape (N,)

Return type:

np.array

raytools.translate.weighted_median(d, weights=None, t=0.0)[source]

convinience function with different signature

raytools.translate.non_uniform_gaussian_filter(x, y, xr=None, sigma=None, sscale=1.0, bw=500, amethod='mean')[source]

apply a guassian filter to non-uniformly spaced data

Parameters:
  • x (np.array) – 1d source data (N,)

  • y (np.array) – data to smooth (M,N)

  • xr (np.array) – coordinates along x to resample (R,). if none, uses x directly

  • sigma (float) – if None applies scotts rule (x.size**0.2)

  • sscale (float) – extra factor to apply to sigma

  • bw (int) – 1/2 bandwidth for kernel (in # of samples) use for N > 10000

  • amethod (Union[str, np.array]) – averaging method, can be ‘mean’, ‘median’, or array like of quantiles. if more than one quantile y must contain only one feature

Returns:

mu – shape (M,), or (R,) if resample

Return type:

np.array

raytools.translate.rmtx_elem(theta, axis=2, degrees=True)[source]
raytools.translate.rotate_elem(v, theta, axis=2, degrees=True)[source]
raytools.translate.rmtx_yp(v, keepdims=False)[source]

generate a pair of rotation matrices to transform from vector v to z, enforcing a z-up in the source space and a y-up in the destination. If v is z, returns pair of identity matrices, if v is -z returns pair of 180 degree rotation matrices.

Parameters:

v (array-like of size (N, 3)) – the vector direction representing the starting coordinate space

Returns:

ymtx, pmtx – two rotation matrices to be premultiplied in order to reverse transform, swap order and transpose.

Return type:

(np.array, np.array)

Notes

if N is one: Forward: (pmtx@(ymtx@xyz.T)).T or np.einsum(“ij,kj,li->kl”, ymtx, xyz, pmtx) Backward: (ymtx.T@(pmtx.T@xyz.T)).T or np.einsum(“ji,kj,il-kl”, pmtx, nv, ymtx) else: Forward: np.einsum(“vij,vkj,vli->vkl”, ymtx, xyz, pmtx) Backward: np.einsum(“vji,vkj,vil-vkl”, pmtx, nv, ymtx)

raytools.translate.cull_vectors(vecs, tol)[source]

return mask to cull duplicate vectors within tolerance

Parameters:
  • vecs (Union[cKDTree, np.array]) – prebuilt KDTree or np.array to build a new one. culling keeps first vector in array used to build tree.

  • tol (float) – tolerance for culling

Returns:

boolean mask of vecs (or vecs.data) to cull vectors

Return type:

np.array

raytools.translate.reflect(ray, normal, returnmasked=False)[source]
raytools.translate.simple_take(ar, *slices, axes=None)[source]

consistent array indexing with arrays, lists, tuples and slices

Parameters:
  • ar (np.array) – the multidimensional arary to index

  • slices (tuple) – if sequence, takes those indices along axis, if None, take whole dimension, if slice, applies to index array before take

  • axes (Union[Sequence, int], optional) – when None, slices are automatically taken starting on axes 0. Use this argument to only operate on a subset of dimensions.

Returns:

matches ndims of ar

Return type:

np.array