{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\nLangmuir probe data analysis\n============================\n\nLet's analyze a few Langmuir probe characteristics using the\n`diagnostics.langmuir` subpackage. First we need to import the module and some\nbasics.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from plasmapy.diagnostics.langmuir import Characteristic, swept_probe_analysis\nimport astropy.units as u\nimport numpy as np\nimport pickle\nimport os"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "The first characteristic we analyze is a simple single-probe measurement in\na low (ion) temperature, low density plasma with a cylindrical probe. This\nallows us to utilize OML theory implemented in `swept_probe_analysis`.\nThe data has been preprocessed with some smoothing, which allows us to obtain\na Electron Energy Distribution Function (EEDF) as well.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# Load the bias and current values stored in the .p pickle file.\npath = os.path.join(\"langmuir_samples\", \"Beckers2017.p\")\nbias, current = pickle.load(open(path, 'rb'))\n\n# Create the Characteristic object, taking into account the correct units\ncharacteristic = Characteristic(np.array(bias) * u.V,\n                                np.array(current)*1e3 * u.mA)\n\n# Calculate the cylindrical probe surface area\nprobe_length = 1.145 * u.mm\nprobe_diameter = 1.57 * u.mm\nprobe_area = (probe_length * np.pi * probe_diameter +\n              np.pi * 0.25 * probe_diameter**2)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Now we can actually perform the analysis. Since the plasma is in Helium an\nion mass number of 4 is entered. The results are visualized and the obtained\nEEDF is also shown.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "print(swept_probe_analysis(characteristic,\n                           probe_area, 4 * u.u,\n                           visualize=True,\n                           plot_EEDF=True))"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "The cyan and yellow lines indicate the fitted electron and ion currents,\nrespectively. The green line is the sum of these and agrees nicely with the\ndata. This indicates a succesfull analysis.\n\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "The next sample probe data is provided by David Pace. is also obtained from a low relatively ion\ntemperature and density plasma, in Argon.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# Load the data from a file and create the Characteristic object\npath = os.path.join(\"langmuir_samples\", \"Pace2015.p\")\nbias, current = pickle.load(open(path, 'rb'))\ncharacteristic = Characteristic(np.array(bias) * u.V,\n                                np.array(current) * 1e3 * u.mA)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Initially the electrons are assumed to be Maxwellian. To check this the fit\nof the electron growth region will be plotted.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "swept_probe_analysis(characteristic,\n                     0.738 * u.cm**2,\n                     40 * u.u,\n                     bimaxwellian=False,\n                     plot_electron_fit=True)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "It can be seen that this plasma is slightly bi-Maxwellian, as there are two\ndistinct slopes in the exponential section. The analysis is now performed\nwith bimaxwellian set to True, which yields improved results.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "print(swept_probe_analysis(characteristic,\n                           0.738 * u.cm**2,\n                           40 * u.u,\n                           bimaxwellian=True,\n                           visualize=True,\n                           plot_electron_fit=True))"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "The probe current resolution of the raw data is relatively poor, but the\nanalysis still performs well in the ion current region. The bi-Maxwellian\nproperties are not significant but do make a difference. Check this analysis\nwithout setting `bimaxwellian` to True!\nThis is reflected in the results, which indicate that the temperatures of\nthe cold and hot electron population are indeed different, but relatively\nclose.\n\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "This Helium plasma is fully bi-Maxwellian.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# Import probe data and calculate probe surface area.\npath = os.path.join(\"langmuir_samples\", \"Beckers2017b.p\")\nbias, current = pickle.load(open(path, 'rb'))\ncharacteristic = Characteristic(np.array(bias) * u.V,\n                                np.array(current) * 1e3 * u.mA)\nprobe_length = 1.145 * u.mm\nprobe_diameter = 1.57 * u.mm\nprobe_area = (probe_length * np.pi * probe_diameter +\n              np.pi * 0.25 * probe_diameter**2)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "`plot_electron_fit` is set to True to check the bi-Maxwellian properties.\nThe fit converges nicely to the two slopes of the electron growth region.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "print(swept_probe_analysis(characteristic,\n                           probe_area,\n                           4 * u.u,\n                           bimaxwellian=True,\n                           plot_electron_fit=True,\n                           visualize=True))"
      ]
    }
  ],
  "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.6.5"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}