-
Notifications
You must be signed in to change notification settings - Fork 352
Add critical_density
#1664
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
Merged
Merged
Add critical_density
#1664
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
475043e
Add `plasma_critical_density` function body
JaydenR2305 48a23a6
Add changelog
JaydenR2305 f12f241
Merge branch 'PlasmaPy:main' into plasma-critical-density
JaydenR2305 e1500d2
Add `test_densities.py` & `test_plasma_critical_density()`
JaydenR2305 4334b2a
Add `densities` to `formulary/__init__`
JaydenR2305 d6313e4
Update `test_densities` to include `isclose()` test
JaydenR2305 b3e711e
Add module page for `densities`
JaydenR2305 9523203
Remove decorator errors from docstring
JaydenR2305 4c475d2
Appease black
JaydenR2305 7898135
Clarify tests
JaydenR2305 1204282
Clean up return unit conversion
JaydenR2305 0e629ac
Appease black x2
JaydenR2305 5d319f4
Change `omega_p` to `omega`
JaydenR2305 4cd5194
Fix examples output
JaydenR2305 23c1413
Use dimensionless_angles for return
JaydenR2305 984c336
Rename `plasma_critical_density` to `critical_density`
JaydenR2305 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Add the `~plasmapy.formulary.densities` submodule | ||
| Add the `~plasmapy.formulary.densities.critical_density` function to the `~plasmapy.formulary.densities` module. This function calculates the critical density of a plasma for a given frequency of radiation. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| .. _densities: | ||
|
|
||
| ****************************************************************** | ||
| Density Plasma Parameters (`plasmapy.formulary.densities`) | ||
| ****************************************************************** | ||
|
|
||
| .. currentmodule:: plasmapy.formulary.densities | ||
|
|
||
| .. automodapi:: plasmapy.formulary.densities |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| """Functions to calculate plasma density parameters.""" | ||
| __all__ = [ | ||
| "critical_density", | ||
| ] | ||
|
|
||
| import astropy.units as u | ||
|
|
||
| from astropy.constants.si import e, eps0, m_e | ||
|
|
||
| from plasmapy.utils.decorators import validate_quantities | ||
|
|
||
|
|
||
| @validate_quantities( | ||
| omega={"can_be_negative": False}, | ||
| validations_on_return={ | ||
| "units": [u.m**-3], | ||
| }, | ||
| ) | ||
| def critical_density(omega: u.rad / u.s) -> u.m**-3: | ||
| r"""Calculate the plasma critical density for a radiation of a given frequency. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| omega: `~astropy.units.Quantity` | ||
| The radiation frequency in units of angular frequency. | ||
|
|
||
| Returns | ||
| ------- | ||
| n_c : `~astropy.units.Quantity` | ||
| The plasma critical density. | ||
|
|
||
| Notes | ||
| ----- | ||
| The critical density for a given frequency of radiation is | ||
| defined as the value at which the electron plasma frequency equals | ||
| the frequency of the radiation. | ||
|
|
||
| The critical density is given by the formula | ||
|
|
||
| .. math:: | ||
| n_{c}=\frac{m_{e}\varepsilon_0\omega^{2}}{e^{2}} | ||
|
|
||
| where :math:`m_{e}` is the mass of an electron, | ||
| :math:`\varepsilon_0` is the permittivity of free space, :math:`\omega` | ||
| is the radiation frequency, and :math:`e` is the elementary charge. | ||
|
|
||
| Examples | ||
| -------- | ||
| >>> from astropy import units as u | ||
| >>> critical_density(5e15 * u.rad/u.s) | ||
| <Quantity 7.85519457e+27 1 / m3> | ||
|
|
||
| """ | ||
|
|
||
| n_c = m_e * eps0 * omega**2 / (e**2) | ||
|
|
||
| return n_c.to(u.m**-3, equivalencies=u.dimensionless_angles()) | ||
pheuer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| """Tests for functionality contained in `plasmapy.formulary.frequencies`.""" | ||
| import astropy.units as u | ||
| import numpy as np | ||
| import pytest | ||
|
|
||
| from plasmapy.formulary.densities import critical_density | ||
| from plasmapy.formulary.frequencies import plasma_frequency | ||
|
|
||
|
|
||
| class TestCriticalDensity: | ||
| """Test the plasma_critical_density function in densities.py.""" | ||
|
Member
Author
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. missed a spot |
||
|
|
||
| n_i = 5e19 * u.m**-3 | ||
| omega = plasma_frequency(n=n_i, particle="e-") | ||
|
|
||
| @pytest.fixture() | ||
| def n_c(self): | ||
| """Get the critical density for the example frequency""" | ||
| return critical_density(self.omega) | ||
|
|
||
| def test_units(self, n_c): | ||
| """Test the return units""" | ||
|
|
||
| assert n_c.unit.is_equivalent(u.m**-3) | ||
|
|
||
| def test_value(self, n_c): | ||
| """ | ||
| Compare the calculated critical density with the expected value. | ||
|
|
||
| The plasma critical density for a given frequency of radiation is | ||
| defined as the value at which the electron plasma frequency equals | ||
| the frequency of the radiation. | ||
| """ | ||
|
|
||
| assert np.isclose(n_c.value, self.n_i.value) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.