{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Discrete fields\n\nHere we transform a field to a discrete field with values.\nIf we do not give thresholds, the pairwise means of the given\nvalues are taken as thresholds.\nIf thresholds are given, arbitrary values can be applied to the field.\n\nSee :any:`transform.discrete`\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\n\nimport gstools as gs\n\n# Structured field with a size of 100x100 and a grid-size of 0.5x0.5\nx = y = np.arange(200) * 0.5\nmodel = gs.Gaussian(dim=2, var=1, len_scale=5)\nsrf = gs.SRF(model, seed=20170519)\nsrf.structured([x, y])"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Create 5 equidistanly spaced values, thresholds are the arithmetic means\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "values1 = np.linspace(np.min(srf.field), np.max(srf.field), 5)\nsrf.transform(\"discrete\", store=\"f1\", values=values1)\nsrf.plot(\"f1\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Calculate thresholds for equal shares\nbut apply different values to the separated classes\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "values2 = [0, -1, 2, -3, 4]\nsrf.transform(\"discrete\", store=\"f2\", values=values2, thresholds=\"equal\")\nsrf.plot(\"f2\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Create user defined thresholds\nand apply different values to the separated classes\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "values3 = [0, 1, 10]\nthresholds = [-1, 1]\nsrf.transform(\"discrete\", store=\"f3\", values=values3, thresholds=thresholds)\nsrf.plot(\"f3\")"
      ]
    }
  ],
  "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
}