{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Multi-field variogram estimation\n\nIn this example, we demonstrate how to estimate a variogram from multiple\nfields on the same point-set that should have the same statistical properties.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\nimport numpy as np\n\nimport gstools as gs\n\nx = np.random.RandomState(19970221).rand(1000) * 100.0\ny = np.random.RandomState(20011012).rand(1000) * 100.0\nmodel = gs.Exponential(dim=2, var=2, len_scale=8)\nsrf = gs.SRF(model, mean=0)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Generate two synthetic fields with an exponential model.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "field1 = srf((x, y), seed=19970221)\nfield2 = srf((x, y), seed=20011012)\nfields = [field1, field2]"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Now we estimate the variograms for both fields individually and then again\nsimultaneously with only one call.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "bins = np.arange(40)\nbin_center, gamma1 = gs.vario_estimate((x, y), field1, bins)\nbin_center, gamma2 = gs.vario_estimate((x, y), field2, bins)\nbin_center, gamma = gs.vario_estimate((x, y), fields, bins)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Now we demonstrate that the mean variogram from both fields coincides\nwith the joined estimated one.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "plt.plot(bin_center, gamma1, label=\"field 1\")\nplt.plot(bin_center, gamma2, label=\"field 2\")\nplt.plot(bin_center, gamma, label=\"joined fields\")\nplt.plot(bin_center, 0.5 * (gamma1 + gamma2), \":\", label=\"field 1+2 mean\")\nplt.legend()\nplt.show()"
      ]
    }
  ],
  "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
}