{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib notebook"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\nFull wavefield vs diffusive approx. for a fullspace\n===================================================\n\nPlay around to see that the difference is getting bigger for\n\n- higher frequencies,\n- higher eperm/mperm.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import empymod\nimport numpy as np\nimport matplotlib.pyplot as plt\nplt.style.use('ggplot')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Define model\n------------\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "x = (np.arange(526))*20-500\nrx = np.repeat([x, ], np.size(x), axis=0)\nry = rx.transpose()\nzsrc = 150\nzrec = 200\nres = 1/3\nfreq = 0.5\nab = 11\naniso = np.sqrt(3/.3)\nperm = 1\ninp = {\n    'src': [0, 0, zsrc],\n    'rec': [rx.ravel(), ry.ravel(), zrec],\n    'res': res,\n    'freqtime': freq,\n    'aniso': aniso,\n    'ab': ab,\n    'epermH': perm,\n    'mpermH': perm,\n    'verb': 0\n}"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Computation\n-----------\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# Halfspace\nhs = empymod.analytical(**inp, solution='dfs')\nhs = hs.reshape(np.shape(rx))\n\n# Fullspace\nfs = empymod.analytical(**inp)\nfs = fs.reshape(np.shape(rx))\n\n# Relative error (%)\namperr = np.abs((fs.amp() - hs.amp())/fs.amp())*100\nphaerr = np.abs((fs.pha(unwrap=False) - hs.pha(unwrap=False)) /\n                fs.pha(unwrap=False))*100"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Plot\n----\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig, axs = plt.subplots(figsize=(10, 4.2), nrows=1, ncols=2)\n\n# Min and max, properties\nvmin = 1e-10\nvmax = 1e0\nprops = {'levels': np.logspace(np.log10(vmin), np.log10(vmax), 50),\n         'locator': plt.matplotlib.ticker.LogLocator(), 'cmap': 'Greys'}\n\n# Plot amplitude error\nplt.sca(axs[0])\nplt.title(r'(a) Amplitude')\ncf1 = plt.contourf(rx/1000, ry/1000, amperr.clip(vmin, vmax), **props)\nplt.ylabel('Crossline offset (km)')\nplt.xlabel('Inline offset (km)')\nplt.xlim(min(x)/1000, max(x)/1000)\nplt.ylim(min(x)/1000, max(x)/1000)\nplt.axis('equal')\n\n# Plot phase error\nplt.sca(axs[1])\nplt.title(r'(b) Phase')\ncf2 = plt.contourf(rx/1000, ry/1000, phaerr.clip(vmin, vmax), **props)\nplt.xlabel('Inline offset (km)')\nplt.xlim(min(x)/1000, max(x)/1000)\nplt.ylim(min(x)/1000, max(x)/1000)\nplt.axis('equal')\n\n# Title\nplt.suptitle('Analytical fullspace solution\\nDifference between full ' +\n             'wavefield and diffusive approximation.', y=1.1)\n\n# Plot colorbar\ncax, kw = plt.matplotlib.colorbar.make_axes(\n        [axs[0], axs[1]], location='right', fraction=.05, pad=0.05, aspect=20)\ncb = plt.colorbar(cf2, cax=cax, ticks=10**(-(np.arange(13.)[::-1])+2), **kw)\ncb.set_label(r'Relative Error $(\\%)$')\n\n# Show\nplt.show()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "empymod.Report()"
      ]
    }
  ],
  "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.3"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}