Skip to content

Commit

Permalink
Enable multiple components to be specified by string array re #6755
Browse files Browse the repository at this point in the history
Also added an example that uses this.

Signed-off-by: Karl Palmen <karl.palmen@stfc.ac.uk>
  • Loading branch information
KarlPalmen committed Apr 3, 2013
1 parent 7aee6ba commit 9d84e59
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#
# TUBE CALIBRATION DEMONSTRATION PROGRAM FOR MAPS - Execute this
#
# Here we run the calibration of a selected part of MAPS consisting of several components
# Here we run the calibration of a selected part of MAPS consisting of several components
# by running setTubeSpecByString several times.

#
from mantid.api import WorkspaceFactory # For table worskspace of calibrations
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#
# TUBE CALIBRATION DEMONSTRATION PROGRAM FOR MAPS - Execute this
#
# Here we run the calibration of a selected part of MAPS consisting of several components
# specifying them in an array of strings.

#
from mantid.api import WorkspaceFactory # For table worskspace of calibrations
from tube_calib_fit_params import * # To handle fit parameters
from ideal_tube import * # For ideal tube
from tube_calib import * # For tube calibration functions
from tube_spec import * # For tube specification class


# == Set parameters for calibration ==

path = r"C:/Temp/" # Path name of folder containing input and output files
filename = 'MAPS14919.raw' # Name of calibration run
rangeLower = 2000 # Integrate counts in each spectra from rangeLower to rangeUpper
rangeUpper = 10000 #


# Set initial parameters for peak finding
ExpectedHeight = -1000.0 # Expected Height of Peaks (initial value of fit parameter)
ExpectedWidth = 8.0 # Expected width of centre peak (initial value of fit parameter)
ExpectedPositions = [4.0, 85.0, 128.0, 161.0, 252.0] # Expected positions of the edges and peak (initial values of fit parameters)

# Set what we want to calibrate (e.g whole intrument or one door )
CalibratedComponents = ['C4_window','C3_window','C2_window'] # Calibrate three C windows

# Get calibration raw file and integrate it
rawCalibInstWS = Load(path+filename) #'raw' in 'rawCalibInstWS' means unintegrated.
print "Integrating Workspace"
CalibInstWS = Integration( rawCalibInstWS, RangeLower=rangeLower, RangeUpper=rangeUpper )
DeleteWorkspace(rawCalibInstWS)
print "Created workspace (CalibInstWS) with integrated data from run and instrument to calibrate"

# == Create Objects needed for calibration ==

#Create Calibration Table
calibrationTable = CreateEmptyTableWorkspace(OutputWorkspace="CalibTable")
calibrationTable.addColumn(type="int",name="Detector ID") # "Detector ID" column required by ApplyCalbration
calibrationTable.addColumn(type="V3D",name="Detector Position") # "Detector Position" column required by ApplyCalbration

# Specify components to calibrate
thisTubeSet = TubeSpec(CalibInstWS)
thisTubeSet.setTubeSpecByStringArray(CalibratedComponents)

# Get ideal tube
iTube = IdealTube()
iTube.setPositionsAndForm([-0.50,-0.16,-0.00, 0.16, 0.50 ],[2,1,1,1,2])

# Get fitting parameters
fitPar = TubeCalibFitParams( ExpectedPositions, ExpectedHeight, ExpectedWidth )

print "Created objects needed for calibration."

# == Get the calibration and put results into calibration table ==
# also put peaks into PeakFile
getCalibration( CalibInstWS, thisTubeSet, calibrationTable, fitPar, iTube, PeakFile=path+'TubeDemoMaps01.txt' )
print "Got calibration (new positions of detectors) "

# == Apply the Calibation ==
ApplyCalibration( Workspace=CalibInstWS, PositionTable=calibrationTable)
print "Applied calibration"


# == Save workspace ==
SaveNexusProcessed( CalibInstWS, path+'TubeCalibDemoMapsResult.nxs',"Result of Running TCDemoMaps.py")
print "saved calibrated workspace (CalibInstWS) into Nexus file TubeCalibDemoMapsResult.nxs"

13 changes: 12 additions & 1 deletion Code/Mantid/scripts/Calibration/tube_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def __init__(self,ws):
self.componentArray = []
self.minNumDetsInTube = 200
self.tubes = []
self.delimiter = '/' # delimiter between parts of string in tree


def setTubeSpecByString(self, tubeSpecString ):
"""
Expand All @@ -43,8 +45,17 @@ def setTubeSpecByString(self, tubeSpecString ):
be no error message. So if in doubt don't skip a step.
"""
self.componentNameArray.append(tubeSpecString)
self.delimiter = '/' # delimiter between parts of string in tree
self.numTubes = -1 # Negative value forces tubes to be searched and counted


def setTubeSpecByStringArray( self, tubeSpecArray ):
"""
Set tube specification like setTubeSpecByString, but with an array of string
to enable multiple components to be calibrated
"""
for i in range(len(tubeSpecArray)):
self.setTubeSpecByString(tubeSpecArray[i])


def getInstrumentName (self):
return self.inst.getName()
Expand Down

0 comments on commit 9d84e59

Please sign in to comment.