{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Creating an Ensemble of Fields\n\nCreating an ensemble of random fields would also be\na great idea. Let's reuse most of the previous code.\n\nWe will set the position tuple `pos` before generation to reuse it afterwards.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as pt\nimport numpy as np\n\nimport gstools as gs\n\nx = y = np.arange(100)\n\nmodel = gs.Gaussian(dim=2, var=1, len_scale=10)\nsrf = gs.SRF(model)\nsrf.set_pos([x, y], \"structured\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "This time, we did not provide a seed to :any:`SRF`, as the seeds will used\nduring the actual computation of the fields. We will create four ensemble\nmembers, for better visualisation, save them in to srf class and in a first\nstep, we will be using the loop counter as the seeds.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "ens_no = 4\nfor i in range(ens_no):\n    srf(seed=i, store=f\"field{i}\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Now let's have a look at the results. We can access the fields by name or\nindex:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig, ax = pt.subplots(2, 2, sharex=True, sharey=True)\nax = ax.flatten()\nfor i in range(ens_no):\n    ax[i].imshow(srf[i].T, origin=\"lower\")\npt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Using better Seeds\n\nIt is not always a good idea to use incrementing seeds. Therefore GSTools\nprovides a seed generator :any:`MasterRNG`. The loop, in which the fields are\ngenerated would then look like\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from gstools.random import MasterRNG\n\nseed = MasterRNG(20170519)\nfor i in range(ens_no):\n    srf(seed=seed(), store=f\"better_field{i}\")"
      ]
    }
  ],
  "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.8.6"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}