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

Update classes & docs for ionization states and fix docstring formatting in plasmapy.particles #796

Merged
merged 105 commits into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
40da515
Add narrative documentation for IonizationState(s)
namurphy May 4, 2020
63c2b1a
Fix ReST error
namurphy May 4, 2020
cc20e9f
Replace State namedtuple with new IonicFraction class
namurphy May 5, 2020
fde8561
Rename IonizationStates to IonizationStateCollection
namurphy May 5, 2020
c27ac33
Change States namedtuple to IonicFractions class
namurphy May 6, 2020
5763b83
Use black to reformat ionization state files
namurphy May 6, 2020
2d9d488
Use isort to sort imports
namurphy May 6, 2020
afdd766
Test for default cases for IonicFraction
namurphy May 6, 2020
cc6336c
Fix ReST link error
namurphy May 6, 2020
04aac8d
Add changelog for ionization state narrative docs
namurphy May 6, 2020
2190e4b
Add changelog for narrative documentation on ionization states
namurphy May 6, 2020
391a61a
Improve docstrings for ionization state classes
namurphy May 6, 2020
ff6163f
Allow IonizationState to accept an ion as an argument
namurphy May 7, 2020
879f4a5
Update changelogs for ionization state functionality
namurphy May 7, 2020
0024549
Rename test file for IonizationStateCollection
namurphy May 7, 2020
61402be
Rename module holding IonizationStateCollection
namurphy May 7, 2020
c9beb3c
Update tests for IonicFraction and IonizationState
namurphy May 7, 2020
0674b01
Rename AtomicError, etc. to ParticleError, etc.
namurphy May 8, 2020
5823634
Update changelog
namurphy May 8, 2020
b3e7ab8
Use isort & black to sort imports & reformat
namurphy May 8, 2020
eb82a1b
Test that IonicFraction raises appropriate exceptions
namurphy May 8, 2020
34a9bf5
Minor revisions to ionization state classes
namurphy May 29, 2020
abe555f
Rename `info` method to `summarize` in ionization classes
namurphy May 29, 2020
67a3c7d
Handle exceptions in IonicFraction.__init__
namurphy May 29, 2020
694adfa
Small fix to exception handling in IonicFraction
namurphy May 29, 2020
3e53ae8
Merge remote-tracking branch 'plasmapy/master' into ionization-state-…
namurphy May 29, 2020
9d22a8b
Change expected exceptions in IonicFraction tests
namurphy May 29, 2020
d7e5811
Remove extraneous test failure messages
namurphy May 29, 2020
4ce0eb7
Remove another extraneous test failure message
namurphy May 29, 2020
f3e01e1
Test TypeErrors from IonicFraction.__eq__
namurphy May 29, 2020
e60b68a
Fix error in docstring
namurphy May 29, 2020
8a7bde9
Fix ReST formatting
namurphy May 29, 2020
89b1ee8
Merge branch 'master' of github.com:PlasmaPy/PlasmaPy into ionization…
namurphy Aug 18, 2020
a5deb1b
Use black and isort in plasmapy.particles
namurphy Aug 18, 2020
7e633d0
Clean up unused imports
namurphy Aug 18, 2020
d4f0e99
Clean up imports
namurphy Aug 18, 2020
d7b2bf6
Remove duplicate examples in ionization states docs
namurphy Aug 18, 2020
0b05d5b
Update method name in docs
namurphy Aug 18, 2020
03ee8b5
Update Atomic to Particle in particles warnings
namurphy Aug 18, 2020
4c5e313
Use black and isort
namurphy Aug 19, 2020
8624913
Finish renaming the exception and warning for missing particle data
namurphy Aug 19, 2020
7f75c23
Formatting changes
namurphy Aug 19, 2020
6c712d4
Revise creation of dictionary for old/new particle symbols
namurphy Aug 19, 2020
16805fb
Changing api_static file after renaming ionization_states
namurphy Aug 19, 2020
a3c6797
Merge branch 'master' of github.com:PlasmaPy/PlasmaPy into ionization…
namurphy Sep 11, 2020
c92ee5b
Fix minor docs formatting issue
namurphy Sep 11, 2020
cb08bb9
Merge branch 'master' of github.com:PlasmaPy/PlasmaPy into ionization…
namurphy Sep 29, 2020
aa56717
Update docs/particles/ionization_states.rst
namurphy Sep 29, 2020
3fccb63
Minor formatting fix
namurphy Sep 29, 2020
182c950
Merge branch 'master' of github.com:PlasmaPy/PlasmaPy into ionization…
namurphy Oct 10, 2020
3419fb4
ReST formatting
namurphy Oct 10, 2020
6a173e4
ReST formatting
namurphy Oct 10, 2020
1ad6ed4
ReST formatting
namurphy Oct 10, 2020
9ed55e1
Shorten TODOs for IonizationState
namurphy Oct 10, 2020
7d17683
Remove placeholder methods for equilibrating ionization states
namurphy Oct 10, 2020
064ed5f
Minor updates to docstrings & ReST formatting
namurphy Oct 10, 2020
481786e
ReST formatting
namurphy Oct 10, 2020
72869f7
Remove pun because it isn't future proof
namurphy Oct 10, 2020
e492815
Create ParticleTypeError and ParticleValueError
namurphy Oct 10, 2020
0d9ffd3
Fix f-string formatting
namurphy Oct 10, 2020
1077dff
Add particle_symbol to __all__
namurphy Oct 10, 2020
3b02763
Fix typo in name of ParticleValueError
namurphy Oct 10, 2020
243b444
Create particle_like as a typing construct
namurphy Oct 10, 2020
8f77e41
Begin using particle_like in docstrings and annotations
namurphy Oct 10, 2020
041210f
Merge branch 'master' of github.com:PlasmaPy/PlasmaPy into ionization…
namurphy Oct 23, 2020
0bb09d6
Update link to exception
namurphy Oct 24, 2020
e12c855
Update link to exception
namurphy Oct 24, 2020
3578076
Update link to exception
namurphy Oct 24, 2020
dffd454
Update link to exception
namurphy Oct 24, 2020
46ac6e7
Update link to exception
namurphy Oct 24, 2020
df931b6
Update link to exception
namurphy Oct 24, 2020
5cf0b7c
Update link to exception
namurphy Oct 24, 2020
4682b3c
Update link to exception
namurphy Oct 24, 2020
10d9ee2
Update link to exception
namurphy Oct 24, 2020
ffe7f86
Fix link to method
namurphy Oct 24, 2020
f26beb0
Use auto-links in change log, except for obsolete names
namurphy Oct 24, 2020
93dcccb
Update ReST links
namurphy Oct 24, 2020
b43d178
Fix link to exception
namurphy Oct 24, 2020
9afb6e2
Update links to exceptions and clean up formatting
namurphy Oct 24, 2020
2e607e2
Merge branch 'ionization-state-fixes' of github.com:namurphy/PlasmaPy…
namurphy Oct 24, 2020
58b4c1b
Update ReST links & formatting
namurphy Oct 24, 2020
69ad664
Update parameters in docs for isotopic_abundance
namurphy Oct 24, 2020
37b7531
Remove unnecessary back ticks
namurphy Oct 24, 2020
db0385d
Remove unnecessary back ticks
namurphy Oct 24, 2020
e78d93d
Remove unnecessary back ticks
namurphy Oct 24, 2020
1c824e3
Remove unnecessary back ticks
namurphy Oct 24, 2020
24e1d7a
Remove unused exceptions for time being
namurphy Oct 24, 2020
f7044c6
Merge branch 'ionization-state-fixes' of github.com:namurphy/PlasmaPy…
namurphy Oct 24, 2020
ba6a9d5
Revert name of exception
namurphy Oct 24, 2020
7bd52dd
Fix ReST formatting, especially in See Also sections
namurphy Oct 24, 2020
525ef48
Merge branch 'master' of github.com:PlasmaPy/PlasmaPy into ionization…
namurphy Oct 24, 2020
3aae8a3
Fix ReST links and formatting
namurphy Oct 24, 2020
339a794
Update exception description
namurphy Oct 25, 2020
86ca4b9
Merge branch 'master' of github.com:PlasmaPy/PlasmaPy into ionization…
namurphy Nov 30, 2020
e425617
Update links to particles exceptions in narrative docs
namurphy Nov 30, 2020
bd7f822
Merge branch 'master' into ionization-state-fixes
StanczakDominik Dec 12, 2020
66ac51f
Apply unit-related suggestion from Erik's review
StanczakDominik Dec 12, 2020
b43b71f
Update docs/particles/ionization_states.rst
StanczakDominik Dec 12, 2020
67d69c5
Reformat with black
namurphy Dec 14, 2020
e05c815
Have IonicFraction.__eq__ return False for different ions
namurphy Dec 14, 2020
d019797
Change IonizationStateCollection kwarg from n to n0
namurphy Dec 14, 2020
f1754c5
Finish renaming n to n0 for IonizationStateCollection
namurphy Dec 14, 2020
5039dd1
Reformat line due to pre-commit
namurphy Dec 14, 2020
ef11379
Update changelog with ionization states changes
namurphy Dec 14, 2020
1a8940b
Formatting changes
namurphy Dec 14, 2020
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
10 changes: 10 additions & 0 deletions changelog/796.breaking.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
In `plasmapy.particles`, the ``IonizationStates`` class was renamed to
`~plasmapy.particles.IonizationStateCollection`. The argument ``n`` in
``IonizationStates`` was changed to ``n0`` in
`~plasmapy.particles.IonizationStateCollection`. The ``State`` namedtuple
was changed to the `~plasmapy.particles.IonicFraction` class. When the
`~plasmapy.particles.IonizationState` class is now provided with an ion,
the ionic fraction for that ion is set to 100% for the corresponding
element or isotope. ``AtomicError`` was renamed to
`~plasmapy.particles.exceptions.ParticleError` and ``MissingAtomicDataError``
was renamed to `~plasmapy.particles.exceptions.MissingParticleDataError`.
1 change: 1 addition & 0 deletions changelog/796.doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add narrative documentation on ionization state functionality.
10 changes: 10 additions & 0 deletions docs/api_static/plasmapy.particles.ionization_state_collection.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
:orphan:

