Skip to main content

RandomFields

Tests codecov

Random Fields

Python package to generate random fields in 2D or 3D on unstructured grids.

Background information

The random fields are generated using gstools.

Currently, the following covariance models are available:

  • Gaussian
  • Exponential
  • Matern
  • Linear

Installation

To install the package, run the following command in the terminal:

pip install git+https://github.com/StemVibrations/RandomFields

Tutorial

Example in 2D

In this example we generate a random field on a 2D regular grid.

First you need to import the packages:

import numpy as np
from random_fields.generate_field import RandomFields, ModelName
from random_fields.utils import plot2D

Then you need to define the grid:

x = np.linspace(0, 100, 50)
y = np.linspace(0, 50, 50)

x, y = np.meshgrid(x, y)

In this example we create a mesh of 50x50 points between 0 and 100 in x and 0 and 50 in y direction.

Then we define the random field properties:

nb_dimensions = 2
mean = 10
variance = 2
vertical_scale_fluctuation = 10
anisotropy = [1]
angle = [0]
model_rf = ModelName.Gaussian

In this example we use a Gaussian covariance model.

Then we create the random field:

rf = RandomFields(model_rf, nb_dimensions, mean, variance, vertical_scale_fluctuation, anisotropy, angle, seed=14)
rf.generate(np.array([x.ravel(), y.ravel()]).T)

To visualise the results you can run:

plot2D([np.array([x.ravel(), y.ravel()]).T], [rf.random_field], title="Random Field", output_folder="./", output_name="random_field.png")

The result is the following random field:

Random field 2D

Example in 3D

In this example we generate a random field on a 3D regular grid.

First you need to import the packages:

import numpy as np
from random_fields.generate_field import RandomFields, ModelName
from random_fields.utils import plot3D

Then you need to define the grid:

x = np.linspace(0, 100, 50)
y = np.linspace(0, 50, 50)
z = np.linspace(0, 25, 25)

x, y, z = np.meshgrid(x, y, z)

In this example we create a mesh of 50x50x25 points between 0 and 100 in x, 0 and 50 in y direction and 0 and 25 in z direction.

Then we define the random field properties:

nb_dimensions = 3
mean = 10
variance = 2
vertical_scale_fluctuation = 10
anisotropy = [5, 5]
angle = [0, 0]
model_rf = ModelName.Gaussian

Then we create the random field:

rf = RandomFields(model_rf, nb_dimensions, mean, variance, vertical_scale_fluctuation, anisotropy, angle, seed=14)
rf.generate(np.array([x.ravel(), y.ravel(), z.ravel()]).T)

To visualise the results you can run:

plot3D([np.array([x.ravel(), y.ravel(), z.ravel()]).T], [rf.random_field], title="Random Field", output_folder="./", output_name="random_field_3D.png")

The result is the following random field:

Random field 3D

Metadata

Release files for random-fields 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for random-fields 1.0.2
File Size Uploaded Provenance Actions
random_fields-1.0.2.tar.gz 6.4 kB Without provenance Details for random_fields-1.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for random-fields 1.0.2
File Interpreter ABI Platform Actions
random_fields-1.0.2-py3-none-any.whl Python 3 none any Details for random_fields-1.0.2-py3-none-any.whl

Total release size: 12.3 kB

Release files / random_fields-1.0.2.tar.gz

Download URL random_fields-1.0.2.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
71f941cdf8b9933f945f4cc44fdd01613d8a371bee321cff3eaf2e05fba887ea
BLAKE2b-256 checksum
How to use checksums
683ff20ce9d90c3d4f5b58566881228af6bd9afad571033ae1dafd1ccf6659d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.1

Release files / random_fields-1.0.2-py3-none-any.whl

Download URL random_fields-1.0.2-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2728d6cb4fef4693becc049b58f1b1054621d44ff5a08a8f8389f147e3269fc6
BLAKE2b-256 checksum
How to use checksums
858d0f930dccbf334cfecf031b63cf00e0c448c9f110662cc9fa506c78b2ad67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.1

Security for random-fields 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page