Skip to content

Commit 3546968

Browse files
authored
add entry point reduceUSANS (#3)
Signed-off-by: Jose Borreguero <[email protected]>
1 parent 6dc7c4f commit 3546968

File tree

5 files changed

+23
-28
lines changed

5 files changed

+23
-28
lines changed

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ license = { text = "MIT" }
1111
[project.urls]
1212
homepage = "https://github.com/neutrons/usansred/"
1313

14+
[project.scripts]
15+
reduceUSANS = "usansred.reduce_USANS:main"
16+
1417
[build-system]
1518
requires = [
1619
"setuptools >= 40.6.0",

scripts/myscripts.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/usansred/reduce.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# standard imports
2+
import argparse
23
import copy
34
import logging
45
import os
56
import csv
67
import math
8+
import warnings
79

810
# third-party imports
11+
from scipy.optimize import differential_evolution
912
import numpy
1013
from scipy.optimize import curve_fit
1114

12-
13-
"""summary.py: summary of the reduced data."""
14-
# from mpmath import fp
15-
# from openpyxl import chartsheet
16-
# from numpy.distutils.exec_command import filepath_from_subprocess_output
15+
# usansred imports
16+
from usansred.summary import reportFromCSV
1717

1818
__author__ = "Yingrui Shang"
1919
__copyright__ = "Copyright 2021, NSD, ORNL"
@@ -443,9 +443,6 @@ def _gaussian(x, k0, k1, k2):
443443
peakArea = None
444444
qOffset = None
445445

446-
from scipy.optimize import differential_evolution
447-
import warnings
448-
449446
# function for genetic algorithm to minimize (sum of squared error)
450447
def sumOfSquaredError(parameterTuple):
451448
warnings.filterwarnings(
@@ -1029,9 +1026,6 @@ def dumpReducedData(self):
10291026

10301027

10311028
if __name__ == "__main__":
1032-
from usansred.summary import reportFromCSV
1033-
import argparse
1034-
10351029
parser = argparse.ArgumentParser(description="USANS data reduction at ORNL.")
10361030
# parser.add_argument('csv file', metavar='csv_file', type=string, nargs='+',
10371031
# help='path to the csv data file')

src/usansred/reduce_USANS.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# standard imports
2+
import csv
23
import json
34
import logging
45
import math
@@ -22,6 +23,9 @@
2223
from matplotlib import use
2324
import numpy as np
2425

26+
# usansred imports
27+
from usansred import reduce
28+
from usansred.summary import reportFromCSV
2529

2630
use("agg")
2731
np.seterr(all="ignore")
@@ -56,11 +60,12 @@ def get_sequence_info(seq_file):
5660
return seq_dict
5761

5862

59-
if __name__ == "__main__":
63+
def main():
6064
# check number of arguments
6165
if len(sys.argv) != 3:
6266
print("autoreduction code requires a filename and an output directory")
63-
sys.exit()
67+
sys.exit(1)
68+
6469
if not (os.path.isfile(sys.argv[1])):
6570
print("data file ", sys.argv[1], " not found")
6671
sys.exit()
@@ -91,9 +96,8 @@ def get_sequence_info(seq_file):
9196
roi_min = (
9297
mtd["USANS"].getRun().getProperty("BL1A:Det:N1:Det1:TOF:ROI:1:Min").value[-1]
9398
)
94-
roi_step = (
95-
mtd["USANS"].getRun().getProperty("BL1A:Det:N1:Det1:TOF:ROI:1:Size").value[-1]
96-
)
99+
# roi_step = mtd["USANS"].getRun().getProperty("BL1A:Det:N1:Det1:TOF:ROI:1:Size").value[-1]
100+
97101
# Reference to the item in the wavelength array
98102
main_index = 1
99103
for i in range(1, 8):
@@ -469,8 +473,6 @@ def get_sequence_info(seq_file):
469473
else:
470474
pass
471475

472-
import csv
473-
474476
autocsvfile = os.path.join(outdir, "auto.csv")
475477

476478
with open(autocsvfile, "w", newline="") as autocsv:
@@ -485,9 +487,6 @@ def get_sequence_info(seq_file):
485487

486488
sys.path.insert(2, "/SNS/USANS/shared/autoreduce/usans-reduction")
487489

488-
from usansred import reduce
489-
from usansred.summary import reportFromCSV
490-
491490
autodir = os.path.join(outdir, "auto")
492491
if not os.path.exists(autodir):
493492
os.makedirs(autodir)
@@ -498,3 +497,7 @@ def get_sequence_info(seq_file):
498497
reportFromCSV(autocsvfile, exp.outputFolder)
499498

500499
# seq_dict = get_sequence_info(os.path.join(outdir, "scan_%s.json" % sequence_first_run))
500+
501+
502+
if __name__ == "__main__":
503+
main()

src/usansred/summary.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1+
"""summary.py: summary of the reduced data."""
2+
13
# standard imports
24
import csv
35
import logging
46
import os
57
import pandas
68
import sys
79

8-
"""summary.py: summary of the reduced data."""
9-
# from mpmath import fp
10-
# from openpyxl import chartsheet
1110
__author__ = "Yingrui Shang"
1211
__copyright__ = "Copyright 2021, NSD, ORNL"
1312

@@ -17,8 +16,6 @@
1716
console.setLevel(logging.INFO)
1817
logging.getLogger("").addHandler(console)
1918
__all__ = ["reportFromCSV"]
20-
21-
2219
suffix = 0
2320

2421

0 commit comments

Comments
 (0)