-
Notifications
You must be signed in to change notification settings - Fork 21
compute mu #278
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
compute mu #278
Changes from 2 commits
5180eeb
5ff2c23
1826221
e54f9bb
be7c275
9e4bc0d
1879f44
a108205
0bdbbb4
00f36ad
255c603
5492ad8
a4a217d
953e187
dd52ad9
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,23 @@ | ||
**Added:** | ||
|
||
* function to compute x-ray attenuation coefficient (mu) using XrayDB | ||
|
||
**Changed:** | ||
|
||
* <news item> | ||
|
||
**Deprecated:** | ||
|
||
* <news item> | ||
|
||
**Removed:** | ||
|
||
* <news item> | ||
|
||
**Fixed:** | ||
|
||
* <news item> | ||
|
||
**Security:** | ||
|
||
* <news item> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
numpy | ||
xraydb |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
numpy | ||
xraydb |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
from copy import copy | ||
from pathlib import Path | ||
|
||
from xraydb import material_mu | ||
|
||
|
||
def _stringify(obj): | ||
""" | ||
|
@@ -131,3 +133,25 @@ def get_package_info(package_names, metadata=None): | |
pkg_info.update({package: importlib.metadata.version(package)}) | ||
metadata["package_info"] = pkg_info | ||
return metadata | ||
|
||
|
||
def compute_mu_using_xraydb(sample, energy, density=None): | ||
"""Compute mu using the XrayDB database. | ||
|
||
Reference: https://xraypy.github.io/XrayDB/python.html#xraydb.material_mu | ||
|
||
Parameters | ||
---------- | ||
sample str | ||
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 think we would normally do tihs as:
i.e., colon and sentencecse |
||
the chemical formula or the name of the material | ||
energy float | ||
the energy in eV | ||
density float or None | ||
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.
|
||
material density in gr/cm^3 | ||
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. this should be "sample mass density" or even better, "mass density of the packed powder/sample" to be clear. the material desnsity is something quite different (mass of atoms in the unit cell divided by unit cell volume) |
||
|
||
Returns | ||
------- | ||
the attenuation coefficient mu in mm^{-1} | ||
""" | ||
mu = material_mu(sample, energy, density=density, kind="total") / 10 | ||
return mu |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
import pytest | ||
|
||
from diffpy.utils.tools import get_package_info, get_user_info | ||
from diffpy.utils.tools import compute_mu_using_xraydb, get_package_info, get_user_info | ||
|
||
# def _setup_dirs(monkeypatch, user_filesystem): | ||
# home_dir, cwd_dir = user_filesystem.home_dir, user_filesystem.cwd_dir | ||
|
@@ -189,3 +189,9 @@ def test_get_package_info(monkeypatch, inputs, expected): | |
) | ||
actual_metadata = get_package_info(inputs[0], metadata=inputs[1]) | ||
assert actual_metadata == expected | ||
|
||
|
||
def test_compute_mu_using_xraydb(): | ||
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. we need a test for no density passed in. Also for packing fraction passed in and also for both passed in. Think about what behavior you want in each of these cases and write a "case" (look elsewhere in test_tools for how we are handling this now) |
||
sample, energy, density = "ZrO2", 17445.362740959618, 1.009 | ||
actual_mu = compute_mu_using_xraydb(sample, energy, density=density) | ||
assert actual_mu == pytest.approx(1.252, rel=1e-4, abs=0.1) |
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.
let's change
sample
tocomposition
or maybesample_composition
.I think we probably need
packing_fraction
as an optional arg.