Skip to content

Commit aab1765

Browse files
authored
Merge pull request #370 from cadenmyers13/rm-packing-fraction
fix: Remove API for calculating mu from packing fraction
2 parents 64ad577 + d41a817 commit aab1765

File tree

3 files changed

+33
-64
lines changed

3 files changed

+33
-64
lines changed

news/rm-packing-fraction.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* <news item>
4+
5+
**Changed:**
6+
7+
* <news item>
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* Removed API that calculates mu from packing fraction.
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

src/diffpy/utils/tools.py

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -231,49 +231,30 @@ def get_density_from_cloud(sample_composition, mp_token=""):
231231
)
232232

233233

234-
def compute_mu_using_xraydb(
235-
sample_composition, energy, sample_mass_density=None, packing_fraction=None
236-
):
234+
def compute_mu_using_xraydb(sample_composition, energy, sample_mass_density):
237235
"""Compute the attenuation coefficient (mu) using the XrayDB
238236
database.
239237
240-
Computes mu based on the sample composition and energy.
241-
User should provide a sample mass density or a packing fraction.
242-
If neither density nor packing fraction is specified,
243-
or if both are specified, a ValueError will be raised.
244-
Reference: https://xraypy.github.io/XrayDB/python.html#xraydb.material_mu.
238+
Computes mu based on the sample composition, X-ray energy, and
239+
sample mass density.
240+
241+
Reference:
242+
https://xraypy.github.io/XrayDB/python.html#xraydb.material_mu
245243
246244
Parameters
247245
----------
248246
sample_composition : str
249247
The chemical formula of the material.
250248
energy : float
251-
The energy of the incident x-rays in keV.
252-
sample_mass_density : float, ``optional``
253-
The mass density of the packed powder/sample in g/cm*3.
254-
Default is None.
255-
packing_fraction : float, ``optional``
256-
The fraction of sample in the capillary (between 0 and 1).
257-
Specify either sample_mass_density or packing_fraction but not both.
258-
Default is None.
249+
The energy of the incident X-rays in keV.
250+
sample_mass_density : float
251+
The mass density of the sample in g/cm^3.
259252
260253
Returns
261254
-------
262255
mu : float
263-
The attenuation coefficient mu in mm^{-1}.
256+
The attenuation coefficient μ in mm⁻¹.
264257
"""
265-
if (sample_mass_density is None and packing_fraction is None) or (
266-
sample_mass_density is not None and packing_fraction is not None
267-
):
268-
raise ValueError(
269-
"You must specify either sample_mass_density or packing_fraction, "
270-
"but not both. "
271-
"Please rerun specifying only one."
272-
)
273-
if packing_fraction is not None:
274-
sample_mass_density = (
275-
get_density_from_cloud(sample_composition) * packing_fraction
276-
)
277258
energy_eV = energy * 1000
278259
mu = (
279260
material_mu(

tests/test_tools.py

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from diffpy.utils.tools import (
1010
_extend_z_and_convolve,
1111
check_and_build_global_config,
12-
compute_mu_using_xraydb,
1312
compute_mud,
1413
get_package_info,
1514
get_user_info,
@@ -270,40 +269,6 @@ def test_get_package_info(monkeypatch, inputs, expected):
270269
assert actual_metadata == expected
271270

272271

273-
@pytest.mark.parametrize(
274-
"inputs",
275-
[
276-
# Test when the function has invalid inputs
277-
( # C1: Both mass density and packing fraction are provided,
278-
# expect ValueError exception
279-
{
280-
"sample_composition": "SiO2",
281-
"energy": 10,
282-
"sample_mass_density": 2.65,
283-
"packing_fraction": 1,
284-
}
285-
),
286-
( # C2: None of mass density or packing fraction are provided,
287-
# expect ValueError exception
288-
{
289-
"sample_composition": "SiO2",
290-
"energy": 10,
291-
}
292-
),
293-
],
294-
)
295-
def test_compute_mu_using_xraydb_bad(inputs):
296-
with pytest.raises(
297-
ValueError,
298-
match=(
299-
"You must specify either sample_mass_density or "
300-
"packing_fraction, but not both. "
301-
"Please rerun specifying only one."
302-
),
303-
):
304-
compute_mu_using_xraydb(**inputs)
305-
306-
307272
def test_compute_mud(tmp_path):
308273
diameter, slit_width, z0, I0, mud, slope = 1, 0.1, 0, 1e5, 3, 0
309274
z_data = np.linspace(-1, 1, 50)

0 commit comments

Comments
 (0)