`plasmapy.particles.ionization_state_collection`
================================================

.. currentmodule:: plasmapy.particles.ionization_state_collection

.. automodapi:: plasmapy.particles.ionization_state_collection
:include-all-objects:
:no-heading:
10 changes: 0 additions & 10 deletions docs/api_static/plasmapy.particles.ionization_states.rst

This file was deleted.

10 changes: 5 additions & 5 deletions docs/particles/decorators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class. The arguments must be annotated with `~plasmapy.particles.Particle`
so that the decorator knows to create the `~plasmapy.particles.Particle`
instance. The function can then access particle properties by using
`~plasmapy.particles.Particle` attributes. This decorator will raise an
`~plasmapy.utils.InvalidParticleError` if the input does not correspond
`~plasmapy.particles.exceptions.InvalidParticleError` if the input does not correspond
to a valid particle.

.. code-block:: python
Expand Down Expand Up @@ -57,10 +57,10 @@ decorator enables several ways to allow this.

If an annotated keyword is named ``element``, ``isotope``, or ``ion``;
then `~plasmapy.particles.particle_input` will raise an
`~plasmapy.utils.InvalidElementError`,
`~plasmapy.utils.InvalidIsotopeError`, or
`~plasmapy.utils.InvalidIonError` if the particle is not associated with
an element, isotope, or ion; respectively.
`~plasmapy.particles.exceptions.InvalidElementError`,
`~plasmapy.particles.exceptions.InvalidIsotopeError`, or
`~plasmapy.particles.exceptions.InvalidIonError` if the particle is not
associated with an element, isotope, or ion; respectively.

