Repository: PlasmaPy/PlasmaPy
Pull request #830 (2020-06-03 20:16:58)

Bohm diffusion coefficient
<!--
Thank you for contributing to PlasmaPy! Here's a bunch of pointers to
make things easier for all of us:

* If this PR will solve an issue tracked by GitHub, please add a phrase like
  "Closes #404." to automatically close the issue once the pull request is
  merged.  If your PR will not completely solve the issue, please still
  reference the issue. For an overview of this functionality, see
  https://help.github.com/articles/closing-issues-using-keywords/

* Remember to add some description of your changes in this text box.

* Tests and docstrings are required for new or changed functionality.
  Please make sure tests are passing before requesting a review - they
  will pop up at the bottom, in the Checks box. If you're unsure why
  they're failing, ask!
  
* If your pull request is not yet ready for review, submit it as a draft.
  Remember to change its' status once it's ready.

* If this is your first contribution, please add your name to the author
  list in `docs/about/credits.rst`.
  
* Feel free to chat with other developers on our Matrix channel at:
   https://riot.im/app/#/room/#plasmapy:openastronomy.org
  
* We have a developer's guide, where some answers to your questions may
  possibly be found, at
  http://docs.plasmapy.org/en/master/development/index.html

Many thanks in advance for following these pointers and for being willing to contribute!

When submitting a pull request, please ensure that you can (eventually,
sometime before it is merged) check the following basic requirements:

-->

- [x] I have added a changelog entry for this pull request (please see
  `changelog/README.rst` for instructions, and if you need help with picking the PR type, ask!)
- [x] If adding new functionality, I have added (passing) tests and
      docstrings. (Tests pop up at the bottom, in the checks box).
