-
Notifications
You must be signed in to change notification settings - Fork 122
/
VisionLoadDetectorTable.py
47 lines (35 loc) · 1.8 KB
/
VisionLoadDetectorTable.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
#pylint: disable=no-init,invalid-name
from mantid.api import *
from mantid.simpleapi import *
from mantid.kernel import *
import numpy as np
class VisionLoadDetectorTable(PythonAlgorithm):
def category(self):
return "Utility\\Development"
def summary(self):
return "Warning - This is under development - Algorithm to load detector parameters for VISION."
def PyInit(self):
self.declareProperty(WorkspaceProperty("OutputWorkspace", "", Direction.Output),
doc="Name of Output Workspace")
self.declareProperty(FileProperty("DetectorFile", "", action=FileAction.Load, extensions=['csv']),
doc="Name of detector file to load.")
def PyExec(self):
filename = self.getPropertyValue("DetectorFile")
output_ws_name = self.getPropertyValue("OutputWorkspace")
# Open File and read parameters
spectra,l1,l2,twotheta,efixed,emode = np.genfromtxt(filename, delimiter=',', unpack=True)
# Setup the output table
output_workspace = CreateEmptyTableWorkspace(OutputWorkspace=output_ws_name)
output_workspace.addColumn("int", "spectra")
output_workspace.addColumn("double", "l1")
output_workspace.addColumn("double", "l2")
output_workspace.addColumn("double", "twotheta")
output_workspace.addColumn("double", "efixed")
output_workspace.addColumn("int", "emode")
# Write the values
for i in range(len(spectra)):
output_workspace.addRow([int(spectra[i]),float(l1[i]),float(l2[i]),
float(twotheta[i]),float(efixed[i]),int(emode[i])])
# Set the output workspace
self.setProperty("OutputWorkspace", output_workspace)
AlgorithmFactory.subscribe(VisionLoadDetectorTable)