-
Notifications
You must be signed in to change notification settings - Fork 11
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
add xraydb function to compute muD #126
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3fc9e5a
make mud an optional argument, add options for entering sample/energy…
yucongalicechen c537fe4
add option for user to enter mu and diameter separately
yucongalicechen bcff387
add functions to compute muD from xraydb database
yucongalicechen 1127a0c
add news
yucongalicechen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.