forked from AmbaPant/mantid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLoadMultipleGSS.py
69 lines (55 loc) · 2.38 KB
/
LoadMultipleGSS.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
#pylint: disable=no-init,invalid-name
from mantid.api import *
from mantid.simpleapi import *
from mantid.kernel import *
import os
class LoadMultipleGSS(PythonAlgorithm):
__exts = None
__loader = None
def category(self):
return "DataHandling\\Text"
def seeAlso(self):
return [ "LoadGSS" ]
def name(self):
return "LoadMultipleGSS"
def summary(self):
return "This algorithm loads multiple gsas files from a single directory into mantid."
def __load(self, directory, prefix):
for ext in self.__exts:
filename = "%s%s" % (prefix, ext)
if len(directory) > 0:
filename = os.path.join(directory, filename)
if not os.path.exists(filename):
continue
try:
self.log().information("Trying to load '%s'" % filename)
self.__loader(Filename=filename, OutputWorkspace=prefix, UseBankIDasSpectrumNumber=True)
return
except (RuntimeError,ValueError,IOError):
pass
raise RuntimeError("Failed to load run %s" % prefix)
def PyInit(self):
self.declareProperty("FilePrefix","")
intArrayValidator = IntArrayBoundedValidator(lower=0)
self.declareProperty(IntArrayProperty("RunNumbers",[0], validator=intArrayValidator))
self.declareProperty(FileProperty("Directory", "", action=FileAction.OptionalDirectory))
def PyExec(self):
# generic stuff for running
prefix = self.getProperty("FilePrefix").value
runs = self.getProperty("RunNumbers").value
directory = self.getProperty("Directory").value.strip()
# change here if you want something other than gsas files
self.__exts = ['.txt', '.gsa']
self.__loader = LoadGSS
# load things and conjoin them
for run in runs:
wksp = "%s_%d" % (prefix,run)
self.__load(directory, wksp)
ConvertUnits(InputWorkspace=wksp, OutputWorkspace=wksp, Target="dSpacing")
AlgorithmFactory.subscribe(LoadMultipleGSS)