forked from AmbaPant/mantid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
LoadVisionInelastic.py
64 lines (49 loc) · 2.36 KB
/
LoadVisionInelastic.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
# 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 AlgorithmFactory
#from mantid.simpleapi import PythonAlgorithm, WorkspaceProperty
# from mantid.kernel import Direction
from mantid.api import *
from mantid.kernel import *
import mantid.simpleapi
class LoadVisionInelastic(PythonAlgorithm):
__forward = "bank1,bank2,bank3,bank4,bank5,bank6,bank7"
__backward = "bank8,bank9,bank10,bank11,bank12,bank13,bank14"
def category(self):
return "DataHandling\\Nexus"
def seeAlso(self):
return [ "LoadVisionElasticBS","LoadVisionElasticEQ" ]
def name(self):
return "LoadVisionInelastic"
def summary(self):
return "This algorithm loads only the inelastic detectors on VISION."
def PyInit(self):
self.declareProperty(FileProperty("Filename", "", action=FileAction.Load, extensions=[".nxs.h5"]))
self.declareProperty("Banks", "all")
self.declareProperty(WorkspaceProperty("OutputWorkspace", "", direction=Direction.Output))
def PyExec(self):
filename = self.getProperty("Filename").value
banks = self.getProperty("Banks").value
# First lets replace 'All' with 'forward,backward'
banks = banks.lower().replace("all", "forward,backward")
banks = banks.lower().replace("forward", self.__forward)
banks = banks.lower().replace("backward", self.__backward)
banks = banks.lower()
# Let's make sure we have a unique and sorted list
banks_integers = banks.replace("bank", "")
banks_list_integers = banks_integers.split(",")
banks_list_integers = list(set(banks_list_integers))
banks_list_integers.sort(key=int)
banks_list = ['bank{0}'.format(i) for i in banks_list_integers]
banks = ",".join(banks_list)
wksp_name = "__tmp"
ws = mantid.simpleapi.LoadEventNexus(Filename=filename, BankName=banks, OutputWorkspace=wksp_name)
self.setProperty("OutputWorkspace", ws)
mantid.simpleapi.DeleteWorkspace(wksp_name)
# Register
AlgorithmFactory.subscribe(LoadVisionInelastic)