{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Divergence free magnetic field\n\nThis example demonstrates the resulting angular profile of\nan SECS pole placed at the north pole. Figure 2 from\nAmm and Viljanen 1999.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\nimport numpy as np\nfrom pysecs import SECS\n\n# Radius of Earth\nR_E = 6378e3\n\n# Pole of the current system at the North Pole\nsec_loc = np.array([90., 0., R_E + 100e3])\n\n# Set up the system with a single SEC\nsystem_df = SECS(sec_df_loc=sec_loc)\n\n# Fit unit currents since we aren't fitting to any data\nsystem_df.fit_unit_currents()\n\n# Scale the system corresponding to Figure 2 of\n# Amm and Viljannen (1999) doi:10.1186/BF03352247\n# 10 kA\ntotal_current = 10000\nsystem_df.sec_amps *= total_current\n\n# Set up the prediction grid\nN = 1000\npred_loc = np.zeros(shape=(N, 3))\nangles = np.linspace(0, 45, N)\n\npred_loc[:, 0] = 90-angles\npred_loc[:, 2] = R_E\n\nB_pred = system_df.predict(pred_loc=pred_loc)\n\n# B_theta == -Bx == -B_pred[:,0]\n# Convert to nT (1e9)\nB_theta = -B_pred[:, 0]*1e9\n# B_r == -Bz = -B_pred[:,2]\nB_r = -B_pred[:, 2]*1e9\n\nfig, ax = plt.subplots()\n\nax.plot(angles, B_theta, c='b', label=r'B$_{\\theta}$')\nax.plot(angles, B_r, c='r', label=r'B$_r$')\nax.legend(loc='upper right')\nax.set_xlim(angles[0], angles[-1])\nax.set_ylim(-5, 10)\nax.set_xlabel('Angle from pole (deg)')\nax.set_ylabel('B (nT)')\nax.axhline(0., c='k', alpha=0.5, linewidth=0.5)\nax.set_title('Amm and Viljanen (1999) Figure 2')\n\nplt.show()"
      ]
    }
  ],
  "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.9"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}