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

first iteration of functional app #1

Merged
merged 3 commits into from
Feb 26, 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
Empty file added diffpy/__init__.py
Empty file.
Empty file added diffpy/labpdfproc/functions.py
Empty file.
67 changes: 67 additions & 0 deletions diffpy/labpdfproc/labpdfprocapp.py
Original file line number Diff line number Diff line change
@@ -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 <input_file> <mu> <diameter> <Ag, ag, Mo, mo, Cu, cu>

# if they give less or more than 4 positional arguments, we return an error message.
if len(sys.argv) < 4:
print('usage: labpdfproc <input_file> <mu> <diameter> <lambda>')

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()
21 changes: 12 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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=[
Expand Down