raytraverse.sampler¶
draw¶
wavelet and associated probability functions.
Sampler¶
-
class
raytraverse.sampler.
Sampler
(scene, engine=<class 'raytraverse.renderer.rtrace.Rtrace'>, idres=5, fdres=9, accuracy=1.0, srcn=1, stype='generic', srcdef=None, bands=1, engine_args='', nproc=None, **kwargs)[source]¶ Bases:
object
wavelet based sampling class
- Parameters
scene (raytraverse.scene.Scene) – scene class containing geometry and formatter compatible with engine
engine (type, optional) – should inherit from raytraverse.renderer.Renderer
idres (int, optional) – initial direction resolution (as log2(res))
fdres (int, optional) – final directional resolution given as log2(res)
accuracy (float, optional) – parameter to set threshold at sampling level relative to final level threshold (smaller number will increase sampling, default is 1.0)
srcn (int, optional) – number of sources return per vector by run
stype (str, optional) – sampler type (prefixes output files)
srcdef (str, optional) – path or string with source definition to add to scene
plotp (bool, optional) – show probability distribution plots at each level (first point only)
bands (int, optional) – number of spectral bands returned by the engine
engine_args (str, optional) – command line arguments used to initialize engine
nproc (int, optional) – number of processors to give to the engine, if None, uses os.cpu_count()
-
t0
= 0.00390625¶ coefficients used to set the sampling thresholds
-
t1
= 0.0625¶
-
lb
= 0.25¶ lower and upper bounds for drawing from pdf
-
ub
= 8¶
-
engine
= None¶ raytraverse.renderer.Renderer
-
bands
= None¶ number of spectral bands / channels returned by renderer based on given renderopts (user ensures these agree).
- Type
int
-
scene
= None¶ scene information
-
srcn
= None¶ number of sources return per vector by run
- Type
int
-
accuracy
= None¶ accuracy parameter
- Type
float
-
idres
= None¶ initial direction resolution (as log2(res))
- Type
int
-
weights
= None¶ holds weights for self.draw
- Type
np.array
-
stype
= None¶ sampler type
- Type
str
-
property
compiledscene
¶
-
property
levels
¶ sampling scheme
- Getter
Returns the sampling scheme
- Setter
Set the sampling scheme from (ptres, fdres, skres)
- Type
np.array
-
sample
(vecf, vecs, outf=None)[source]¶ generic sample function
- Parameters
vecf (str) – path of file name with sample vectors shape (N, 6) vectors in binary float format
vecs (np.array) – sample vectors (subclasses can choose which to use)
outf (str, optional) – if given, append results to file
- Returns
lum – array of shape (N,) to update weights
- Return type
np.array
-
_offset
(shape, dim)[source]¶ for modifying jitter behavior of UV direction samples
- Parameters
shape (tuple) – shape of samples to jitter/offset
dim (int) – number of divisions in square side
-
sample_to_uv
(pdraws, shape)[source]¶ generate samples vectors from flat draw indices
- Parameters
pdraws (np.array) – flat index positions of samples to generate
shape (tuple) – shape of level samples
- Returns
si (np.array) – index array of draws matching samps.shape
vecs (np.array) – sample vectors
-
detailfunc
= 'wav3'¶
-
filters
= {'cross': (<MagicMock name='mock().__truediv__()' id='140680668775760'>, <MagicMock name='mock().__truediv__()' id='140680668069392'>), 'point': (<MagicMock name='mock().__truediv__()' id='140680668240144'>, <MagicMock name='mock()' id='140680663108432'>), 'prewitt': (<MagicMock name='mock().__truediv__()' id='140680669772048'>, <MagicMock name='mock().__truediv__()' id='140680663620624'>), 'sobel': (<MagicMock name='mock().__truediv__()' id='140680670176144'>, <MagicMock name='mock().__truediv__()' id='140680690838032'>), 'sobelswap': (<MagicMock name='mock().__truediv__()' id='140680667011920'>, <MagicMock name='mock().__truediv__()' id='140680670452624'>), 'wav': (<MagicMock name='mock().__truediv__()' id='140680662473104'>, <MagicMock name='mock().__truediv__()' id='140680663382864'>), 'wav3': (<MagicMock name='mock().__rmul__()' id='140680667711248'>, <MagicMock name='mock().__rmul__()' id='140680667419344'>, <MagicMock name='mock().__rmul__()' id='140680665857552'>)}¶
-
draw
(level)[source]¶ draw samples based on detail calculated from weights detail is calculated across direction only as it is the most precise dimension
- Returns
pdraws (np.array) – index array of flattened samples chosen to sample at next level
p (np.array) – computed probabilities
-
update_weights
(si, lum)[source]¶ update self.weights (which holds values used to calculate pdf)
- Parameters
si (np.array) – multidimensional indices to update
lum – values to update with
-
run_callback
(vecfs, name, point, posidx, vm)[source]¶ handle class specific cleanup and lightpointKD construction
-
run
(point, posidx, vm=None, plotp=False, log=False, outf=True, **kwargs)[source]¶ - Parameters
point (np.array) – point to sample
posidx (int) – position index
vm (raytraverse.mapper.ViewMapper) – view direction to sample
plotp – plot weights, detail and vectors for each level
log – whether to log level sampling rates can be ‘scene’, ‘err’ or None ‘scene’ - logs to Scene log file ‘err’ - logs to stderr anything else - does not log incremental progress
outf (bool, optional) – some inheriting classes do not need an outfile, but this should not be changed unless the class stores the lum results directly and the run_callback of the class does not expect the file to exist.
SkySampler¶
-
class
raytraverse.sampler.
SkySampler
(scene, engine=<class 'raytraverse.renderer.rcontrib.Rcontrib'>, skyres=10.0, engine_args='-ab 7 -ad 2 -c 16200 -as 0 -lw .0625', **kwargs)[source]¶ Bases:
raytraverse.sampler.sampler.Sampler
sample contributions from the sky hemisphere according to a square grid transformed by shirley-chiu mapping using rcontrib.
- Parameters
scene (raytraverse.scene.Scene) – scene class containing geometry, location and analysis plane scene: str, optional (required if not reload) space separated list of radiance scene files (no sky) or octree
skyres (float, optional) – approximate square patch size in degrees
engine_args (str, optional) – rtrace arguments to pass to rcontrib
SunSampler¶
-
class
raytraverse.sampler.
SunSampler
(scene, sun, sunbin, speclevel=9, fdres=10, engine_args='-ab 7 -ad 10 -c 100 -as 0 -lw 1.25e-5', keepamb=True, ambcache=False, slimit=0.01, maxspec=0.3, **kwargs)[source]¶ Bases:
raytraverse.sampler.sampler.Sampler
sample contributions from direct suns.
- Parameters
scene (raytraverse.scene.Scene) – scene class containing geometry, location and analysis plane
sun (np.array) – shape 3, sun position
sunbin (int) – sun bin
ropts (str, optional) – arguments for engine
speclevel (int, optional) – at this sampling level, pdf is made from brightness of sky sampling rather than progressive variance to look for fine scale specular highlights, this should be atleast 1 level from the end and the resolution of this level should be smaller than the size of the source
keepamb (bool, optional) – whether to keep ambient files after run, if kept, a successive call will load these ambient files, so care must be taken to not change any parameters
ambcache (bool, optional) – whether the rcopts indicate that the calculation will use ambient caching (and thus should write an -af file argument to the engine)
-
specidx
= None¶ index of level at which brightness sampling occurs
- Type
int
-
sunpos
= None¶ sun position x,y,z
- Type
np.array
-
draw
(level)[source]¶ draw samples based on detail calculated from weights detail is calculated across direction only as it is the most precise dimension
- Returns
pdraws – index array of flattened samples chosen to sample at next level
- Return type
np.array
-
run_callback
(vecfs, name, point, posidx, vm)[source]¶ handle class specific cleanup and lightpointKD construction
-
run
(point, posidx, vm=None, plotp=False, **kwargs)[source]¶ - Parameters
point (np.array) – point to sample
posidx (int) – position index
vm (raytraverse.mapper.ViewMapper) – view direction to sample
plotp – plot weights, detail and vectors for each level
log – whether to log level sampling rates can be ‘scene’, ‘err’ or None ‘scene’ - logs to Scene log file ‘err’ - logs to stderr anything else - does not log incremental progress
outf (bool, optional) – some inheriting classes do not need an outfile, but this should not be changed unless the class stores the lum results directly and the run_callback of the class does not expect the file to exist.
SunViewSampler¶
-
class
raytraverse.sampler.
SunViewSampler
(scene, sun, sunbin, **kwargs)[source]¶ Bases:
raytraverse.sampler.sampler.Sampler
sample view rays to direct suns.
here idres and fdres are sampled on a per sun basis for a view centered on each sun direction with a view angle of .533 degrees (hardcoded in sunmapper class).
- Parameters
scene (raytraverse.scene.Scene) – scene class containing geometry, location and analysis plane
suns (raytraverse.sunsetter.SunSetter) – sun class containing sun locations.
loadsrc (bool) – include suns.rad in base scene initialization. if False, self.engine.load_source must be invoked before call.
-
ub
= 1¶ deterministic sample draws
-
_offset
(shape, dim)[source]¶ no jitter on sun view because of very fine resolution and potentially large number of samples bog down random number generator
-
run_callback
(vecfs, name, point, posidx, vm)[source]¶ post sampling, write full resolution (including interpolated values) non zero rays to result file.
-
run
(point, posidx, vm=None, plotp=False, **kwargs)[source]¶ - Parameters
point (np.array) – point to sample
posidx (int) – position index
vm (raytraverse.mapper.ViewMapper) – view direction to sample
plotp – plot weights, detail and vectors for each level
log – whether to log level sampling rates can be ‘scene’, ‘err’ or None ‘scene’ - logs to Scene log file ‘err’ - logs to stderr anything else - does not log incremental progress
outf (bool, optional) – some inheriting classes do not need an outfile, but this should not be changed unless the class stores the lum results directly and the run_callback of the class does not expect the file to exist.
ImageSampler¶
-
class
raytraverse.sampler.
ImageSampler
(scene, scalefac=None, **kwargs)[source]¶ Bases:
raytraverse.sampler.sampler.Sampler
sample image (for testing algorithms).
- Parameters
scene (raytraverse.scene.ImageScene) – scene class containing image file information
scalefac (float, optional) – by default set to the average of non-zero pixels in the image used to establish sampling thresholds similar to contribution based samplers