Newer
Older
import os
from mantid.api import *
Federico Montesino Pouzols
committed
import mantid.simpleapi as sapi
def getDetIDsForBank(bank):
""" Returns detector IDs corresponding to the specified EnginX bank number
"""
Federico Montesino Pouzols
committed
groupingFilePath = os.path.join(sapi.config.getInstrumentDirectory(),
'Grouping', 'ENGINX_Grouping.xml')
alg = AlgorithmManager.create('LoadDetectorsGroupingFile')
alg.setProperty('InputFile', groupingFilePath)
alg.setProperty('OutputWorkspace', '__EnginXGrouping')
alg.execute()
grouping = mtd['__EnginXGrouping']
detIDs = set()
for i in range(grouping.getNumberHistograms()):
if grouping.readY(i)[0] == bank:
detIDs.add(grouping.getDetector(i).getID())
Federico Montesino Pouzols
committed
sapi.DeleteWorkspace(grouping)
if len(detIDs) == 0:
return detIDs
def getWsIndicesForBank(bank, ws):
""" Get a list of workspace indices which correspond to the specified bank
"""
detIDs = getDetIDsForBank(bank)
def isIndexInBank(index):
try:
det = ws.getDetector(index)
return det.getID() in detIDs
Federico Montesino Pouzols
committed
except RuntimeError:
Federico Montesino Pouzols
committed
return [i for i in range(0, ws.getNumberHistograms()) if isIndexInBank(i)]
Federico Montesino Pouzols
committed
def generateOutputParTable(self, name, difc, zero):
"""
Produces a table workspace with the two fitted calibration parameters
@param name :: the name to use for the table workspace that is created here
"""
tbl = sapi.CreateEmptyTableWorkspace(OutputWorkspace=name)
tbl.addColumn('double', 'difc')
tbl.addColumn('double', 'zero')
tbl.addRow([float(difc), float(zero)])