-
Notifications
You must be signed in to change notification settings - Fork 306
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 type hints and docstrings in plasmapy.formulary
#2543
Changes from all commits
8d28fb1
5cfc72d
6532b1d
e8ec508
9c6845e
a33ab4e
1027a3d
447f38f
cf96896
0721e4f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Added and updated type hint annotations across `plasmapy.formulary`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Exposed `~plasmapy.formulary.dielectric.StixTensorElements` | ||
and `~plasmapy.formulary.dielectric.RotatingTensorElements` | ||
to the public API. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,20 +8,21 @@ | |
import numpy as np | ||
from astropy.constants.si import eps0, hbar | ||
|
||
from plasmapy import particles | ||
from plasmapy.formulary.collisions import frequencies, misc | ||
from plasmapy.formulary.lengths import Debye_length | ||
from plasmapy.formulary.quantum import Wigner_Seitz_radius | ||
from plasmapy.particles.decorators import particle_input | ||
from plasmapy.particles.particle_class import Particle | ||
from plasmapy.utils.decorators import validate_quantities | ||
|
||
|
||
@validate_quantities( | ||
T={"can_be_negative": False, "equivalencies": u.temperature_energy()} | ||
) | ||
@particles.particle_input | ||
@particle_input | ||
def impact_parameter_perp( | ||
T: u.Quantity[u.K], | ||
species: (particles.Particle, particles.Particle), | ||
species: (Particle, Particle), | ||
Comment on lines
-21
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be more consistent with the import conventions we use elsewhere. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I love it when a review is just basically import statements, it makes the review a lot easier 😆 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It makes the pull request a lot easier too! |
||
V: u.Quantity[u.m / u.s] = np.nan * u.m / u.s, | ||
) -> u.Quantity[u.m]: | ||
r""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,17 +3,22 @@ | |
"cold_plasma_permittivity_SDP", | ||
"cold_plasma_permittivity_LRP", | ||
"permittivity_1D_Maxwellian", | ||
"RotatingTensorElements", | ||
"StixTensorElements", | ||
Comment on lines
+6
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I needed to expose these to the public API so that they could be used as return annotations without causing a "missing reference" error when doing the doc build. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you explain this when we next talk please? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be happy to, with the caveat that I only understand 83% of what's happening here! |
||
] | ||
__lite_funcs__ = ["permittivity_1D_Maxwellian_lite"] | ||
|
||
from collections import namedtuple | ||
from collections.abc import Sequence | ||
|
||
import astropy.units as u | ||
import numpy as np | ||
|
||
from plasmapy.dispersion.dispersion_functions import plasma_dispersion_func_deriv | ||
from plasmapy.formulary.frequencies import gyrofrequency, plasma_frequency | ||
from plasmapy.formulary.speeds import thermal_speed | ||
from plasmapy.particles.particle_class import ParticleLike | ||
from plasmapy.particles.particle_collections import ParticleListLike | ||
from plasmapy.utils.decorators import ( | ||
bind_lite_func, | ||
preserve_signature, | ||
|
@@ -27,15 +32,22 @@ | |
""" | ||
|
||
StixTensorElements = namedtuple("StixTensorElements", ["sum", "difference", "plasma"]) | ||
"""Output type for `~plasmapy.formulary.dielectric.cold_plasma_permittivity_SDP`.""" | ||
|
||
|
||
RotatingTensorElements = namedtuple( | ||
"RotatingTensorElements", ["left", "right", "plasma"] | ||
) | ||
"""Output type for `~plasmapy.formulary.dielectric.cold_plasma_permittivity_LRP`.""" | ||
|
||
|
||
@validate_quantities(B={"can_be_negative": False}, omega={"can_be_negative": False}) | ||
def cold_plasma_permittivity_SDP( | ||
B: u.Quantity[u.T], species, n, omega: u.Quantity[u.rad / u.s] | ||
): | ||
B: u.Quantity[u.T], | ||
species: ParticleListLike, | ||
n: Sequence[u.Quantity[u.m**-3]] | u.Quantity[u.m**-3], | ||
omega: u.Quantity[u.rad / u.s], | ||
) -> StixTensorElements: | ||
r""" | ||
Magnetized cold plasma dielectric permittivity tensor elements. | ||
|
||
|
@@ -49,7 +61,7 @@ def cold_plasma_permittivity_SDP( | |
B : `~astropy.units.Quantity` | ||
Magnetic field magnitude in units convertible to tesla. | ||
|
||
species : `list` of `str` | ||
species : |particle-list-like| | ||
List of the plasma particle species, | ||
e.g.: ``['e-', 'D+']`` or ``['e-', 'D+', 'He+']``. | ||
|
||
|
@@ -63,13 +75,13 @@ def cold_plasma_permittivity_SDP( | |
Returns | ||
------- | ||
sum : `~astropy.units.Quantity` | ||
S ("Sum") dielectric tensor element. | ||
The "sum" dielectric tensor element, :math:`S`. | ||
|
||
difference : `~astropy.units.Quantity` | ||
D ("Difference") dielectric tensor element. | ||
The "difference" dielectric tensor element, :math:`D`. | ||
|
||
plasma : `~astropy.units.Quantity` | ||
P ("Plasma") dielectric tensor element. | ||
The "plasma" dielectric tensor element, :math:`P`. | ||
|
||
Notes | ||
----- | ||
|
@@ -129,8 +141,11 @@ def cold_plasma_permittivity_SDP( | |
|
||
@validate_quantities(B={"can_be_negative": False}, omega={"can_be_negative": False}) | ||
def cold_plasma_permittivity_LRP( | ||
B: u.Quantity[u.T], species, n, omega: u.Quantity[u.rad / u.s] | ||
): | ||
B: u.Quantity[u.T], | ||
species: ParticleListLike, | ||
n: list[u.Quantity[u.m**-3]] | u.Quantity[u.m**-3], | ||
omega: u.Quantity[u.rad / u.s], | ||
) -> RotatingTensorElements: | ||
r""" | ||
Magnetized cold plasma dielectric permittivity tensor elements. | ||
|
||
|
@@ -145,11 +160,11 @@ def cold_plasma_permittivity_LRP( | |
B : `~astropy.units.Quantity` | ||
Magnetic field magnitude in units convertible to tesla. | ||
|
||
species : `list` of `str` | ||
species : (k,) |particle-list-like| | ||
The plasma particle species (e.g.: ``['e-', 'D+']`` or | ||
``['e-', 'D+', 'He+']``. | ||
|
||
n : `list` of `~astropy.units.Quantity` | ||
n : (k,) `list` of `~astropy.units.Quantity` | ||
`list` of species density in units convertible to per cubic meter. | ||
The order of the species densities should follow species. | ||
|
||
|
@@ -288,7 +303,7 @@ def permittivity_1D_Maxwellian( | |
kWave: u.Quantity[u.rad / u.m], | ||
T: u.Quantity[u.K], | ||
n: u.Quantity[u.m**-3], | ||
particle, | ||
particle: ParticleLike, | ||
z_mean: float | None = None, | ||
) -> u.Quantity[u.dimensionless_unscaled]: | ||
r""" | ||
|
@@ -318,7 +333,7 @@ def permittivity_1D_Maxwellian( | |
The plasma density — this can be either the electron or the ion | ||
density, but should be consistent with temperature and particle. | ||
|
||
particle : `str` | ||
particle : |particle-like| | ||
The plasma particle species. | ||
|
||
z_mean : `float` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a mypy error about how
plasmapy.particles
doesn't explicitly exportParticleLike
. Hence, I'm making a bunch of these import statements a lot more specific.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I remember this issue