Skip to content
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

working version of app, then broken again after adding diffraction ob… #2

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions diffpy/labpdfproc/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import sys



def get_keywords():
"""Get the keywords needed to look up the version information."""
# these strings will be replaced by git during git-archive.
Expand Down
16 changes: 16 additions & 0 deletions diffpy/labpdfproc/functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import numpy as np

wavelengths = {"Mo": 0.7107, "Ag": 0.59}
def compute_cve(diffraction_data, mud, wavelength):
# for a given mu and d and lambda, we will compute cve on a tth grid
# something arbitrary for the moment
cve = diffpy.utils.DiffractionObject()
cve_x = diffraction_data.on_tth[0]
cve_y = cve_x * mud * wavelength
cve.insert_scattering_quantity(cve_x, cve_y, "tth", metadata={ })
return cve

def apply_corr(i_m, cve):
# we apply the absorption correction by doing: I(tth) * c_ve
i_c = i_m * cve
return i_c
37 changes: 20 additions & 17 deletions diffpy/labpdfproc/labpdfprocapp.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import sys
import numpy as np
from labpdfproc.functions import compute_cve, apply_corr
from diffpy.utils.parsers.loaddata import loadData
from argparse import ArgumentParser

from diffpy.labpdfproc.functions import compute_cve, apply_corr, wavelengths
from diffpy.utils.parsers.loaddata import loadData
from diffpy.utils.scattering_objects import DiffractionObject


known_sources = ["Ag", "Mo"]
# def load_data(input_file):
# # 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.
Expand All @@ -19,7 +21,6 @@
# else:
# raise ValueError('Error: your .xy contains headers. Delete the header rows in your .xy or .xye file')


# def tth_to_q(tth, wl):
# tth_rad = np.deg2rad(tth)
# q = (4 * np.pi / wl) * np.sin(tth_rad / 2)
Expand All @@ -34,8 +35,8 @@

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

args = get_args()
print(args.__dir__)
tth, i_m = loadData(input_file, unpack=True)
wavelength = wavelengths[args.anode_type]
input_pattern = DiffractionObject()
xarray, yarray = loadData(args.data_file, unpack=True)
input_pattern.insert_scattering_quantity(xarray, yarray, "tth", metadata={ })

cve = compute_cve(tth, mu, diameter, wl)
i_c = apply_corr(i_m, cve)
q = tth_to_q(tth, wl)
cve = compute_cve(input_pattern, args.mud, wavelength)
i_c = input_pattern * cve

# get the basename from the input_file and save the corrected patter as a .tth and a .chi file.
base_name = input_file.split('.')[0]
output_chi = f"{base_name}.chi"
output_tth = f"{base_name}.tth"
np.savetxt(output_tth, np.column_stack((tth, i_c)), header='tth I(tth)')
np.savetxt(output_chi, np.column_stack((q, i_c)), header='tth I(tth)')
# base_name = input_file.split('.')[0]
# output_chi = f"{base_name}.chi"
# output_tth = f"{base_name}.tth"
# np.savetxt(output_tth, np.column_stack((tth, i_c)), header='tth I(tth)')
# np.savetxt(output_chi, np.column_stack((q, i_c)), header='tth I(tth)')
input_pattern.dump("filename", type="chi")

if __name__ == '__main__':
main()
main()
Loading