Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defining a CustomVariogram istead of a CustomCovariance #303

Open
rkenko opened this issue Mar 23, 2023 · 1 comment
Open

Defining a CustomVariogram istead of a CustomCovariance #303

rkenko opened this issue Mar 23, 2023 · 1 comment
Milestone

Comments

@rkenko
Copy link

rkenko commented Mar 23, 2023

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))
@MuellerSeb
Copy link
Member

Hey there,

at the moment this is not possible. All models need to be bounded and therefore have a covariance dependent formulation.

Here is an issue tracking the need of a class for unbounded models:
#192

The main obstacle is the random field generation, since the randomization method depends on the covariance function associated with the variogram.

For now, I would recommend using a truncated model, where there is an upper bound for the variance. Examples are the truncated linear model and the truncated power law models that are already implemented.

Cheers,
Sebastian

@MuellerSeb MuellerSeb added this to the 2.0 milestone Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants