{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib notebook"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\nPoint dipole vs finite length dipole\n====================================\n\nComparison of a 800 m long bipole with a dipole at its centre.\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 models\n-------------\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "name = 'Example Model'         # Model name\ndepth = [0, 300, 1000, 1200]   # Layer boundaries\nres = [2e14, 0.3, 1, 50, 1]    # Anomaly resistivities\nresBG = [2e14, 0.3, 1, 1, 1]   # Background resistivities\naniso = [1, 1, 1.5, 1.5, 1.5]  # Layer anis. (same for anomaly and background)\n\n# Modelling parameters\nverb = 2\n\n# Spatial parameters\nzsrc = 250                   # Src-depth\nzrec = 300                   # Rec-depth\nfx = np.arange(5, 101)*100   # Offsets\nfy = np.zeros(fx.size)       # 0s"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Plot models\n~~~~~~~~~~~\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "pdepth = np.repeat(np.r_[-100, depth], 2)\npdepth[:-1] = pdepth[1:]\npdepth[-1] = 2*depth[-1]\npres = np.repeat(res, 2)\npresBG = np.repeat(resBG, 2)\npani = np.repeat(aniso, 2)\n\n# Create figure\nfig = plt.figure(figsize=(7, 5), facecolor='w')\nfig.subplots_adjust(wspace=.25, hspace=.4)\nplt.suptitle(name, fontsize=20)\n\n# Plot Resistivities\nax1 = plt.subplot(1, 2, 1)\nplt.plot(pres, pdepth, 'r')\nplt.plot(presBG, pdepth, 'k')\nplt.xscale('log')\nplt.xlim([.2*np.array(res).min(), 2*np.array(res)[1:].max()])\nplt.ylim([1.5*depth[-1], -100])\nplt.ylabel('Depth (m)')\nplt.xlabel(r'Resistivity $\\rho_h\\ (\\Omega\\,\\rm{m})$')\n\n# Plot anisotropies\nax2 = plt.subplot(1, 2, 2)\nplt.plot(pani, pdepth, 'k')\nplt.xlim([0, 2])\nplt.ylim([1.5*depth[-1], -100])\nplt.xlabel(r'Anisotropy $\\lambda (-)$')\nax2.yaxis.tick_right()\n\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Frequency response for f = 1 Hz\n-------------------------------\n\nCompute\n~~~~~~~\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# Dipole\ninpdat = {'src': [0, 0, zsrc, 0, 0], 'rec': [fx, fy, zrec, 0, 0],\n          'depth': depth, 'freqtime': 1, 'aniso': aniso,\n          'htarg': {'pts_per_dec': -1}, 'verb': verb}\nfEM = empymod.bipole(**inpdat, res=res)\nfEMBG = empymod.bipole(**inpdat, res=resBG)\n\n# Bipole\ninpdat['src'] = [-400, 400, 0, 0, zsrc, zsrc]\ninpdat['srcpts'] = 10\nfEMbp = empymod.bipole(**inpdat, res=res)\nfEMBGbp = empymod.bipole(**inpdat, res=resBG)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Plot\n~~~~\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig = plt.figure(figsize=(8, 6), facecolor='w')\nfig.subplots_adjust(wspace=.25, hspace=.4)\nfig.suptitle(name+': src-x, rec-x; f = 1 Hz', fontsize=16, y=1)\n\n# Plot Amplitude\nax1 = plt.subplot(2, 2, 1)\nplt.semilogy(fx/1000, fEMBG.amp(), label='BG')\nplt.semilogy(fx/1000, fEM.amp(), label='Anomaly')\nplt.semilogy(fx/1000, fEMBGbp.amp(), '--', label='BG bipole')\nplt.semilogy(fx/1000, fEMbp.amp(), '--', label='Anomaly bipole')\nplt.legend(loc='best')\nplt.title(r'Amplitude ($V/(A\\ $m$^2$))')\nplt.xlabel('Offset (km)')\n\n# Plot Phase\nax2 = plt.subplot(2, 2, 2)\nplt.title(r'Phase ($^\\circ$)')\nplt.plot(fx/1000, fEMBG.pha(deg=True), label='BG')\nplt.plot(fx/1000, fEM.pha(deg=True), label='Anomaly')\nplt.plot(fx/1000, fEMBGbp.pha(deg=True), '--', label='BG bipole')\nplt.plot(fx/1000, fEMbp.pha(deg=True), '--', label='Anomaly bipole')\nplt.xlabel('Offset (km)')\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.7.3"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}