Skip to content

Defining a CustomVariogram istead of a CustomCovariance #303

Open
@rkenko

Description

@rkenko

Hi,

Is it a way to define a custom variogram model instead of a custom covariance model in order to perform simulation of the field?

I want to define directly the variogram since the field is not stationnary: there is no sill due to the linear component.

This is an example of what i try to do (the current version of the code is not working):

# importing modules
!pip install gstools
!export GSTOOLS_BUILD_PARALLEL=1
!pip install --no-binary=gstools gstools
!pip install gstools-core
from gstools import Variogram, SRF
import gstools as gs

# defining the variogram parameters
gamma0, gamma1, a1, gamma2, amplitud = 3.50822126e-05, 6.67841391e-04, 2.05546548e-01, 9.60346380e-06, 1.8182820314159756e-05

# defining the variogram model
class CustomVariogramModel():
    def __init__(self, gamma0, gamma1, a1, gamma2, amplitud, **kwargs):
        super().__init__(**kwargs)
        self.gamma0 = gamma0
        self.gamma1 = gamma1
        self.a1 = a1
        self.gamma2 = gamma2
        self.amplitud = amplitud
    def model(self, h):
        gaussian = self.gamma0 + self.gamma1 * (1 - np.exp(-(np.abs(h) ** 2) / (self.a1 ** 2)))
        linear = self.gamma2 * np.abs(h)
        periodic = self.amplitud * np.cos(2 * np.pi / (12 / 10) * h)
        return gaussian + linear + periodic

# attributing the variogram parameters 
my_variogram = CustomVariogramModel(gamma0, gamma1, a1, gamma2, amplitud)

# initializing the variogram model
my_variogram_model = Variogram(my_variogram.model)

# initializing the spatial random field 
srf = SRF(variogram_model=my_variogram_model, seed=0)

# generating the 2D field on a N x N grid
field = srf((100, 100))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions