Random fields on unstructured grids
Project description
RandomFields
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:
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:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file random_fields-1.0.1.tar.gz.
File metadata
- Download URL: random_fields-1.0.1.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21d780a4ce671752dcd1a67413dae8e97c0488537edd823988a95128fe52b9e0
|
|
| MD5 |
13befbd7b5ad3672fd4406202269d17f
|
|
| BLAKE2b-256 |
f445438cde25aecb746220c361a7626576460a262b5e98f547f48e9cacd80c9e
|
File details
Details for the file random_fields-1.0.1-py3-none-any.whl.
File metadata
- Download URL: random_fields-1.0.1-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed88d2ae8b870e01ac909131e37dee4be90115ea81b8be0c10b16bbe9ec5116f
|
|
| MD5 |
c3977b912feda2b74519a58ee01d6cb2
|
|
| BLAKE2b-256 |
91118269b389a804859bd458b9b4a6ac1b9aa7aae089ec3cfd8edc246cb4e81c
|