raytraverse.translate

functions for translating between coordinate spaces and resolutions

raytraverse.translate.norm(v)[source]

normalize 2D array of vectors along last dimension

raytraverse.translate.norm1(v)[source]

normalize flat vector

raytraverse.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.

raytraverse.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.

raytraverse.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.

raytraverse.translate.xyz2skybin(xyz, side, tol=0, normalize=False)[source]
raytraverse.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

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

xyz coordinates to xy mapping of angular fisheye proejection

raytraverse.translate.tpnorm(thetaphi)[source]

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

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

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

raytraverse.translate.xyz2tp(xyz)[source]

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

raytraverse.translate.tp2uv(thetaphi)[source]

calculate UV from theta (0-pi), phi

raytraverse.translate.uv2tp(uv)[source]

calculate theta (0-pi), phi from UV

raytraverse.translate.aa2xyz(aa)[source]

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

raytraverse.translate.xyz2aa(xyz)[source]

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

raytraverse.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

raytraverse.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

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

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

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

angle in radians betweeen a and b

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

angle in degrees betweeen a and b

raytraverse.translate.uv2ij(uv, side, aspect=2)[source]
raytraverse.translate.uv2bin(uv, side)[source]
raytraverse.translate.bin2uv(bn, side, offset=0.5)[source]
raytraverse.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

raytraverse.translate.rmtx_elem(theta, axis=2, degrees=True)[source]
raytraverse.translate.rotate_elem(v, theta, axis=2, degrees=True)[source]
raytraverse.translate.rmtx_yp(v)[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)

raytraverse.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

raytraverse.translate.reflect(ray, normal, returnmasked=False)[source]
raytraverse.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

raytraverse.translate.calc_omega(vecs, pm)[source]

calculate area