Skip to content

Commit abc8f1d

Browse files
authored
Merge pull request #2 from sbillinge/app_work
working version of app, then broken again after adding diffraction ob…
2 parents 9f3d524 + 8a806a9 commit abc8f1d

File tree

5 files changed

+5675
-25
lines changed

5 files changed

+5675
-25
lines changed

diffpy/labpdfproc/_version.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import sys
1717

1818

19+
1920
def get_keywords():
2021
"""Get the keywords needed to look up the version information."""
2122
# these strings will be replaced by git during git-archive.

diffpy/labpdfproc/functions.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import numpy as np
2+
3+
wavelengths = {"Mo": 0.7107, "Ag": 0.59}
4+
def compute_cve(diffraction_data, mud, wavelength):
5+
# for a given mu and d and lambda, we will compute cve on a tth grid
6+
# something arbitrary for the moment
7+
cve = diffpy.utils.DiffractionObject()
8+
cve_x = diffraction_data.on_tth[0]
9+
cve_y = cve_x * mud * wavelength
10+
cve.insert_scattering_quantity(cve_x, cve_y, "tth", metadata={ })
11+
return cve
12+
13+
def apply_corr(i_m, cve):
14+
# we apply the absorption correction by doing: I(tth) * c_ve
15+
i_c = i_m * cve
16+
return i_c

diffpy/labpdfproc/labpdfprocapp.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import sys
2-
import numpy as np
3-
from labpdfproc.functions import compute_cve, apply_corr
4-
from diffpy.utils.parsers.loaddata import loadData
52
from argparse import ArgumentParser
63

4+
from diffpy.labpdfproc.functions import compute_cve, apply_corr, wavelengths
5+
from diffpy.utils.parsers.loaddata import loadData
6+
from diffpy.utils.scattering_objects import DiffractionObject
7+
8+
79
known_sources = ["Ag", "Mo"]
810
# def load_data(input_file):
911
# # we want to load .xy, xye, file types. These are the most common. For anyting else (.snc, .txt, .csv, .dat) we return an error message. Why: some of them have different delimineters.
@@ -19,7 +21,6 @@
1921
# else:
2022
# raise ValueError('Error: your .xy contains headers. Delete the header rows in your .xy or .xye file')
2123

22-
2324
# def tth_to_q(tth, wl):
2425
# tth_rad = np.deg2rad(tth)
2526
# q = (4 * np.pi / wl) * np.sin(tth_rad / 2)
@@ -34,8 +35,8 @@
3435

3536
def get_args():
3637
p = ArgumentParser()
37-
p.add_argument("filename", help="the filename of the datafile to load")
38-
p.add_argument("mud", help="mu*D for your sample")
38+
p.add_argument("data_file", help="the filename of the datafile to load")
39+
p.add_argument("mud", help="mu*D for your sample", type=float)
3940
p.add_argument("--anode_type", help=f"x-ray source, allowed values:{*[known_sources],}", default="Mo")
4041
args = p.parse_args()
4142
return args
@@ -49,19 +50,21 @@ def main():
4950
print('usage: labpdfproc <input_file> <mu> <diameter> <lambda>')
5051

5152
args = get_args()
52-
print(args.__dir__)
53-
tth, i_m = loadData(input_file, unpack=True)
53+
wavelength = wavelengths[args.anode_type]
54+
input_pattern = DiffractionObject()
55+
xarray, yarray = loadData(args.data_file, unpack=True)
56+
input_pattern.insert_scattering_quantity(xarray, yarray, "tth", metadata={ })
5457

55-
cve = compute_cve(tth, mu, diameter, wl)
56-
i_c = apply_corr(i_m, cve)
57-
q = tth_to_q(tth, wl)
58+
cve = compute_cve(input_pattern, args.mud, wavelength)
59+
i_c = input_pattern * cve
5860

5961
# get the basename from the input_file and save the corrected patter as a .tth and a .chi file.
60-
base_name = input_file.split('.')[0]
61-
output_chi = f"{base_name}.chi"
62-
output_tth = f"{base_name}.tth"
63-
np.savetxt(output_tth, np.column_stack((tth, i_c)), header='tth I(tth)')
64-
np.savetxt(output_chi, np.column_stack((q, i_c)), header='tth I(tth)')
62+
# base_name = input_file.split('.')[0]
63+
# output_chi = f"{base_name}.chi"
64+
# output_tth = f"{base_name}.tth"
65+
# np.savetxt(output_tth, np.column_stack((tth, i_c)), header='tth I(tth)')
66+
# np.savetxt(output_chi, np.column_stack((q, i_c)), header='tth I(tth)')
67+
input_pattern.dump("filename", type="chi")
6568

6669
if __name__ == '__main__':
67-
main()
70+
main()

0 commit comments

Comments
 (0)