From c0f6503fd66df44b64fb6c4c0e80c80a60d36ca5 Mon Sep 17 00:00:00 2001 From: Nick Murphy Date: Fri, 17 Jun 2022 20:24:23 -0400 Subject: [PATCH 1/5] Rename notebook --- docs/notebooks/{magnetic_statics.ipynb => magnetostatics.ipynb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename docs/notebooks/{magnetic_statics.ipynb => magnetostatics.ipynb} (100%) diff --git a/docs/notebooks/magnetic_statics.ipynb b/docs/notebooks/magnetostatics.ipynb similarity index 100% rename from docs/notebooks/magnetic_statics.ipynb rename to docs/notebooks/magnetostatics.ipynb From a5cd222adb062ec1fdc927096211ffc11d7fa92d Mon Sep 17 00:00:00 2001 From: Nick Murphy Date: Fri, 17 Jun 2022 20:47:40 -0400 Subject: [PATCH 2/5] Update magnetostatics notebook --- docs/notebooks/magnetostatics.ipynb | 123 +++++++++++----------------- 1 file changed, 46 insertions(+), 77 deletions(-) diff --git a/docs/notebooks/magnetostatics.ipynb b/docs/notebooks/magnetostatics.ipynb index c8db9bdcb4..9f1a947a36 100644 --- a/docs/notebooks/magnetostatics.ipynb +++ b/docs/notebooks/magnetostatics.ipynb @@ -1,41 +1,35 @@ { "cells": [ { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false, - "jupyter": { - "outputs_hidden": false - } - }, - "outputs": [], + "cell_type": "markdown", + "metadata": {}, "source": [ - "%matplotlib inline" + "Magnetostatic Fields\n", + "=================" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ + "[magnetostatics]: https://docs.plasmapy.org/en/stable/formulary/magnetostatics.html\n", + "[plasmapy.formulary]: https://docs.plasmapy.org/en/stable/formulary/\n", "\n", - "Magnetostatic Fields\n", - "=====================\n", - "\n", - "An example of using PlasmaPy's `Magnetostatic` class in `physics` subpackage.\n" + "This notebook presents examples of using PlasmaPy's [magnetostatics] module in [plasmapy.formulary]." ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [], "source": [ + "%matplotlib inline\n", + "\n", "import astropy.units as u\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", @@ -48,16 +42,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Some common magnetostatic fields can be generated and added to a plasma object.\n", - "A dipole\n", - "\n" + "Common magnetostatic fields, like those from a magnetic dipole, can be generated and added to a plasma object." ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false, "jupyter": { "outputs_hidden": false } @@ -74,15 +65,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "initialize a a plasma, where the magnetic field will be calculated on\n", - "\n" + "First, we will initialize a plasma on which the magnetic field will be calculated." ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false, "jupyter": { "outputs_hidden": false } @@ -100,15 +89,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "add the dipole field to it\n", - "\n" + "Let's then add the dipole field to it, and plot the results." ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false, "jupyter": { "outputs_hidden": false } @@ -126,7 +113,6 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false, "jupyter": { "outputs_hidden": false }, @@ -140,29 +126,32 @@ "plt.axis(\"square\")\n", "plt.xlim(-2, 2)\n", "plt.ylim(-2, 2)\n", - "plt.title(\n", - " \"Dipole field in x-z plane, generated by a dipole pointing in the z direction\"\n", - ")\n", - "plt.streamplot(plasma.x.value, plasma.z.value, U, W)" + "plt.xlabel(\"x\")\n", + "plt.ylabel(\"z\")\n", + "plt.title(\"Dipole magnetic field\")\n", + "plt.streamplot(plasma.x.value, plasma.z.value, U, W)\n", + "plt.show()" ] }, { - "cell_type": "raw", + "cell_type": "markdown", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ - "A circular current-carring wire (:class:`~plasmapy.formulary.magnetostatics.CircularWire`)\n" + "[CircularWire]: https://docs.plasmapy.org/en/stable/api/plasmapy.formulary.magnetostatics.CircularWire.html#plasmapy.formulary.magnetostatics.CircularWire\n", + "\n", + "Next let's calculate the magnetic field from a current-carrying loop with [CircularWire]." ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false, "jupyter": { "outputs_hidden": false - } + }, + "scrolled": true }, "outputs": [], "source": [ @@ -176,15 +165,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "initialize a a plasma, where the magnetic field will be calculated on\n", - "\n" + "Let's initialize another plasma object, add the magnetic field from the circular wire to it, and plot the result." ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false, "jupyter": { "outputs_hidden": false } @@ -198,19 +185,10 @@ ")" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "add the circular coil field to it\n", - "\n" - ] - }, { "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false, "jupyter": { "outputs_hidden": false } @@ -227,27 +205,29 @@ "plt.axis(\"square\")\n", "plt.xlim(-2, 2)\n", "plt.ylim(-2, 2)\n", - "plt.title(\n", - " \"Circular coil field in x-z plane, generated by a circular coil in the x-y plane\"\n", - ")\n", - "plt.streamplot(plasma.x.value, plasma.z.value, U, W)" + "plt.xlabel(\"x\")\n", + "plt.ylabel(\"z\")\n", + "plt.title(\"Magnetic field from a circular coil\")\n", + "plt.tight_layout()\n", + "plt.streamplot(plasma.x.value, plasma.z.value, U, W)\n", + "plt.show()" ] }, { - "cell_type": "raw", + "cell_type": "markdown", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ - "a circular wire can be described as parametric equation and converted to :class:`~plasmapy.formulary.magnetostatics.GeneralWire`\n", - "\n" + "[GeneralWire]: https://docs.plasmapy.org/en/stable/api/plasmapy.formulary.magnetostatics.GeneralWire.html#plasmapy.formulary.magnetostatics.GeneralWire\n", + "\n", + "A circular wire can be described as parametric equation and converted to a [GeneralWire]. Let's do that, and check that the resulting magnetic fields are close." ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false, "jupyter": { "outputs_hidden": false } @@ -256,25 +236,24 @@ "source": [ "gw_cw = cw.to_GeneralWire()\n", "\n", - "# the calculated magnetic field is close\n", "print(gw_cw.magnetic_field([0, 0, 0]) - cw.magnetic_field([0, 0, 0]))" ] }, { - "cell_type": "raw", + "cell_type": "markdown", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ - "A infinite straight wire (:class:`~plasmapy.formulary.magnetostatics.InfiniteStraightWire`)\n", - "\n" + "[InfiniteStraightWire]: https://docs.plasmapy.org/en/stable/api/plasmapy.formulary.magnetostatics.InfiniteStraightWire.html#plasmapy.formulary.magnetostatics.InfiniteStraightWire\n", + "\n", + "Finally, let's use [InfiniteStraightWire] to calculate the magnetic field from an infinite straight wire, add it to a plasma object, and plot the results." ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false, "jupyter": { "outputs_hidden": false } @@ -287,19 +266,10 @@ "print(iw)" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "initialize a a plasma, where the magnetic field will be calculated on\n", - "\n" - ] - }, { "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": false, "jupyter": { "outputs_hidden": false } @@ -312,7 +282,6 @@ " domain_z=np.linspace(-2, 2, 20) * u.m,\n", ")\n", "\n", - "# add the infinite straight wire field to it\n", "plasma.add_magnetostatic(iw)\n", "\n", "X, Z = plasma.grid[0, :, 0, :], plasma.grid[2, :, 0, :]\n", @@ -320,20 +289,21 @@ "W = plasma.magnetic_field[2, :, 0, :].value.T # because grid uses 'ij' indexing\n", "\n", "plt.figure()\n", - "plt.title(\n", - " \"Dipole field in x-z plane, generated by a infinite straight wire \"\n", - " \"pointing in the y direction\"\n", - ")\n", + "plt.title(\"Magnetic field from an infinite straight wire\")\n", "plt.axis(\"square\")\n", "plt.xlim(-2, 2)\n", "plt.ylim(-2, 2)\n", - "plt.streamplot(plasma.x.value, plasma.z.value, U, W)" + "plt.xlabel(\"x\")\n", + "plt.ylabel(\"z\")\n", + "plt.tight_layout()\n", + "plt.streamplot(plasma.x.value, plasma.z.value, U, W)\n", + "plt.show()" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -346,8 +316,7 @@ "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.8.2" + "pygments_lexer": "ipython3" }, "widgets": { "application/vnd.jupyter.widget-state+json": { From 7568e71203c511542c0bc547801b21e07cd4cd03 Mon Sep 17 00:00:00 2001 From: Nick Murphy Date: Fri, 17 Jun 2022 21:07:43 -0400 Subject: [PATCH 3/5] Add changelog entry --- changelog/1588.doc.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog/1588.doc.rst diff --git a/changelog/1588.doc.rst b/changelog/1588.doc.rst new file mode 100644 index 0000000000..fcdab7d3e5 --- /dev/null +++ b/changelog/1588.doc.rst @@ -0,0 +1,3 @@ +Renamed the :file:`magnetic_statics.ipynb` to +:file:`magnetostatics.ipynb`, and made some minor edits to the text +and plotting code in this example notebook. From 5c199ae82918d61891a4c45301e8a263bed9be76 Mon Sep 17 00:00:00 2001 From: Nick Murphy Date: Fri, 17 Jun 2022 21:33:29 -0400 Subject: [PATCH 4/5] Update changelog entry --- changelog/1588.doc.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/changelog/1588.doc.rst b/changelog/1588.doc.rst index fcdab7d3e5..829464fffc 100644 --- a/changelog/1588.doc.rst +++ b/changelog/1588.doc.rst @@ -1,3 +1,3 @@ -Renamed the :file:`magnetic_statics.ipynb` to -:file:`magnetostatics.ipynb`, and made some minor edits to the text -and plotting code in this example notebook. +Renamed the :file:`magnetic_statics.ipynb` notebook to +:file:`magnetostatics.ipynb`, and made some minor edits to its text +and plotting code. From 9bc050b0996d1c8cd6a9cadc558ce2571096ef84 Mon Sep 17 00:00:00 2001 From: Nick Murphy Date: Tue, 21 Jun 2022 11:36:53 -0400 Subject: [PATCH 5/5] Set default size for notebooks --- docs/notebooks/magnetostatics.ipynb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/notebooks/magnetostatics.ipynb b/docs/notebooks/magnetostatics.ipynb index 9f1a947a36..cc0bca7d5a 100644 --- a/docs/notebooks/magnetostatics.ipynb +++ b/docs/notebooks/magnetostatics.ipynb @@ -35,7 +35,9 @@ "import numpy as np\n", "\n", "from plasmapy.formulary import magnetostatics\n", - "from plasmapy.plasma.sources import Plasma3D" + "from plasmapy.plasma.sources import Plasma3D\n", + "\n", + "plt.rcParams[\"figure.figsize\"] = [10.5, 10.5]" ] }, {