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

Replace @u.quantity_input with @validate_quantities #905

Merged
merged 7 commits into from Oct 1, 2020
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
1 change: 1 addition & 0 deletions changelog/905.trivial.rst
@@ -0,0 +1 @@
Changed remaining instances of @u.quantity_input to @validate_quantities in response to issue #880.
2 changes: 1 addition & 1 deletion docs/about/credits.rst
Expand Up @@ -84,7 +84,7 @@ in parentheses are `ORCID author identifiers <https://orcid.org>`__.
* `Anthony Vo <https://github.com/anthony-vo>`__
* `Sixue Xu <https://github.com/hzxusx>`__
* `Carol Zhang <https://github.com/carolyz>`__

* `Cody Skinner <https://github.com/wskinner74>`__

This list contains contributors to PlasmaPy's core package and vision
statement, including a few people who do not show up as `PlasmaPy
Expand Down
16 changes: 8 additions & 8 deletions plasmapy/particles/ionization_state.py
Expand Up @@ -387,7 +387,7 @@ def equil_ionic_fractions(self, T_e: u.K = None):
"""
raise NotImplementedError

@u.quantity_input(equivalencies=u.temperature_energy())
@validate_quantities(equivalencies=u.temperature_energy())
def equilibrate(self, T_e: u.K = np.nan * u.K):
"""
Set the ionic fractions to collisional ionization equilibrium
Expand All @@ -397,7 +397,7 @@ def equilibrate(self, T_e: u.K = np.nan * u.K):
raise NotImplementedError

@property
@u.quantity_input
@validate_quantities
def n_e(self) -> u.m ** -3:
"""
Return the electron number density assuming a single species
Expand All @@ -406,13 +406,13 @@ def n_e(self) -> u.m ** -3:
return np.sum(self._n_elem * self.ionic_fractions * self.integer_charges)

@property
@u.quantity_input
@validate_quantities
def n_elem(self) -> u.m ** -3:
"""Return the total number density of neutrals and all ions."""
return self._n_elem.to(u.m ** -3)

@n_elem.setter
@u.quantity_input
@validate_quantities
def n_elem(self, value: u.m ** -3):
"""Set the number density of neutrals and all ions."""
if value < 0 * u.m ** -3:
Expand All @@ -423,7 +423,7 @@ def n_elem(self, value: u.m ** -3):
self._n_elem = np.nan * u.m ** -3

@property
@u.quantity_input
@validate_quantities
def number_densities(self) -> u.m ** -3:
"""Return the number densities for each state."""
try:
Expand All @@ -432,7 +432,7 @@ def number_densities(self) -> u.m ** -3:
return np.full(self.atomic_number + 1, np.nan) * u.m ** -3

@number_densities.setter
@u.quantity_input
@validate_quantities
def number_densities(self, value: u.m ** -3):
"""Set the number densities for each state."""
if np.any(value.value < 0):
Expand All @@ -447,15 +447,15 @@ def number_densities(self, value: u.m ** -3):
self._ionic_fractions = value / self._n_elem

@property
@u.quantity_input(equivalencies=u.temperature_energy())
@validate_quantities(equivalencies=u.temperature_energy())
def T_e(self) -> u.K:
"""Return the electron temperature."""
if self._T_e is None:
raise AtomicError("No electron temperature has been specified.")
return self._T_e.to(u.K, equivalencies=u.temperature_energy())

@T_e.setter
@u.quantity_input(equivalencies=u.temperature_energy())
@validate_quantities(equivalencies=u.temperature_energy())
def T_e(self, value: u.K):
"""Set the electron temperature."""
try:
Expand Down
10 changes: 5 additions & 5 deletions plasmapy/particles/ionization_states.py
Expand Up @@ -699,7 +699,7 @@ def equilibrate(
raise NotImplementedError

@property
@u.quantity_input
@validate_quantities
def n_e(self) -> u.m ** -3:
"""
Return the electron number density under the assumption of
Expand All @@ -715,13 +715,13 @@ def n_e(self) -> u.m ** -3:
return n_e

@property
@u.quantity_input
@validate_quantities
def n(self) -> u.m ** -3:
"""Return the number density scaling factor."""
return self._pars["n"]

@n.setter
@u.quantity_input
@validate_quantities
def n(self, n: u.m ** -3):
"""Set the number density scaling factor."""
try:
Expand Down Expand Up @@ -834,13 +834,13 @@ def log_abundances(self, value: Optional[Dict[str, Real]]):
raise AtomicError("Invalid log_abundances.") from None

@property
@u.quantity_input(equivalencies=u.temperature_energy())
@validate_quantities(equivalencies=u.temperature_energy())
def T_e(self) -> u.K:
"""Return the electron temperature."""
return self._pars["T_e"]

@T_e.setter
@u.quantity_input(equivalencies=u.temperature_energy())
@validate_quantities(equivalencies=u.temperature_energy())
def T_e(self, electron_temperature: u.K):
"""Set the electron temperature."""
try:
Expand Down
3 changes: 2 additions & 1 deletion plasmapy/plasma/sources/plasma3d.py
Expand Up @@ -11,6 +11,7 @@

from plasmapy.formulary.magnetostatics import MagnetoStatics
from plasmapy.plasma.plasma_base import GenericPlasma
from plasmapy.utils.decorators import validate_quantities


class Plasma3D(GenericPlasma):
Expand All @@ -33,7 +34,7 @@ class Plasma3D(GenericPlasma):
Any keyword accepted by `~plasmapy.plasma.plasma_base.GenericPlasma`
"""

@u.quantity_input(domain_x=u.m, domain_y=u.m, domain_z=u.m)
@validate_quantities(domain_x=u.m, domain_y=u.m, domain_z=u.m)
def __init__(self, domain_x, domain_y, domain_z, **kwargs):
super().__init__(**kwargs)

Expand Down
3 changes: 2 additions & 1 deletion plasmapy/plasma/sources/plasmablob.py
Expand Up @@ -12,6 +12,7 @@
from plasmapy.particles import particle_mass
from plasmapy.plasma.plasma_base import GenericPlasma
from plasmapy.utils import call_string, CouplingWarning
from plasmapy.utils.decorators import validate_quantities


class PlasmaBlob(GenericPlasma):
Expand All @@ -20,7 +21,7 @@ class PlasmaBlob(GenericPlasma):
spatial/temporal description.
"""

@u.quantity_input(T_e=u.K, n_e=u.m ** -3)
@validate_quantities(T_e=u.K, n_e=u.m ** -3)
def __init__(self, T_e, n_e, Z=None, particle="p"):
"""
Initialize plasma paramters.
Expand Down
3 changes: 2 additions & 1 deletion plasmapy/simulation/particletracker.py
Expand Up @@ -10,6 +10,7 @@
from astropy import constants

from plasmapy.particles import atomic
from plasmapy.utils.decorators import validate_quantities


class ParticleTracker:
Expand Down Expand Up @@ -57,7 +58,7 @@ class ParticleTracker:
.. _`Particle Stepper Notebook`: ../notebooks/particle_stepper.ipynb
"""

@u.quantity_input(dt=u.s)
@validate_quantities(dt=u.s)
def __init__(
self,
plasma,
Expand Down