{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib notebook"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Comparison of all src-rec combinations\n\nComparison of all source-receiver combinations; electric and magnetic\n\nWe compute the secondary field for a simple model of a 1 Ohm.m halfspace below\nair. Source is 50 m above the surface in the air, receivers are on the surface,\nfrequency is 1 Hz.\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"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "x = np.linspace(-10, 10, 101)*1000\nrx = np.repeat([x, ], np.size(x), axis=0)\nry = rx.transpose()\ninp = {'src': [0, 0, -50],\n       'rec': [rx.ravel(), ry.ravel(), 0],\n       'depth': 0,\n       'res': [2e14, 1],\n       'freqtime': 1,\n       'xdirect': None,  # Secondary field comp., req. empymod >= v1.6.1.\n       'htarg': {'pts_per_dec': -1},  # To speed-up the calculation\n       'verb': 0}"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Compute\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# All possible combinations\npab = [11, 12, 13, 14, 15, 16, 21, 22, 23, 24, 25, 26,\n       31, 32, 33, 34, 35, 36, 41, 42, 43, 44, 45, 46,\n       51, 52, 53, 54, 55, 56, 61, 62, 63, 64, 65, 66]\n\n# Compute and store them in fs\nfs = dict()\nfor ab in pab:\n    fs[str(ab)] = empymod.dipole(ab=ab, **inp).reshape(np.shape(rx))"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Plot\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig, axs = plt.subplots(figsize=(10, 12), nrows=6, ncols=6)\naxs = axs.ravel()\n\n# Labels\nlabel1 = ['x', 'y', 'z']\nlabel2 = ['E', 'H']\n\n# Colour settings\nvmin = 1e-14\nvmax = 1e-0\nprops = {'levels': np.logspace(np.log10(vmin), np.log10(vmax), 50),\n         'locator': plt.matplotlib.ticker.LogLocator()}\n\n# Loop over combinations\nfor i, val in enumerate(pab):\n    plt.sca(axs[i])\n\n    # Axis settings\n    plt.xlim(min(x)/1000, max(x)/1000)\n    plt.ylim(min(x)/1000, max(x)/1000)\n    plt.axis('equal')\n\n    # Plot the contour\n    cf = plt.contourf(\n            rx/1000, ry/1000, np.abs(fs[str(val)]).clip(vmin, vmax), **props)\n\n    # Add titels\n    if i < 6:\n        label = r'Src: '\n        label += label2[0] if i < 3 else label2[1]\n        label += '$_' + label1[i % 3] + '$'\n        plt.title(label, fontsize=12)\n\n    # Remove unnecessary x-tick labels\n    if i < 30:\n        plt.xticks([-10, 0, 10], ())\n\n    # Remove unnecessary y-tick labels; add y-labels\n    if i % 6 != 0:\n        plt.yticks([-10, 0, 10], ())\n    else:\n        label = r'Rec: '\n        label += label2[0] if i < 18 else label2[1]\n        label += '$_' + label1[(i // 6) % 3] + '$'\n        plt.ylabel(label, fontsize=12)\n\n# Colour bar\ncax, kw = plt.matplotlib.colorbar.make_axes(\n        axs, location='bottom', fraction=.05, pad=0.1, aspect=30)\ncb = plt.colorbar(\n        cf, cax=cax, ticks=np.logspace(np.log10(vmin), np.log10(vmax), 8),\n        **kw)\ncb.set_label(r'Amplitude V/m (el. rec) or T (mag. rec)')\n\n# Annotate\nplt.suptitle('Comparison of all source-receiver combinations, electric ' +\n             'and magnetic', y=0.93, fontsize=16)\nfig.text(0.5, 0.18, 'X-Offset (km)', ha='center', fontsize=14)\nfig.text(0.01, 0.5, 'Y-Offset (km)', va='center', rotation='vertical',\n         fontsize=14)\n\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.8.6"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}