{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Get the Venus plasma boundary positions\n",
    "\n",
    "Here we will get the plasma boundaries the bow shock and induced magnetosphere boundaries (sometimes call also as magnetic pileup boundary or ion composition boundaries).\n",
    "\n",
    "\n",
    "``Author: Yoshifumi Futaana``\n",
    "\n",
    "## Model from Venus Express, solar minimum\n",
    "\n",
    "The model is based on Martinecz et al., 2008. (doi: 10.1016/j.pss.2007.07.007)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### irfpy implementation to get the bow shock position\n",
    "\n",
    "``irfpy`` provides a function to get the boundary surface position.\n",
    "\n",
    "https://irfpy.irf.se/projects/planets/api/api_irfpy.venus.bowshock.html"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from irfpy.venus import bowshock"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "x_bs, r_bs = bowshock.xr_martinecz08()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "``x_bs`` and ``r_bs`` are numpy arrays that give the position of the bow shock in Rv."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.plot(x_bs, r_bs, 'b')   # Plot the data in the cylindrical coordinate\n",
    "\n",
    "# Figure decoration.\n",
    "plt.xlim(2, -10)\n",
    "plt.ylim(0, 7)\n",
    "plt.xlabel('X [Rv]')\n",
    "plt.ylabel('R [Rv]')\n",
    "plt.gca().set_aspect(1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### irfpy implementation to get the IMB (ICB) position\n",
    "\n",
    "https://irfpy.irf.se/projects/planets/api/api_irfpy.venus.icb.html\n",
    "\n",
    "It is the same interface to get the bow shock position."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from irfpy.venus import icb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "x_icb, r_icb = icb.xr_martinecz08()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.plot(x_icb, r_icb, 'r')   # Plot the data in the cylindrical coordinate\n",
    "\n",
    "# Figure decoration.\n",
    "plt.xlim(2, -10)\n",
    "plt.ylim(0, 7)\n",
    "plt.xlabel('X [Rv]')\n",
    "plt.ylabel('R [Rv]')\n",
    "plt.gca().set_aspect(1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Final plot\n",
    "Here is the final plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from matplotlib.patches import Circle   # Circle to represent Venus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.plot(x_bs, r_bs, 'b')   # Plot the BS data in the cylindrical coordinate\n",
    "plt.plot(x_icb, r_icb, 'r')   # Plot the ICB data in the cylindrical coordinate\n",
    "\n",
    "# Figure decoration.\n",
    "plt.gca().add_patch(Circle([0, 0], 1, color='y'))   # Add venus disk\n",
    "\n",
    "plt.xlim(2, -10)\n",
    "plt.ylim(0, 7)\n",
    "plt.xlabel('X [Rv]')\n",
    "plt.ylabel('R [Rv]')\n",
    "plt.gca().set_aspect(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "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.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}