From b0061c0bd58dfac3f96212c886226e818a6f0e20 Mon Sep 17 00:00:00 2001 From: tschertenleib Date: Fri, 23 Feb 2024 12:32:02 -0500 Subject: [PATCH 1/3] hello world --- diffpy/__init__.py | 0 diffpy/labpdfproc/labpdfprocapp.py | 5 +++++ setup.py | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 diffpy/__init__.py create mode 100644 diffpy/labpdfproc/labpdfprocapp.py diff --git a/diffpy/__init__.py b/diffpy/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/diffpy/labpdfproc/labpdfprocapp.py b/diffpy/labpdfproc/labpdfprocapp.py new file mode 100644 index 0000000..299f3a6 --- /dev/null +++ b/diffpy/labpdfproc/labpdfprocapp.py @@ -0,0 +1,5 @@ +def main(): + print('hello world') + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/setup.py b/setup.py index 3bdcf78..2404a61 100644 --- a/setup.py +++ b/setup.py @@ -51,7 +51,7 @@ packages=find_packages(exclude=["docs", "tests"]), entry_points={ "console_scripts": [ - 'labpdfproc = diffpy.snmf.stretchednmfapp:main', + 'labpdfproc = diffpy.labpdfproc.labpdfprocapp:main', ], }, include_package_data=True, From 4f71aa2a56f4bd508eb4931b891a6c0f6adf1945 Mon Sep 17 00:00:00 2001 From: tschertenleib Date: Fri, 23 Feb 2024 17:47:01 -0500 Subject: [PATCH 2/3] arbitrary correction for testing global structure --- diffpy/labpdfproc/labpdfprocapp.py | 67 +++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/diffpy/labpdfproc/labpdfprocapp.py b/diffpy/labpdfproc/labpdfprocapp.py index 299f3a6..d9ea91b 100644 --- a/diffpy/labpdfproc/labpdfprocapp.py +++ b/diffpy/labpdfproc/labpdfprocapp.py @@ -1,5 +1,70 @@ +import sys +import numpy as np + +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. + # we want to load the tth column in a numpy array + # we want to load the intensitie Im into a numpy array + # the input files should not contain any header. Typically, .xy or .xye files don't contain headers. + tth = np.loadtxt(input_file, usecols=0) + i_m = np.loadtxt(input_file, usecols=1) + # this should return an error if the first row contains anything except a float, and if the columns are not separated by a space. + # I think the latter is also dealt with if we check if the first elemnt in one tth is a flaot. + if np.issubdtype(tth[0], np.floating) and np.issubdtype(i_m[0], np.floating): + return tth, i_m + 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) + return q + +def compute_cve(tth, mu, wl, diameter): + # for a given mu and d and lambda, we will compute cve on a tth grid + + # something arbitrary for the moment + cve = np.ones(len(tth)) + cve = cve * mu * wl * diameter + + 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 + +# def write_files(base_name): + # we save the corrected intensities in a two-column file on a q-grid and a tth-grid. + # we need to know the x-ray wavelenth so that we can convert tth to q + # we make a new two-column file .chi where column 1 contains the q grid and columnt 2 contains the corrected intensities. + + def main(): - print('hello world') + # we want the user to type the following: + # labpdfproc + + # if they give less or more than 4 positional arguments, we return an error message. + if len(sys.argv) < 4: + print('usage: labpdfcor ') + + + input_file = sys.argv[1] + tth, i_m = load_data(input_file) + + mu = float(sys.argv[2]) + diameter = float(sys.argv[3]) + wl = float(sys.argv[4]) + cve = compute_cve(tth, mu, diameter, wl) + i_c = apply_corr(i_m, cve) + q = tth_to_q(tth, wl) + + # 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)') if __name__ == '__main__': main() \ No newline at end of file From 7d56995e32b1800d2766806d5527f8dc94ffe729 Mon Sep 17 00:00:00 2001 From: tschertenleib Date: Mon, 26 Feb 2024 17:44:43 -0500 Subject: [PATCH 3/3] intermediate commit of app. still not working --- diffpy/labpdfproc/functions.py | 0 diffpy/labpdfproc/labpdfprocapp.py | 71 ++++++++++++++---------------- setup.py | 19 ++++---- 3 files changed, 45 insertions(+), 45 deletions(-) create mode 100644 diffpy/labpdfproc/functions.py diff --git a/diffpy/labpdfproc/functions.py b/diffpy/labpdfproc/functions.py new file mode 100644 index 0000000..e69de29 diff --git a/diffpy/labpdfproc/labpdfprocapp.py b/diffpy/labpdfproc/labpdfprocapp.py index d9ea91b..9cae851 100644 --- a/diffpy/labpdfproc/labpdfprocapp.py +++ b/diffpy/labpdfproc/labpdfprocapp.py @@ -1,44 +1,44 @@ 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 -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. - # we want to load the tth column in a numpy array - # we want to load the intensitie Im into a numpy array - # the input files should not contain any header. Typically, .xy or .xye files don't contain headers. - tth = np.loadtxt(input_file, usecols=0) - i_m = np.loadtxt(input_file, usecols=1) - # this should return an error if the first row contains anything except a float, and if the columns are not separated by a space. - # I think the latter is also dealt with if we check if the first elemnt in one tth is a flaot. - if np.issubdtype(tth[0], np.floating) and np.issubdtype(i_m[0], np.floating): - return tth, i_m - 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) - return q +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. +# # we want to load the tth column in a numpy array +# # we want to load the intensitie Im into a numpy array +# # the input files should not contain any header. Typically, .xy or .xye files don't contain headers. +# tth = np.loadtxt(input_file, usecols=0) +# i_m = np.loadtxt(input_file, usecols=1) +# # this should return an error if the first row contains anything except a float, and if the columns are not separated by a space. +# # I think the latter is also dealt with if we check if the first elemnt in one tth is a flaot. +# if np.issubdtype(tth[0], np.floating) and np.issubdtype(i_m[0], np.floating): +# return tth, i_m +# else: +# raise ValueError('Error: your .xy contains headers. Delete the header rows in your .xy or .xye file') -def compute_cve(tth, mu, wl, diameter): - # for a given mu and d and lambda, we will compute cve on a tth grid - - # something arbitrary for the moment - cve = np.ones(len(tth)) - cve = cve * mu * wl * diameter - return cve +# def tth_to_q(tth, wl): +# tth_rad = np.deg2rad(tth) +# q = (4 * np.pi / wl) * np.sin(tth_rad / 2) +# return q + -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 # def write_files(base_name): # we save the corrected intensities in a two-column file on a q-grid and a tth-grid. # we need to know the x-ray wavelenth so that we can convert tth to q # we make a new two-column file .chi where column 1 contains the q grid and columnt 2 contains the corrected intensities. - + +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("--anode_type", help=f"x-ray source, allowed values:{*[known_sources],}", default="Mo") + args = p.parse_args() + return args def main(): # we want the user to type the following: @@ -46,15 +46,12 @@ def main(): # if they give less or more than 4 positional arguments, we return an error message. if len(sys.argv) < 4: - print('usage: labpdfcor ') + print('usage: labpdfproc ') + args = get_args() + print(args.__dir__) + tth, i_m = loadData(input_file, unpack=True) - input_file = sys.argv[1] - tth, i_m = load_data(input_file) - - mu = float(sys.argv[2]) - diameter = float(sys.argv[3]) - wl = float(sys.argv[4]) cve = compute_cve(tth, mu, diameter, wl) i_c = apply_corr(i_m, cve) q = tth_to_q(tth, wl) diff --git a/setup.py b/setup.py index 2404a61..346ed14 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,13 @@ import sys +import os from os import path from setuptools import find_packages, setup import versioneer +MYDIR = os.path.dirname(os.path.abspath(__file__)) + # NOTE: This file must remain Python 2 compatible for the foreseeable future, # to ensure that we error out properly for people with outdated setuptools # and/or pip. @@ -48,20 +51,20 @@ author_email="sb2896@columbia.edu", url="https://github.com/sbillinge/diffpy.labpdfproc", python_requires=">={}".format(".".join(str(n) for n in min_version)), - packages=find_packages(exclude=["docs", "tests"]), + packages=find_packages(os.path.join(MYDIR, "diffpy"), exclude=["docs", "tests"]), entry_points={ "console_scripts": [ 'labpdfproc = diffpy.labpdfproc.labpdfprocapp:main', ], }, include_package_data=True, - package_data={ - "labpdfproc": [ - # When adding files here, remember to update MANIFEST.in as well, - # or else they will not be included in the distribution on PyPI! - # 'path/to/data_file', - ] - }, + # package_data={ + # "labpdfproc": [ + # # When adding files here, remember to update MANIFEST.in as well, + # # or else they will not be included in the distribution on PyPI! + # # 'path/to/data_file', + # ] + # }, install_requires=requirements, license="BSD (3-clause)", classifiers=[