Spatial Consistency

class ConsistentGenerator(rng)[source]

Bases: object

Generator of consistent random variables.

Parameters:

rng (np.random.Generator | RandomNode) – Random number generator used to initialize this random variable.

add_variable(variable)[source]

Add a dual consistent random variable to the generator.

Return the variable’s offset in the generated samples.

Return type:

int

boolean(shape=None)[source]

Create a dual consistent boolean random variable.

Return type:

ConsistentBoolean

gaussian(shape=None)[source]

Create a dual consistent Gaussian random variable.

Return type:

ConsistentGaussian

realize(decorrelation_distance, num_sinusoids=30)[source]
Parameters:
  • decorrelation_distance (float) – Euclidean distance at which a sample of this Gaussian process is considered to be uncorrelated with another sample.

  • num_sinusoids (int, optional) – Number of sinusoids used to approximate the Gaussian process. 30 by default.

Return type:

ConsistentRealization

Returns: Realization of the consistent generator.

uniform(shape=None)[source]

Create a dual consistent uniform random variable.

Return type:

ConsistentUniform

class ConsistentRealization[source]

Bases: ABC, HDFSerializable

Base class for a realization of a consistent random generator.

abstract sample(position_a, position_b)[source]

Sample the realization given two locations in euclidean space.

Parameters:
  • position_a (np.ndarray) – First position in euclidean space.

  • position_b (np.ndarray) – Second position in euclidean space.

Return type:

ConsistentSample

Returns: Sample of the realization.

class DualConsistentRealization(frequencies, phases)[source]

Bases: ConsistentRealization

Realization of a set of dual consistent random variables.

Parameters:
  • frequencies (np.ndarray) – Frequencies of the spatially consistent process.

  • phases (np.ndarray) – Phases of the spatially consistent process.

sample(position_a, position_b)[source]

Sample the realization given two locations in euclidean space.

Parameters:
  • position_a (np.ndarray) – First position in euclidean space.

  • position_b (np.ndarray) – Second position in euclidean space.

Return type:

DualConsistentSample

Returns: Sample of the realization.

property frequencies: ndarray

Frequencies of the spatially consistent process.

property phases: ndarray

Phases of the spatially consistent process.

class StaticConsistentRealization(scalar_samples)[source]

Bases: ConsistentRealization

Consistent realization that is immutable in space.

Parameters:

scalar_samples (np.ndarray) – Scalar samples of the realization.

sample(position_a, position_b)[source]

Sample the realization given two locations in euclidean space.

Parameters:
  • position_a (np.ndarray) – First position in euclidean space.

  • position_b (np.ndarray) – Second position in euclidean space.

Return type:

DualConsistentSample

Returns: Sample of the realization.

class ConsistentSample[source]

Bases: object

Sample of a consistent realization.

Generated by calling ConsistentRealization.sample().

abstract fetch_scalars(offset, num_scalars)[source]

Fetch the scalar samples.

Parameters:
  • offset (int) – Offset of the scalar samples within this realization.

  • num_scalars (int) – Number of scalar samples to fetch.

Return type:

ndarray

Returns: Numpy vector of scalar samples.

class DualConsistentSample(scalar_samples)[source]

Bases: ConsistentSample

Sample of a dual consistent realization.

Generated by calling DualConsistentRealization.sample().

Initialize a dual consistent sample.

fetch_scalars(offset, num_scalars)[source]

Fetch the scalar samples.

Parameters:
  • offset (int) – Offset of the scalar samples within this realization.

  • num_scalars (int) – Number of scalar samples to fetch.

Return type:

ndarray

Returns: Numpy vector of scalar samples.

class StaticConsistentSample(scalar_samples)[source]

Bases: ConsistentSample

Consistent sample that is invariant in space.

Parameters:

scalar_samples (np.ndarray) – Scalar samples of the realization.

fetch_scalars(offset, num_scalars)[source]

Fetch the scalar samples.

Parameters:
  • offset (int) – Offset of the scalar samples within this realization.

  • num_scalars (int) – Number of scalar samples to fetch.

Return type:

ndarray

Returns: Numpy vector of scalar samples.

class ConsistentVariable(generator, shape=None)[source]

Bases: ABC

Base class for spatially consistent random variables.

Parameters:
  • generator (ConsistentGenerator) – Generator to which this variable belongs.

  • shape (Tuple[int, ...] | None, optional) – Shape of the output array. Scalar by default.

sample(sample)[source]

Sample the variable given a sample of the realization.

Parameters:

sample (ConsistentSample) – Sample of the realization.

Return type:

ndarray

Returns: Numpy array of samples of dimensions matching the variable size.

property offset: int

Offset of the variable in the generated samples.

property shape: Tuple[int, ...]

Shape of the output array.

property size: int

Number of scalar samples to be generated.

class ConsistentGaussian(generator, shape=None)[source]

Bases: ConsistentVariable

Spatially consistent normally distributed Gaussian variable.

Parameters:
  • generator (ConsistentGenerator) – Generator to which this variable belongs.

  • shape (Tuple[int, ...] | None, optional) – Shape of the output array. Scalar by default.

sample(sample, mean=0.0, std=1.0)[source]

Sample the variable given a sample of the realization.

Parameters:

sample (ConsistentSample) – Sample of the realization.

Return type:

ndarray

Returns: Numpy array of samples of dimensions matching the variable size.

class ConsistentUniform(generator, shape=None)[source]

Bases: ConsistentVariable

Spatially consistent uniformly distributed random variable.

Parameters:
  • generator (ConsistentGenerator) – Generator to which this variable belongs.

  • shape (Tuple[int, ...] | None, optional) – Shape of the output array. Scalar by default.

sample(sample)[source]

Sample the variable given a sample of the realization.

Parameters:

sample (ConsistentSample) – Sample of the realization.

Return type:

ndarray

Returns: Numpy array of samples of dimensions matching the variable size.

class ConsistentBoolean(generator, shape=None)[source]

Bases: ConsistentVariable

Spatially consistent boolean random variable.

Parameters:
  • generator (ConsistentGenerator) – Generator to which this variable belongs.

  • shape (Tuple[int, ...] | None, optional) – Shape of the output array. Scalar by default.

sample(sample)[source]

Sample the variable given a sample of the realization.

Parameters:

sample (ConsistentSample) – Sample of the realization.

Return type:

ndarray

Returns: Numpy array of samples of dimensions matching the variable size.