raytools.mapper

Mapper

class raytools.mapper.Mapper(dxyz=(0.0, 0.0, 1.0), sf=(1, 1), bbox=((0, 0), (1, 1)), aspect=None, name='mapper', origin=(0, 0, 0), jitterrate=1.0, uvz=0.0)[source]

Bases: object

translate between world and normalized UV space. do not use directly, instead use an inheriting class.

Parameters:
  • sf (tuple np.array, optional) – scale factor for each axis (array of length(2)

  • bbox (tuple np.array, optional) – bounding box for mapper shape (2, 2)

  • name (str, optional) – used for output file naming

property aspect
property dxyz

(float, float, float) central view direction

property bbox

bounding box of view

Type:

np.array of shape (2,2)

view2world(xyz)[source]

rotate vectors from view direction to world Z

world2view(xyz)[source]

rotate vectors from world Z to view direction

xyz2uv(xyz)[source]

transform from world xyz space to mapper UV space

uv2xyz(uv, stackorigin=False)[source]

transform from mapper UV space to world xyz

idx2uv(idx, shape, jitter=True)[source]
Parameters:
  • idx (flattened index)

  • shape – the shape to unravel into

  • jitter (bool, optional) – randomly offset coordinates within grid

Returns:

uv – uv coordinates

Return type:

np.array

static uv2idx(uv, shape)[source]
xyz2vxy(xyz)[source]

transform from world xyz to view image space (2d)

vxy2xyz(xy, stackorigin=False)[source]

transform from view image space (2d) to world xyz

framesize(res)[source]
pixels(res, jitter=0.0)[source]

generate pixel coordinates for image space

pixelrays(res, jitter=0.0)[source]

world xyz coordinates for pixels in view image space

ray2pixel(xyz, res, integer=True)[source]

world xyz to pixel coordinate

pixel2ray(pxy, res)[source]

pixel coordinate to world xyz vector

pixel2omega(pxy, res)[source]

pixel area

in_view(vec, indices=True)[source]

generate mask for vec that are in the field of view

header(**kwargs)[source]
init_img(res=512, jitter=0.0, **kwargs)[source]

Initialize an image array with vectors and mask

Parameters:
  • res (int, optional) – image array resolution

  • jitter (float, optional) – pixel jitter rate

  • kwargs – passed to self.header

Returns:

  • img (np.array) – zero array of shape (res, res)

  • vecs (np.array) – direction vectors corresponding to each pixel (img.size, 3)

  • mask (np.array) – indices of flattened img that are in view

  • mask2 (np.array None) –

    if ViewMapper has inverse, mask for opposite view, usage:

    add_to_img(img, vecs[mask], mask)
    add_to_img(img[res:], vecs[res:][mask2], mask2
    
  • header (str)

add_vecs_to_img(img, v, channels=(1, 0, 0), grow=0, **kwargs)[source]
plot(xyz, outf, res=1000, grow=1, **kwargs)[source]

AngularMixin

class raytools.mapper.angularmixin.AngularMixin[source]

Bases: object

includes overrides of transformation functions for angular type mapper classes. Inherit before raytools.mapper.Mapper eg:

NewMapper(AngularMixin, Mapper)

initialization of NewMapper must include declarations of:

self._viewangle = viewangle
self._chordfactor = chordfactor
self._ivm = ivm
xyz2uv(xyz)[source]

transform from world xyz space to mapper UV space

uv2xyz(uv, stackorigin=False)[source]

transform from mapper UV space to world xyz

xyz2vxy(xyz)[source]

transform from world xyz to view image space (2d)

vxy2xyz(xy, stackorigin=False)[source]

transform from view image space (2d) to world xyz

static framesize(res)[source]
pixelrays(res)[source]

world xyz coordinates for pixels in view image space

pixel2omega(pxy, res)[source]

pixel solid angle

in_view(vec, indices=True, tol=0.0)[source]

generate mask for vec that are in the field of view (up to 180 degrees) if view aspect is 2, only tests against primary view direction

header(pt=(0, 0, 0), viewproj='vta', **kwargs)[source]
init_img(res=512, pt=(0, 0, 0), features=1, viewproj='vta', indices=True, **kwargs)[source]

Initialize an image array with vectors and mask

Parameters:
  • res (int, optional) – image array resolution

  • pt (tuple, optional) – view point for image header

  • features (int, optional) – when greater than 1 initialize img array with N output channels

  • viewproj (str, optional) –

    output view projection chose from:

    angular: '[Aa]*', 'vta', 'fish*'
    shirley chiu: '[Uu]*', 'square'
    

Returns:

  • img (np.array) – zero array of shape (res*self.aspect, res)

  • vecs (np.array) – direction vectors corresponding to each pixel (img.size, 3)

  • mask (np.array) – indices of flattened img that are in view

  • mask2 (np.array None) – if features > 1, use mask 2 fro color images

  • header (str)

add_vecs_to_img(img, v, channels=(1, 0, 0), grow=0, fisheye=True, mask=None)[source]
property viewangle

view angle

property ivm

viewmapper for opposite view direction (in case of 360 degree view

ctheta(vec)[source]

cos(theta) (dot product) between view direction and vec

radians(vec)[source]

angle in radians betweeen view direction and vec

degrees(vec)[source]

angle in degrees betweeen view direction and vec

ViewMapper

class raytools.mapper.ViewMapper(dxyz=(0.0, 1.0, 0.0), viewangle=360.0, name='view', origin=(0, 0, 0), jitterrate=0.5)[source]

Bases: AngularMixin, Mapper

translate between world direction vectors and normalized UV space for a given view angle. pixel projection yields equiangular projection

Parameters:
  • dxyz (tuple, optional) – central view direction

  • viewangle (float, optional) – if < 180, the horizontal and vertical view angle, if greater, view becomes 360,180

property aspect
property dxyz

(float, float, float) central view direction

idx2uv(idx, shape, jitter=True)[source]
Parameters:
  • idx (flattened index)

  • shape – the shape to unravel into

  • jitter (bool, optional) – randomly offset coordinates within grid

Returns:

uv – uv coordinates

Return type:

np.array

transform_to(imarray, other, nearest=False)[source]

take an image arrray with an assumed projection of self and transform it to other

Parameters:
  • imarray (np.array) – 2-d or 3-d array with (features,x,y)

  • other (raytools.ViewMapper) – the destination view

  • nearest (bool) – disable linear interpolation and use nearest pixel sets the method= of scipy.interpolate.RegularGridInterpolator

Return type:

np.array