Skip to content

Commit 5180eeb

Browse files
initial commit
1 parent de55560 commit 5180eeb

File tree

5 files changed

+57
-1
lines changed

5 files changed

+57
-1
lines changed

news/mu.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* function to compute x-ray attenuation coefficient (mu) using XrayDB
4+
5+
**Changed:**
6+
7+
* <news item>
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

requirements/conda.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
numpy
2+
xraydb

requirements/pip.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
numpy
2+
xraydb

src/diffpy/utils/tools.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from copy import copy
44
from pathlib import Path
55

6+
from xraydb import material_mu
7+
68

79
def _stringify(obj):
810
"""
@@ -131,3 +133,26 @@ def get_package_info(package_names, metadata=None):
131133
pkg_info.update({package: importlib.metadata.version(package)})
132134
metadata["package_info"] = pkg_info
133135
return metadata
136+
137+
138+
def compute_mu_using_xraydb(sample, energy, density=None):
139+
"""
140+
compute mu using the XrayDB database
141+
142+
Reference: https://xraypy.github.io/XrayDB/python.html#xraydb.material_mu
143+
144+
Parameters
145+
----------
146+
sample str
147+
the chemical formula or the name of the material
148+
energy float
149+
the energy in eV
150+
density float or None
151+
material density in gr/cm^3
152+
153+
Returns
154+
-------
155+
the attenuation coefficient mu in mm^{-1}
156+
"""
157+
mu = material_mu(sample, energy, density=density, kind="total") / 10
158+
return mu

tests/test_tools.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import pytest
77

8-
from diffpy.utils.tools import get_package_info, get_user_info
8+
from diffpy.utils.tools import compute_mu_using_xraydb, get_package_info, get_user_info
99

1010
# def _setup_dirs(monkeypatch, user_filesystem):
1111
# home_dir, cwd_dir = user_filesystem.home_dir, user_filesystem.cwd_dir
@@ -189,3 +189,9 @@ def test_get_package_info(monkeypatch, inputs, expected):
189189
)
190190
actual_metadata = get_package_info(inputs[0], metadata=inputs[1])
191191
assert actual_metadata == expected
192+
193+
194+
def test_compute_mu_using_xraydb():
195+
sample, energy, density = "ZrO2", 17445.362740959618, 1.009
196+
actual_mu = compute_mu_using_xraydb(sample, energy, density=density)
197+
assert actual_mu == pytest.approx(1.252, rel=1e-4, abs=0.1)

0 commit comments

Comments
 (0)