Spatial Consistency

class ConsistentGenerator(rng)[source]

Bases: object

Generator of consistent random variables.

Parameters:

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

add_variable(variable)[source]

Add a dual consistent random variable to the generator.

Returns: The variable’s offset in the generated samples.

Return type:

int

boolean(shape=None)[source]

Create a dual consistent boolean random variable.

Parameters:

shape (Optional[Tuple[int, ...]]) – Shape of the output array. If not specified, the variable will be scalar.

Return type:

ConsistentBoolean

Returns: Dual consistent boolean random variable.

gaussian(shape=None)[source]

Create a dual consistent Gaussian random variable.

Parameters:

shape (Optional[Tuple[int, ...]]) – Shape of the output array. If not specified, the variable will be scalar.

Return type:

ConsistentGaussian

Returns: Dual consistent Gaussian random variable.

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) – 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.

Parameters:

shape (Optional[Tuple[int, ...]]) – Shape of the output array. If not specified, the variable will be scalar.

Return type:

ConsistentUniform

Returns: Dual consistent uniform random variable.

class ConsistentRealization[source]

Bases: ABC, Serializable

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 (ndarray) – First position in euclidean space.

  • position_b (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 (ndarray) – Frequencies of the spatially consistent process.

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

classmethod Deserialize(process)[source]

Deserialize an object’s state.

Objects cannot be deserialized directly, instead a Factory must be instructed to carry out the deserialization process.

Parameters:

process (DeserializationProcess) – The current stage of the deserialization process. This object is generated by the Factory and provides an interface to deserialization methods supporting multiple backends.

Return type:

DualConsistentRealization

Returns:

The deserialized object.

sample(position_a, position_b)[source]

Sample the realization given two locations in euclidean space.

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

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

Return type:

DualConsistentSample

Returns: Sample of the realization.

serialize(process)[source]

Serialize this object’s state.

Objects cannot be serialized directly, instead a Factory must be instructed to carry out the serialization process.

Parameters:

process (SerializationProcess) – The current stage of the serialization process. This object is generated by the Factory and provides an interface to serialization methods supporting multiple backends.

Return type:

None

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 (ndarray) – Scalar samples of the realization.

classmethod Deserialize(process)[source]

Deserialize an object’s state.

Objects cannot be deserialized directly, instead a Factory must be instructed to carry out the deserialization process.

Parameters:

process (DeserializationProcess) – The current stage of the deserialization process. This object is generated by the Factory and provides an interface to deserialization methods supporting multiple backends.

Return type:

StaticConsistentRealization

Returns:

The deserialized object.

sample(position_a, position_b)[source]

Sample the realization given two locations in euclidean space.

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

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

Return type:

DualConsistentSample

Returns: Sample of the realization.

serialize(process)[source]

Serialize this object’s state.

Objects cannot be serialized directly, instead a Factory must be instructed to carry out the serialization process.

Parameters:

process (SerializationProcess) – The current stage of the serialization process. This object is generated by the Factory and provides an interface to serialization methods supporting multiple backends.

Return type:

None

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 (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(shape, offset=0)[source]

Bases: ABC, Serializable

Base class for spatially consistent random variables.

Parameters:
  • shape (Tuple[int, ...]) – Shape of the output array

  • offset (int) – Offset of the variable within its generator. Defaults to zero. Adding a variable to a generator will change the offset.

classmethod Deserialize(process)[source]

Deserialize an object’s state.

Objects cannot be deserialized directly, instead a Factory must be instructed to carry out the deserialization process.

Parameters:

process (DeserializationProcess) – The current stage of the deserialization process. This object is generated by the Factory and provides an interface to deserialization methods supporting multiple backends.

Return type:

ConsistentVariable

Returns:

The deserialized object.

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.

serialize(process)[source]

Serialize this object’s state.

Objects cannot be serialized directly, instead a Factory must be instructed to carry out the serialization process.

Parameters:

process (SerializationProcess) – The current stage of the serialization process. This object is generated by the Factory and provides an interface to serialization methods supporting multiple backends.

Return type:

None

property offset: int

Offset of the variable in the generated samples.

Adding a variable to a generator will change the offset.

property shape: Tuple[int, ...]

Shape of the output array.

property size: int

Number of scalar samples to be generated.

class ConsistentGaussian(shape, offset=0)[source]

Bases: ConsistentVariable

Spatially consistent normally distributed Gaussian variable.

Parameters:
  • shape (Tuple[int, ...]) – Shape of the output array

  • offset (int) – Offset of the variable within its generator. Defaults to zero. Adding a variable to a generator will change the offset.

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(shape, offset=0)[source]

Bases: ConsistentVariable

Spatially consistent uniformly distributed random variable.

Parameters:
  • shape (Tuple[int, ...]) – Shape of the output array

  • offset (int) – Offset of the variable within its generator. Defaults to zero. Adding a variable to a generator will change the offset.

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(shape, offset=0)[source]

Bases: ConsistentVariable

Spatially consistent boolean random variable.

Parameters:
  • shape (Tuple[int, ...]) – Shape of the output array

  • offset (int) – Offset of the variable within its generator. Defaults to zero. Adding a variable to a generator will change the offset.

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.