Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor updates to magnetostatics notebook #1588

Merged
merged 6 commits into from Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/1588.doc.rst
@@ -0,0 +1,3 @@
Renamed the :file:`magnetic_statics.ipynb` notebook to
:file:`magnetostatics.ipynb`, and made some minor edits to its text
and plotting code.
@@ -1,63 +1,56 @@
{
"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",
namurphy marked this conversation as resolved.
Show resolved Hide resolved
"import astropy.units as u\n",
"import matplotlib.pyplot as plt\n",
"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]"
]
},
{
"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
}
Expand All @@ -74,15 +67,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
}
Expand All @@ -100,15 +91,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
}
Expand All @@ -126,7 +115,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
},
Expand All @@ -140,29 +128,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": [
Expand All @@ -176,15 +167,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
}
Expand All @@ -198,19 +187,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
}
Expand All @@ -227,27 +207,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
}
Expand All @@ -256,25 +238,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
}
Expand All @@ -287,19 +268,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
}
Expand All @@ -312,28 +284,28 @@
" 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",
"U = plasma.magnetic_field[0, :, 0, :].value.T # because grid uses 'ij' indexing\n",
"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"
},
Expand All @@ -346,8 +318,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": {
Expand Down