.. code-block:: python

Expand Down
2 changes: 1 addition & 1 deletion docs/particles/functional.rst
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ unstable), `~plasmapy.particles.half_life` returns infinity seconds.

If the particle's half-life is not known to sufficient precision, then
`~plasmapy.particles.half_life` returns a `str` with the estimated value
while issuing a `~plasmapy.particles.exceptions.MissingAtomicDataWarning`.
while issuing a `~plasmapy.particles.exceptions.MissingParticleDataWarning`.

Additional Properties
=====================
Expand Down
1 change: 1 addition & 0 deletions docs/particles/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Submodules
particle_class
functional
nuclear
ionization_states
decorators

See Also
Expand Down
163 changes: 163 additions & 0 deletions docs/particles/ionization_states.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
.. _ionization-state-data-structures:

Ionization state data structures
********************************

The ionization state (or charge state) of a plasma refers to the
fraction of an element that is at each ionization level. For example,
the ionization state of a pure helium plasma could be 5% He⁰⁺, 94% He¹⁺,
and 1% He²⁺.

The ionization state of a single element
========================================

We may use the `~plasmapy.particles.IonizationState` class
to represent the ionization state of a single element, such as for this
example.

>>> from plasmapy.particles import IonizationState
>>> ionization_state = IonizationState("He", [0.05, 0.94, 0.01])

The ionization state for helium may be accessed using the
``ionic_fractions`` attribute. These ionic fractions correspond to the
``integer_charges`` attribute.

>>> ionization_state.ionic_fractions
array([0.05, 0.94, 0.01])
>>> ionization_state.integer_charges
array([0, 1, 2])

The ``Z_mean`` attribute returns the mean integer charge averaged
over all particles in that element.

>>> ionization_state.Z_mean
0.96

The ``Z_rms`` attribute returns the root mean square integer charge.

>>> ionization_state.Z_rms
0.9899...

The ``Z_most_abundant`` attribute returns a `list` of the most abundant
ion(s). The `list` may contain more than one integer charge in case of
a tie.

