{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Introductory example\n\nLet us start with a short example of a self defined model (Of course, we\nprovide a lot of predefined models [See: :any:`gstools.covmodel`],\nbut they all work the same way).\nTherefore we reimplement the Gaussian covariance model\nby defining just the \"normalized\"\n`correlation <https://en.wikipedia.org/wiki/Autocovariance#Normalization>`_\nfunction:\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\n\nimport gstools as gs\n\n\n# use CovModel as the base-class\nclass Gau(gs.CovModel):\n    def cor(self, h):\n        return np.exp(-(h ** 2))"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Here the parameter ``h`` stands for the normalized range ``r / len_scale``.\nNow we can instantiate this model:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "model = Gau(dim=2, var=2.0, len_scale=10)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "To have a look at the variogram, let's plot it:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "model.plot()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "This is almost identical to the already provided :any:`Gaussian` model.\nThere, a scaling factor is implemented so the len_scale coincides with the\nintegral scale:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "gau_model = gs.Gaussian(dim=2, var=2.0, len_scale=10)\ngau_model.plot()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Parameters\n\nWe already used some parameters, which every covariance models has.\nThe basic ones are:\n\n    - **dim** : dimension of the model\n    - **var** : variance of the model (on top of the subscale variance)\n    - **len_scale** : length scale of the model\n    - **nugget** : nugget (subscale variance) of the model\n\nThese are the common parameters used to characterize\na covariance model and are therefore used by every model in GSTools.\nYou can also access and reset them:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "print(\"old model:\", model)\nmodel.dim = 3\nmodel.var = 1\nmodel.len_scale = 15\nmodel.nugget = 0.1\nprint(\"new model:\", model)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "<div class=\"alert alert-info\"><h4>Note</h4><p>- The sill of the variogram is calculated by ``sill = variance + nugget``\n     So we treat the variance as everything **above** the nugget,\n     which is sometimes called **partial sill**.\n   - A covariance model can also have additional parameters.</p></div>\n\n"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.7.9"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}