Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 13
add xraydb function to compute muD#126
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
3fc9e5ac537fe4bcff3871127a0cFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
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 mu*D based on basic information provided | ||
| **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,6 +1,8 @@ | ||
| import copy | ||
| from pathlib import Path | ||
| from xraydb import material_mu | ||
| from diffpy.labpdfproc.mud_calculator import compute_mud | ||
| from diffpy.utils.scattering_objects.diffraction_objects import QQUANTITIES, XQUANTITIES | ||
| from diffpy.utils.tools import get_package_info, get_user_info | ||
| @@ -158,9 +160,9 @@ def set_xtype(args): | ||
| return args | ||
| def set_mud(args): | ||
| def set_mud_from_zscan_file(args): | ||
| """ | ||
| Set the mud based on the given input arguments | ||
| Set the mud based on the given z-scan file | ||
| Parameters | ||
| ---------- | ||
| @@ -180,6 +182,49 @@ def set_mud(args): | ||
| return args | ||
| def set_mud_using_xraydb(args): | ||
| """ | ||
| Set the mud using xraydb, prompting for parameters if not provided by the user | ||
| The function works in this way: | ||
| (1) if mu*D is provided, no further input is required, and any additional inputs are written to metadata. | ||
| (2) if mu*D is missing but mu is provided, prompt for diameter if missing and compute muD = mu * d. | ||
| (3) if neither is provided, prompt for sample name, energy, density, and diameter as needed, then compute muD. | ||
| Reference for the xraydb database: https://xraypy.github.io/XrayDB/python.html#xraydb.material_mu. | ||
| Parameters | ||
| ---------- | ||
| args argparse.Namespace | ||
| the arguments from the parser | ||
| sample str | ||
| the chemical formula or name of material | ||
| energy float | ||
| the energy in eV | ||
| density float or None | ||
| material density in gr/cm^3 | ||
| diameter float | ||
| the capillary diameter in mm | ||
| Returns | ||
| ------- | ||
| the updated args argparse.Namespace with mu*D | ||
| """ | ||
| if args.mud: | ||
| return args | ||
| if args.mu: | ||
| args.diameter = args.diameter or float(input("Please enter the capillary diameter (mm): ").strip()) | ||
| args.mud = args.mu * args.diameter | ||
| return args | ||
| args.sample = args.sample or input("Please enter the chemical formula or name of material: ").strip() | ||
| args.energy = args.energy or float(input("Please enter the energy (eV): ").strip()) | ||
| args.density = args.density or float(input("Please enter material density (gr/cm^3): ").strip()) | ||
| args.diameter = args.diameter or float(input("Please enter the capillary diameter (mm): ").strip()) | ||
| args.mu = material_mu(args.sample, args.energy, density=args.density, kind="total") / 10 | ||
| args.mud = args.mu * args.diameter | ||
| return args | ||
| def _load_key_value_pair(s): | ||
| items = s.split("=") | ||
| key = items[0].strip() | ||
| @@ -281,7 +326,8 @@ def preprocessing_args(args): | ||
| args.output_directory = set_output_directory(args) | ||
| args = set_wavelength(args) | ||
| args = set_xtype(args) | ||
| args = set_mud(args) | ||
| args = set_mud_from_zscan_file(args) | ||
CollaboratorAuthor 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. Here I am thinking that during the pre-processing we first check for z-scan files and read muD from there. If there's no file /muD provided, we then proceed to ask for other information. | ||
| args = set_mud_using_xraydb(args) | ||
| args = load_user_metadata(args) | ||
| return args | ||
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.
I added some input prompts because it might be easier to enter from here than from cli inputs.