>>> ionization_state.Z_most_abundant
[1]
StanczakDominik marked this conversation as resolved.
Show resolved Hide resolved

The ``summarize`` method prints out the ionic fraction for the ions with
an abundance of at least 1%.

>>> ionization_state.summarize()
IonizationState instance for He with Z_mean = 0.96
----------------------------------------------------------------
He 0+: 0.050
He 1+: 0.940
He 2+: 0.010
----------------------------------------------------------------

The number density of the element may be specified through the
``n_elem`` keyword argument.

>>> import astropy.units as u
>>> ionization_state = IonizationState(
... "He", [0.05, 0.94, 0.01], n_elem = 1e19 * u.m ** -3,
... )

The ``n_e`` attribute provides the electron number density as a
`~astropy.units.Quantity`.

>>> ionization_state.n_e
<Quantity 9.6e+18 1 / m3>

The ``number_densities`` attribute provides the number density of each
ion or neutral.

>>> ionization_state.number_densities
<Quantity [5.0e+17, 9.4e+18, 1.0e+17] 1 / m3>

Ionization states for multiple elements
=======================================

The `~plasmapy.particles.IonizationStateCollection` class may be used to
represent the ionization state for multiple elements. This can be used,
for example, to describe the various impurities in a fusion plasma or
the charge state distributions of different elements in the solar wind.

>>> from plasmapy.particles import IonizationStateCollection

The minimal input to `~plasmapy.particles.IonizationStateCollection` is a `list`
of the elements or isotopes to represent. Integers in the `list` will
be treated as atomic numbers.

>>> states = IonizationStateCollection(["H", 2])

To set the ionic fractions for hydrogen, we may do item assignment.

>>> states["H"] = [0.9, 0.1]

We may use indexing to retrieve an `~plasmapy.particles.IonizationState`
instance for an element.

>>> states["H"]
<IonizationState instance for H>

The ionization states for all of the elements may be specified directly
as arguments to the class.

>>> states = IonizationStateCollection(
... {"H": [0.01, 0.99], "He": [0.04, 0.95, 0.01]},
... abundances={"H": 1, "He": 0.08},
... n0 = 5e19 * u.m ** -3,
... )

The ionic fractions will be stored as a `dict`.

>>> states.ionic_fractions
{'H': array([0.01, 0.99]), 'He': array([0.04, 0.95, 0.01])}

The number density for each element is the product of the number
density scaling factor ``n0`` with that element's abundance.
The number density for each ion is the product of ``n0``, the
corresponding element's abundance, and the ionic fraction.

>>> states.n0
<Quantity 5.e+19 1 / m3>
>>> states.abundances
{'H': 1.0, 'He': 0.08}
>>> states.number_densities["H"]
<Quantity [5.00e+17, 4.95e+19] 1 / m3>

The
corresponding element's abundance, and the ionic fraction.

>>> states.n0
<Quantity 5.e+19 1 / m3>
>>> states.abundances
{'H': 1.0, 'He': 0.08}
>>> states.number_densities["H"]
<Quantity [5.00e+17, 4.95e+19] 1 / m3>

The
corresponding element's abundance, and the ionic fraction.

>>> states.n
<Quantity 5.e+19 1 / m3>
>>> states.abundances
{'H': 1.0, 'He': 0.08}
>>> states.number_densities["H"]
<Quantity [5.00e+17, 4.95e+19] 1 / m3>

The `~plasmapy.particles.IonizationStates.summarize` method may also be
used to get a summary of the ionization states.

>>> states.summarize()
----------------------------------------------------------------
H 1+: 0.990 n_i = 4.95e+19 m**-3
----------------------------------------------------------------
He 0+: 0.040 n_i = 1.60e+17 m**-3
He 1+: 0.950 n_i = 3.80e+18 m**-3
----------------------------------------------------------------
n_e = 5.34e+19 m**-3
T_e = 1.30e+04 K
----------------------------------------------------------------
5 changes: 3 additions & 2 deletions plasmapy/particles/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
standard_atomic_weight,
)
from plasmapy.particles.decorators import particle_input
from plasmapy.particles.ionization_state import IonizationState, State
from plasmapy.particles.ionization_states import IonizationStates
from plasmapy.particles.ionization_state import IonicFraction, IonizationState
from plasmapy.particles.ionization_state_collection import IonizationStateCollection
from plasmapy.particles.nuclear import nuclear_binding_energy, nuclear_reaction_energy
from plasmapy.particles.particle_class import (
AbstractParticle,
CustomParticle,
DimensionlessParticle,
Particle,
particle_like,
)
from plasmapy.particles.serialization import (
json_load_particle,
Expand Down