- [x] I have fixed any new failing tests (if you're unsure why
  they're failing, ask!).


codecov[bot]: # [Codecov](https://codecov.io/gh/PlasmaPy/PlasmaPy/pull/830?src=pr&el=h1) Report
> Merging [#830](https://codecov.io/gh/PlasmaPy/PlasmaPy/pull/830?src=pr&el=desc) into [master](https://codecov.io/gh/PlasmaPy/PlasmaPy/commit/25c81278e74d6e765e738a973975d790e6b83865&el=desc) will **increase** coverage by `0.00%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/PlasmaPy/PlasmaPy/pull/830/graphs/tree.svg?width=650&height=150&src=pr&token=LzZ5mnXVad)](https://codecov.io/gh/PlasmaPy/PlasmaPy/pull/830?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master     #830   +/-   ##
=======================================
  Coverage   95.88%   95.88%           
=======================================
  Files          56       56           
  Lines        5124     5127    +3     
=======================================
+ Hits         4913     4916    +3     
  Misses        211      211           
```


| [Impacted Files](https://codecov.io/gh/PlasmaPy/PlasmaPy/pull/830?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [plasmapy/formulary/parameters.py](https://codecov.io/gh/PlasmaPy/PlasmaPy/pull/830/diff?src=pr&el=tree#diff-cGxhc21hcHkvZm9ybXVsYXJ5L3BhcmFtZXRlcnMucHk=) | `98.88% <100.00%> (+0.02%)` | :arrow_up: |
| [plasmapy/particles/elements.py](https://codecov.io/gh/PlasmaPy/PlasmaPy/pull/830/diff?src=pr&el=tree#diff-cGxhc21hcHkvcGFydGljbGVzL2VsZW1lbnRzLnB5) | `100.00% <0.00%> (ø)` | |
| [plasmapy/data/test/\_\_init\_\_.py](https://codecov.io/gh/PlasmaPy/PlasmaPy/pull/830/diff?src=pr&el=tree#diff-cGxhc21hcHkvZGF0YS90ZXN0L19faW5pdF9fLnB5) | | |
| [plasmapy/particles/data/test/\_\_init\_\_.py](https://codecov.io/gh/PlasmaPy/PlasmaPy/pull/830/diff?src=pr&el=tree#diff-cGxhc21hcHkvcGFydGljbGVzL2RhdGEvdGVzdC9fX2luaXRfXy5weQ==) | `100.00% <0.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/PlasmaPy/PlasmaPy/pull/830?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/PlasmaPy/PlasmaPy/pull/830?src=pr&el=footer). Last update [25c8127...29d89fb](https://codecov.io/gh/PlasmaPy/PlasmaPy/pull/830?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md
index 3ff2d3f2..10c7aa02 100644
--- a/.github/PULL_REQUEST_TEMPLATE.md
+++ b/.github/PULL_REQUEST_TEMPLATE.md
@@ -15,7 +15,9 @@
   will pop up at the bottom, in the Checks box. If you're unsure why
   they're failing, ask!
   
-* If your pull request is not yet ready for review, submit it as a draft.
+* If your pull request is not yet ready for review - either because
+  you're just looking for feedback on a change or because you're not
+  perfectly satisfied with your change - submit it as a draft pull request.
   Remember to change its' status once it's ready.
 
 * If this is your first contribution, please add your name to the author
diff --git a/changelog/828.bugfix.rst b/changelog/828.bugfix.rst
new file mode 100644
index 00000000..2901783e
--- /dev/null
+++ b/changelog/828.bugfix.rst
@@ -0,0 +1,2 @@
+Repair notebook links that are defined in the `nbsphinx_prolog` sphinx configuration
+variable.
\ No newline at end of file
diff --git a/changelog/830.feature.rst b/changelog/830.feature.rst
new file mode 100644
index 00000000..78505f2e
--- /dev/null
+++ b/changelog/830.feature.rst
@@ -0,0 +1,1 @@
+Create :func:`~plasmapy.formulary.parameters.Bohm_diffusion` function.
diff --git a/changelog/835.bugfix.rst b/changelog/835.bugfix.rst
new file mode 100644
index 00000000..e1703ff3
--- /dev/null
+++ b/changelog/835.bugfix.rst
@@ -0,0 +1,1 @@
+Increase the required Astropy version from 3.1 to 4.0, Numpy from 1.14 to 1.16.6, Scipy from 0.19 to 1.2 and lmfit from 0.9.7 to 1.0.1. This fixes long-standing issues with Numpy operations dropping units from AstroPy quantities.
diff --git a/docs/conf.py b/docs/conf.py
index 06b0b864..5000c35c 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -21,6 +21,8 @@
 import os
 import sys
 
+from sphinx.application import Sphinx
+from pkg_resources import parse_version
 from plasmapy import __version__ as release
 
 sys.path.insert(0, os.path.abspath(".."))
@@ -81,8 +83,13 @@
 #        However, release needs to be a semantic style version number, so set
 #        the 'unknown' case to ''.
 release = "" if release == "unknown" else release
-# The short X.Y version.
-version = ".".join(release.split(".")[:2])
+if release == "unknown":
+    release = version = revision = ""
+else:
+    pv = parse_version(release)
+    release = pv.public
+    version = ".".join(release.split(".")[:2])  # short X.Y version
+    revision = pv.local[1:]  # revision number w/o the leading g
 
 
 # The language for content autogenerated by Sphinx. Refer to documentation
@@ -198,30 +205,21 @@
 
 # This is processed by Jinja2 and inserted before each notebook
 nbsphinx_prolog = r"""
-{% set docname = 'doc/' + env.doc2path(env.docname, base=None) %}
+{% set docname = 'docs/' + env.doc2path(env.docname, base=None) %}
+{% set nb_base = 'tree' if env.config.revision else 'blob' %}
+{% set nb_where = env.config.revision if env.config.revision else 'master' %}
+
 .. raw:: html
 
     <div class="admonition note">
-      <p>This page was generated from
-        <a class="reference external" href="https://github.com/PlasmaPy/PlasmaPy/blob/{{ env.config.release|e }}/{{ docname|e }}">{{ docname|e }}</a>.
+      <p style="margin-bottom:0px">
+        This page was generated by
+        <a href="https://nbsphinx.readthedocs.io/">nbsphinx</a> from
+        <a class="reference external" href="https://github.com/PlasmaPy/PlasmaPy/{{ nb_base|e }}/{{ nb_where|e }}/{{ docname|e }}">{{ docname|e }}</a>.
+        <br>
         Interactive online version:
-        <a href="https://mybinder.org/v2/gh/PlasmaPy/PlasmaPy/{{ env.config.release|e }}?filepath={{ docname|e }}"><img alt="Binder badge" src="https://mybinder.org/badge_logo.svg" style="vertical-align:text-bottom"></a>.
+        <a href="https://mybinder.org/v2/gh/PlasmaPy/PlasmaPy/{{ nb_where|e }}/?filepath={{ docname|e }}"><img alt="Binder badge" src="https://mybinder.org/badge_logo.svg" style="vertical-align:text-bottom"></a>.
       </p>
-      <script>
-        if (document.location.host) {
-          var p = document.currentScript.previousSibling.previousSibling;
-          var a = document.createElement('a');
-          a.innerHTML = 'View in <em>nbviewer</em>';
-          a.href = `https://nbviewer.jupyter.org/url${
-            (window.location.protocol == 'https:' ? 's/' : '/') +
-            window.location.host +
-            window.location.pathname.slice(0, -4) }ipynb`;
-          a.classList.add('reference');
-          a.classList.add('external');
-          p.appendChild(a);
-          p.appendChild(document.createTextNode('.'));
-        }
-      </script>
     </div>
 
 .. raw:: latex
@@ -230,3 +228,7 @@
     \textcolor{gray}{The following section was generated from
     \sphinxcode{\sphinxupquote{\strut {{ docname | escape_latex }}}} \dotfill}}
 """
+
+
+def setup(app: Sphinx) -> None:
+    app.add_config_value("revision", "", True)
diff --git a/docs/install.rst b/docs/install.rst
index dbfba489..72b776a9 100644
--- a/docs/install.rst
+++ b/docs/install.rst
@@ -18,9 +18,9 @@ Requirements
 PlasmaPy requires Python version 3.6 or newer.
 PlasmaPy requires the following packages for installation:
 
-- `NumPy <http://www.numpy.org/>`_ 1.14 or newer
-- `SciPy <https://www.scipy.org/>`_ 0.19 or newer
-- `Astropy <http://www.astropy.org/>`_ 3.1 or newer
+- `NumPy <http://www.numpy.org/>`_ 1.16.6 or newer
+- `SciPy <https://www.scipy.org/>`_ 1.2 or newer
+- `Astropy <http://www.astropy.org/>`_ 4.0 or newer
 - `colorama <https://pypi.org/project/colorama/>`_ 0.3 or newer
 
 PlasmaPy also depends on the following packages for optional features:
@@ -28,7 +28,7 @@ PlasmaPy also depends on the following packages for optional features:
 - `matplotlib <https://matplotlib.org/>`_ 2.0 or newer
 - `h5py <https://www.h5py.org/>`_ 2.8 or newer
 - `mpmath <http://mpmath.org/>`_ 1.0 or newer
-- `lmfit <https://lmfit.github.io/lmfit-py/>`_ 0.9.7 or newer
+- `lmfit <https://lmfit.github.io/lmfit-py/>`_ 1.0.1 or newer
 
 .. _install-process:
 
diff --git a/plasmapy/formulary/dimensionless.py b/plasmapy/formulary/dimensionless.py
index 88777a90..47e3e2b9 100644
--- a/plasmapy/formulary/dimensionless.py
+++ b/plasmapy/formulary/dimensionless.py
@@ -8,7 +8,7 @@
 highly turbulent, while turbulence is negligible at low Reynolds
 numbers.
 """
-__all__ = ["beta", "quantum_theta", "Reynolds_number"]
+__all__ = ["beta", "quantum_theta", "Reynolds_number", "Mag_Reynolds"]
 
 from astropy import constants
 from astropy import units as u
diff --git a/plasmapy/formulary/parameters.py b/plasmapy/formulary/parameters.py
index 20a1c648..e5010ce9 100644
--- a/plasmapy/formulary/parameters.py
+++ b/plasmapy/formulary/parameters.py
@@ -20,6 +20,7 @@
     "magnetic_energy_density",
     "upper_hybrid_frequency",
     "lower_hybrid_frequency",
+    "Bohm_diffusion",
 ]
 
 import numbers
@@ -218,7 +219,7 @@ def Alfven_speed(
     >>> Alfven_speed(B, rho, ion)
     <Quantity 43173.870... m / s>
     >>> Alfven_speed(B, rho, ion).to(u.cm/u.us)
-    <Quantity 4.31738... cm / us>
+    <Quantity 4.317387 cm / us>
 
     """
     rho = mass_density(density, ion, z_mean)
@@ -1588,3 +1589,58 @@ def lower_hybrid_frequency(B: u.T, n_i: u.m ** -3, ion="p+") -> u.rad / u.s:
     omega_lh = omega_lh
 
     return omega_lh
+
+
+@validate_quantities(
+    T_e={"can_be_negative": False, "equivalencies": u.temperature_energy()},
+    B={"can_be_negative": False})
+def Bohm_diffusion(T_e: u.K, B: u.T) -> u.m ** 2 / u.s:
+
+    r"""
+    The Bohm diffusion coefficient was conjectured to follow Bohm model of
+    the diffusion of plasma across a magnetic field and describe
+    the diffusion of early fusion energy machines.
+    The rate predicted by Bohm diffusion is much higher than classical diffusion
+    and if there were no exceptions, magnetically confined fusion would be impractical.
+
+    Parameters
+    ----------
+    T_e: `~astropy.units.Quantity`
+        The electron temperature.
+    B: `~astropy.units.Quantity`
+        The magnitude of the magnetic field in the plasma.
+
+    Warns
+    -----
+    ~astropy.units.UnitsWarning
+        If units are not provided, SI units are assumed.
+
+    Raises
+    ------
+    TypeError
+        The `T_e` is not a `~astropy.units.Quantity` and cannot be
+        converted into a ~astropy.units.Quantity.
+
+    ~astropy.units.UnitConversionError
+        If the `T_e` is not in appropriate units.
+
+    Examples
+    --------
+    >>> import astropy.units as u
+    >>> T_e = 5000 * u.K
+    >>> B = 10 * u.T
+    >>> Bohm_diffusion(T_e, B)
+    <Quantity 0.00269292 m2 / s>
+    >>> T_e = 50 * u.eV
+    >>> B = 10 * u.T
+    >>> Bohm_diffusion(T_e, B)
+    <Quantity 0.3125 m2 / s>
+
+    Returns
+    -------
+    D_B: `~astropy.units.Quantity`
+    The Bohm diffusion coefficient in meters squared per second.
+
+    """
+    D_B = k_B * T_e / (16 * e * B)
+    return D_B
diff --git a/requirements/requirements.txt b/requirements/requirements.txt
index af1d28f7..0a968d30 100644
--- a/requirements/requirements.txt
+++ b/requirements/requirements.txt
@@ -1,10 +1,10 @@
 # Required Packages w/ version
-astropy >= 3.1
+astropy >= 4.0
 colorama >= 0.3
 h5py >= 2.8
-lmfit >= 0.9.7
+lmfit >= 1.0.1
 matplotlib >= 2.0
 mpmath >= 1.0.0
-numpy >= 1.14
-scipy >= 0.19
+numpy >= 1.16.6
+scipy >= 1.2
 setuptools >= 41.2
diff --git a/setup.cfg b/setup.cfg
index 46a8edb6..bdeb69e3 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -30,10 +30,10 @@ packages = find:
 include_package_data = True
 setup_requires = setuptools_scm
 install_requires =
-  astropy >= 3.1
+  astropy >= 4.0
   colorama >= 0.3
-  numpy >= 1.14
-  scipy >= 0.19
+  numpy >= 1.16.6
+  scipy >= 1.2
   setuptools >= 41.2
 
 [options.extras_require]
diff --git a/tox.ini b/tox.ini
index b1b08d96..e090249c 100644
--- a/tox.ini
+++ b/tox.ini
@@ -45,14 +45,13 @@ deps =
   pytest-cov
   pytest-xdist
 conda_deps =
-  numpy>=1.14
-  scipy>=0.19
-  astropy>=3.1
+  numpy>=1.16.6
+  scipy>=1.2
+  astropy>=4.0
   colorama>=0.3
   pytest>=5.1
   h5py
   matplotlib
-  pytest
   mpmath
   numpydoc
   pillow
@@ -65,22 +64,19 @@ commands = {env:PYTEST_COMMAND} {posargs}
 basepython = python3.6
 extras =
 deps =
-  lmfit==0.9.7
+  lmfit==1.0.1
   pytest-cov
   pytest-xdist
 conda_deps =
-  numpy=1.14
-  scipy=0.19
-  astropy=3.1
+  numpy=1.16.6
+  scipy=1.2
+  astropy=4.0
   colorama=0.3
   h5py=2.8
   matplotlib=2.0
   pytest=5.1
   mpmath=1.0
-  numpydoc
   pillow
-  sphinx
-  sphinx_rtd_theme
 commands = {env:PYTEST_COMMAND} {posargs}
 
 [testenv:py36-minimal-pypi-import]


Test patch:
diff --git a/plasmapy/formulary/tests/test_parameters.py b/plasmapy/formulary/tests/test_parameters.py
index 4f116ed1..e4cb2bf9 100644
--- a/plasmapy/formulary/tests/test_parameters.py
+++ b/plasmapy/formulary/tests/test_parameters.py
@@ -28,6 +28,7 @@
     magnetic_pressure,
     upper_hybrid_frequency,
     lower_hybrid_frequency,
+    Bohm_diffusion,
 )
 
 B = 1.0 * u.T
@@ -1039,3 +1040,20 @@ def test_lower_hybrid_frequency():
             1.3 * u.T, 1e19 * u.m ** -3
         )
     assert_can_handle_nparray(lower_hybrid_frequency)
+
+
+def test_Bohm_diffusion():
+    r"""Test Mag_Reynolds in dimensionless.py"""
+
+    T_e = 5000 * u.K
+    B = 10 * u.T
+
+    assert (
+            Bohm_diffusion(T_e, B)
+           ).unit == u.m ** 2 / u.s
+
+    with pytest.warns(u.UnitsWarning):
+        Bohm_diffusion(5000, B)
+
+    with pytest.raises(u.UnitTypeError):
+        Bohm_diffusion(2.2 * u.kg, B)