Skip to content

feat: getmud UC1 (get_diameter) #184

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions news/getmud.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* New ``getmuD`` module with ``get_diameter`` function to calculate capillary diameter.

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
38 changes: 38 additions & 0 deletions src/diffpy/labpdfproc/getmud.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from diffpy.utils.tools import compute_mu_using_xraydb


def get_diameter(
mud,
sample_composition,
xray_energy,
sample_mass_density=None,
packing_fraction=None,
):
"""
Compute capillary diameter (mm) from muD, sample composition, energy,
and either sample mass density or packing fraction.

Parameters
----------
mud : float
The given muD of the sample.
sample_composition : str
The chemical formula of the material (e.g. "ZrO2").
xray_energy : float
The energy of the incident x-rays in keV.
sample_mass_density : float, optional
The mass density of the packed sample in g/cm^3.
packing_fraction : float, optional
The packing fraction of the sample (0–1).

Returns
-------
diameter : float
Computed capillary diameter in mm.
"""
return mud / compute_mu_using_xraydb(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better format - use compute_mu function from diffpy.utils.

sample_composition,
xray_energy,
sample_mass_density,
packing_fraction,
)
26 changes: 26 additions & 0 deletions tests/test_getmud.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pytest

from diffpy.labpdfproc.getmud import get_diameter


@pytest.mark.parametrize(
"inputs, expected_diameter",
[
( # C1: User specifies target mud,
# sample composition, energy, and mass density
# expect to return diameter
{
"mud": 2.0,
"sample_composition": "ZrO2",
"xray_energy": 17.45,
"sample_mass_density": 1.20,
},
1.3439,
),
],
)
def test_compute_diameter(inputs, expected_diameter):
actual_diameter = get_diameter(**inputs)
assert actual_diameter == pytest.approx(
expected_diameter, rel=0.01, abs=0.1
)
Loading