tolerancing.perturbation

Perturbation Module

This module contains classes for generating perturbations to optical system variables. Perturbations are used to simulate the effects of manufacturing errors or other sources of variability in an optical system.

Kramer Harrison, 2024

Classes

BaseSampler()

Abstract base class for samplers.

DistributionSampler(distribution[, seed])

A sampler that generates random samples from a given distribution. Options for the distribution include 'normal' and 'uniform' and these require arguments as follows: "normal": loc, scale (corresponding to mean and standard deviation) "uniform": low, high.

Perturbation(optic, variable_type, sampler, ...)

A class representing a perturbation to an optic variable.

RangeSampler(start, end, steps)

A sampler that generates a range of samples over a linear range.

ScalarSampler(value)

A sampler that always returns a fixed scalar value.

class BaseSampler[source]

Abstract base class for samplers.

This class defines the interface for samplers in the optiland.tolerancing module.

abstract sample()[source]
class DistributionSampler(distribution, seed=None, **params)[source]

A sampler that generates random samples from a given distribution. Options for the distribution include ‘normal’ and ‘uniform’ and these require arguments as follows:

“normal”: loc, scale (corresponding to mean and standard deviation) “uniform”: low, high

Parameters:
  • distribution (str) – The type of distribution to sample from. Options are ‘normal’ and ‘uniform’.

  • *params – Variable length arguments representing the parameters of the distribution.

  • seed (int, optional) – The seed value for random number generation. Defaults to None.

Raises:

ValueError – If the distribution type is unknown.

sample()[source]

Return a random value from the given distribution.

Returns:

A random value sampled from the specified distribution.

Return type:

float

class Perturbation(optic, variable_type, sampler, **kwargs)[source]

A class representing a perturbation to an optic variable. Perturbations are used to simulate the effects of manufacturing errors or other sources of variability in an optical system.

Parameters:
  • optic – The optic object to apply the perturbation to.

  • variable_type – The type of variable to perturb.

  • sampler – The sampler object used to generate perturbation values.

  • **kwargs – Additional keyword arguments to be passed to the Variable object.

optic

The optic object to apply the perturbation to.

type

The type of variable to perturb.

sampler

The sampler object used to generate perturbation values.

variable

The Variable object representing the perturbed variable.

value

The value of the perturbation.

apply()[source]

Apply the perturbation to the optic.

reset()[source]

Reset the perturbation to its original value.

class RangeSampler(start, end, steps)[source]

A sampler that generates a range of samples over a linear range.

Parameters:
  • start (float or int) – The start of the range.

  • end (float or int) – The end of the range.

  • steps (int) – The number of samples to generate.

start

The start of the range.

Type:

float or int

end

The end of the range.

Type:

float or int

size

The number of samples to generate.

Type:

int

sample()[source]

Return the next value in the range.

Returns:

The next value in the range.

Return type:

float

class ScalarSampler(value)[source]

A sampler that always returns a fixed scalar value.

Parameters:

value (float or int) – The scalar value to be returned by the sampler.

value

The scalar value to be returned by the sampler.

Type:

float or int

size

The size of the sample, which is always 1 for ScalarSampler.

Type:

int

sample()[source]

Returns the fixed scalar value.

Returns:

The scalar value.

Return type:

float or int