{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "Cold Magnetized Plasma Waves Tensor Elements (S, D, P in Stix's notation)\n", "=========================================================================\n", "\n", "This example shows how to calculate the values of the cold plasma tensor\n", "elements for various electromagnetic wave frequencies.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "import numpy as np\n", "\n", "from astropy import units as u\n", "\n", "from plasmapy.formulary import (\n", " cold_plasma_permittivity_LRP,\n", " cold_plasma_permittivity_SDP,\n", ")" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "Take a look at the docs to :func:`~plasmapy.formulary.dielectric.cold_plasma_permittivity_SDP` and :func:`~plasmapy.formulary.dielectric.cold_plasma_permittivity_LRP` for more information on these." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's define some parameters, such as the magnetic field magnitude,\n", "the plasma species and densities and the frequency band of interest\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [], "source": [ "B = 2 * u.T\n", "species = [\"e\", \"D+\"]\n", "n = [1e18 * u.m ** -3, 1e18 * u.m ** -3]\n", "\n", "f = np.logspace(start=6, stop=11.3, num=3001) # 1 MHz to 200 GHz\n", "omega_RF = f * (2 * np.pi) * (u.rad / u.s)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [], "source": [ "help(cold_plasma_permittivity_SDP)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [], "source": [ "S, D, P = cold_plasma_permittivity_SDP(B, species, n, omega_RF)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Filter positive and negative values, for display purposes only.\n", "Still for display purposes, replace 0 by NaN to NOT plot 0 values\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [], "source": [ "S_pos = S * (S > 0)\n", "D_pos = D * (D > 0)\n", "P_pos = P * (P > 0)\n", "S_neg = S * (S < 0)\n", "D_neg = D * (D < 0)\n", "P_neg = P * (P < 0)\n", "S_pos[S_pos == 0] = np.NaN\n", "D_pos[D_pos == 0] = np.NaN\n", "P_pos[P_pos == 0] = np.NaN\n", "S_neg[S_neg == 0] = np.NaN\n", "D_neg[D_neg == 0] = np.NaN\n", "P_neg[P_neg == 0] = np.NaN" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false }, "tags": [ "nbsphinx-thumbnail" ] }, "outputs": [], "source": [ "plt.figure(figsize=(12, 6))\n", "plt.semilogx(f, abs(S_pos), f, abs(D_pos), f, abs(P_pos), lw=2)\n", "plt.semilogx(\n", " f,\n", " abs(S_neg),\n", " \"#1f77b4\",\n", " f,\n", " abs(D_neg),\n", " \"#ff7f0e\",\n", " f,\n", " abs(P_neg),\n", " \"#2ca02c\",\n", " lw=2,\n", " ls=\"--\",\n", ")\n", "plt.yscale(\"log\")\n", "plt.grid(True, which=\"major\")\n", "plt.grid(True, which=\"minor\")\n", "plt.ylim(1e-4, 1e8)\n", "plt.xlim(1e6, 200e9)\n", "plt.legend((\"S > 0\", \"D > 0\", \"P > 0\", \"S < 0\", \"D < 0\", \"P < 0\"), fontsize=16, ncol=2)\n", "plt.xlabel(\"RF Frequency [Hz]\", size=16)\n", "plt.ylabel(\"Absolute value\", size=16)\n", "plt.tick_params(labelsize=14)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Cold Plasma tensor elements in the rotating basis\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [], "source": [ "L, R, P = cold_plasma_permittivity_LRP(B, species, n, omega_RF)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [], "source": [ "L_pos = L * (L > 0)\n", "R_pos = R * (R > 0)\n", "L_neg = L * (L < 0)\n", "R_neg = R * (R < 0)\n", "L_pos[L_pos == 0] = np.NaN\n", "R_pos[R_pos == 0] = np.NaN\n", "L_neg[L_neg == 0] = np.NaN\n", "R_neg[R_neg == 0] = np.NaN\n", "\n", "plt.figure(figsize=(12, 6))\n", "plt.semilogx(f, abs(L_pos), f, abs(R_pos), f, abs(P_pos), lw=2)\n", "plt.semilogx(\n", " f,\n", " abs(L_neg),\n", " \"#1f77b4\",\n", " f,\n", " abs(R_neg),\n", " \"#ff7f0e\",\n", " f,\n", " abs(P_neg),\n", " \"#2ca02c\",\n", " lw=2,\n", " ls=\"--\",\n", ")\n", "plt.yscale(\"log\")\n", "plt.grid(True, which=\"major\")\n", "plt.grid(True, which=\"minor\")\n", "plt.xlim(1e6, 200e9)\n", "plt.legend((\"L > 0\", \"R > 0\", \"P > 0\", \"L < 0\", \"R < 0\", \"P < 0\"), fontsize=16, ncol=2)\n", "plt.xlabel(\"RF Frequency [Hz]\", size=16)\n", "plt.ylabel(\"Absolute value\", size=16)\n", "plt.tick_params(labelsize=14)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Checks if the values obtained are coherent. They should satisfy\n", "S = (R+L)/2 and D = (R-L)/2\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [], "source": [ "try:\n", " np.testing.assert_allclose(S, (R + L) / 2)\n", " np.testing.assert_allclose(D, (R - L) / 2)\n", "except AssertionError as e:\n", " print(e)\n", "# Checks for R=S+D and L=S-D\n", "try:\n", " np.testing.assert_allclose(R, S + D)\n", " np.testing.assert_allclose(L, S - D)\n", "except AssertionError as e:\n", " print(e)" ] } ], "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.9.1" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 4 }