{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib notebook"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\nComparison of half-space solutions\n==================================\n\nComparing of the functions ``analytical`` with ``dipole`` for a half-space and\na fullspace-solution, where ``dipole`` internally uses ``kernel.fullspace`` for\nthe fullspace solution (``xdirect=True``), and ``analytical`` uses internally\n``kernel.halfspace``. Both in the frequency and in the time domain.\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": [
        "Time Domain\n-----------\nDefine models\n~~~~~~~~~~~~~\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "src = [0, 0, 100]\nrec = [2000, 500, 200]\nres = [2e14, 2.5]\naniso = [1, 2]\ntime = np.logspace(-2, 3, 301)\n\n# Collect parameters\ninpEM = {'src': src, 'rec': rec, 'freqtime': time, 'verb': 0}\ninpEMdip = inpEM.copy()\ninpEMdip['htarg'] = {'pts_per_dec': -1}\nmodHS = {'res': res, 'aniso': aniso}\nmodFS = {'res': res[1], 'aniso': aniso[1]}\n\nall_abs = [11, 12, 13, 21, 22, 23, 31, 32, 33]"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Plot result\n~~~~~~~~~~~\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "def plot_t(EM, HS, title, i):\n    plt.figure(title, figsize=(10, 8))\n    plt.subplot(i)\n    plt.semilogx(time, EM)\n    plt.semilogx(time, HS, '--')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Impulse HS\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "plt.figure('Impulse HS')\ni = 330\nfor ab in all_abs:\n    i += 1\n    EM = empymod.dipole(**inpEMdip, **modHS, ab=ab, signal=0, depth=0)\n    HS = empymod.analytical(**inpEM, **modFS, solution='dhs', ab=ab, signal=0)\n    plot_t(EM, HS, 'Impulse HS', i)\nplt.suptitle('Impulse HS')\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Switch-on HS\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "plt.figure('Switch-on HS')\ni = 330\nfor ab in all_abs:\n    i += 1\n    EM = empymod.dipole(**inpEMdip, **modHS, ab=ab, signal=1, depth=0)\n    HS = empymod.analytical(**inpEM, **modFS, solution='dhs', ab=ab, signal=1)\n    plot_t(EM, HS, 'Switch-on HS', i)\nplt.suptitle('Switch-on HS')\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Switch-off HS\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "plt.figure('Switch-off HS')\ni = 330\nfor ab in all_abs:\n    i += 1\n    EM = empymod.dipole(**inpEMdip, **modHS, ab=ab, signal=-1, depth=0)\n    HS = empymod.analytical(**inpEM, **modFS, solution='dhs', ab=ab, signal=-1)\n    plot_t(EM, HS, 'Switch-off HS', i)\nplt.suptitle('Switch-off HS')\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Impulse FS\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "plt.figure('Impulse FS')\ni = 330\nfor ab in all_abs:\n    i += 1\n    EM = empymod.dipole(**inpEMdip, **modFS, ab=ab, signal=0, depth=[])\n    HS = empymod.analytical(**inpEM, **modFS, solution='dfs', ab=ab, signal=0)\n    plot_t(EM, HS, 'Impulse FS', i)\nplt.suptitle('Impulse FS')\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Switch-on FS\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "plt.figure('Switch-on FS')\ni = 330\nfor ab in all_abs:\n    i += 1\n    EM = empymod.dipole(**inpEMdip, **modFS, ab=ab, signal=1, depth=[])\n    HS = empymod.analytical(**inpEM, **modFS, solution='dfs', ab=ab, signal=1)\n    plot_t(EM, HS, 'Switch-on FS', i)\nplt.suptitle('Switch-on FS')\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Switch-off FS\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "plt.figure('Switch-off FS')\ni = 330\nfor ab in all_abs:\n    i += 1\n\n    # Switch-off\n    EM = empymod.dipole(**inpEMdip, **modFS, ab=ab, signal=-1, depth=[])\n    HS = empymod.analytical(**inpEM, **modFS, solution='dfs', ab=ab, signal=-1)\n    plot_t(EM, HS, 'Switch-off FS', i)\nplt.suptitle('Switch-off FS')\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Frequency domain\n----------------\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "inpEM['freqtime'] = 1/time\ninpEMdip['freqtime'] = 1/time\n\n\ndef plot_f(EM, HS, title, i):\n    plt.figure(title, figsize=(10, 8))\n    plt.subplot(i)\n    plt.semilogx(1/time, EM.real)\n    plt.semilogx(1/time, HS.real, '--')\n    plt.semilogx(1/time, EM.imag)\n    plt.semilogx(1/time, HS.imag, '--')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Halfspace\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "i = 330\nfor ab in all_abs:\n    i += 1\n    EM = empymod.dipole(**inpEMdip, **modHS, ab=ab, depth=0)\n    HS = empymod.analytical(**inpEM, **modFS, solution='dhs', ab=ab)\n    plot_f(EM, HS, 'Frequency HS', i)\nplt.figure('Frequency HS')\nplt.suptitle('Frequency HS')\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Fullspace\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "plt.figure('Frequency FS')\ni = 330\nfor ab in all_abs:\n    i += 1\n    EM = empymod.dipole(**inpEMdip, **modFS, ab=ab, depth=[])\n    HS = empymod.analytical(**inpEM, **modFS, solution='dfs', ab=ab)\n    plot_f(EM, HS, 'Frequency FS', i)\nplt.suptitle('Frequency FS')\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
}