diff --git a/diffpy/__init__.py b/diffpy/__init__.py new file mode 100644 index 0000000..e69de29 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 new file mode 100644 index 0000000..9cae851 --- /dev/null +++ b/diffpy/labpdfproc/labpdfprocapp.py @@ -0,0 +1,67 @@ +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 + +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 tth_to_q(tth, wl): +# tth_rad = np.deg2rad(tth) +# q = (4 * np.pi / wl) * np.sin(tth_rad / 2) +# return q + + + +# 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: + # labpdfproc + + # if they give less or more than 4 positional arguments, we return an error message. + if len(sys.argv) < 4: + print('usage: labpdfproc ') + + args = get_args() + print(args.__dir__) + tth, i_m = loadData(input_file, unpack=True) + + 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 diff --git a/setup.py b/setup.py index 3bdcf78..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.snmf.stretchednmfapp:main', + '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=[