-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Signed-off-by: Karl Palmen <karl.palmen@stfc.ac.uk>
- Loading branch information
1 parent
469b50b
commit 3e83adf
Showing
5 changed files
with
178 additions
and
10 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
Code/Mantid/scripts/Calibration/Examples/TubeCalibDemoMaps_Simple.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# | ||
# TUBE CALIBRATION DEMONSTRATION PROGRAM FOR MAPS | ||
# | ||
# This is a simple example for running calibration for and calibration run of MAPS. | ||
# It uses the CalibrateMaps function | ||
|
||
# | ||
from mantid.api import WorkspaceFactory # For table worskspace of calibrations | ||
from mantid.kernel import config # To set default instrument to MAPS | ||
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 | ||
|
||
def CalibrateMaps( RunNumber ): | ||
''' | ||
RunNumber is the run number for the calibration. | ||
''' | ||
|
||
# == Set parameters for calibration == | ||
previousDefaultInstrument = config['default.instrument'] | ||
config['default.instrument']="MAPS" | ||
filename = str(RunNumber) # Name of calibration run | ||
print "Filename",filename | ||
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 Gaussian Peaks (initial value of fit parameter) | ||
ExpectedWidth = 8.0 # Expected width of Gaussian peaks in pixels (initial value of fit parameter) | ||
ExpectedPositions = [4.0, 85.0, 128.0, 165.0, 252.0] #Expected positions of the edges and Gaussian peaks in pixels (initial values of fit parameters) | ||
|
||
# Set what we want to calibrate (e.g whole intrument or one door ) | ||
CalibratedComponent = 'MAPS' # Calibrate all | ||
|
||
|
||
# Get calibration raw file and integrate it | ||
rawCalibInstWS = Load(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 component to calibrate | ||
thisTubeSet = TubeSpec(CalibInstWS) | ||
thisTubeSet.setTubeSpecByString(CalibratedComponent) | ||
|
||
# Get ideal tube | ||
iTube = IdealTube() | ||
# Set positions of where the shadows and ends should be. | ||
# First array gives positions in Metres and second array gives type 1=Gaussian peak 2=edge. | ||
# See http://www.mantidproject.org/IdealTube for details | ||
# An intelligent guess is used here that is not correct for all tubes. | ||
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 ) | ||
print "Got calibration (new positions of detectors) " | ||
|
||
# == Apply the Calibation == | ||
ApplyCalibration( Workspace=CalibInstWS, PositionTable=calibrationTable) | ||
print "Applied calibration" | ||
|
||
|
||
# == Save workspace == | ||
SaveNexusProcessed( CalibInstWS, 'TubeCalibDemoMapsResult.nxs',"Result of Running MAPS Calibration") | ||
print "saved calibrated workspace (CalibInstWS) into Nexus file TubeCalibDemoMapsResult.nxs" | ||
|
||
# == Reset dafault instrument == | ||
config['default.instrument'] = previousDefaultInstrument | ||
|
||
# ==== End of CalibrateMaps() ==== | ||
|
||
CalibrateMaps( 14919 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
Code/Mantid/scripts/Calibration/Examples/TubeCalibDemoWish_Simple.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# | ||
# TUBE CALIBRATION DEMONSTRATION PROGRAM FOR WISH | ||
# | ||
# Here we run the calibration of WISH panel03 using a simple CalibrateWish function. | ||
# | ||
from mantid.api import WorkspaceFactory # For table worskspace of calibrations | ||
from mantid.kernel import config # To set default instrument to WISH | ||
from ideal_tube import * # for ideal tube | ||
from tube_calib_fit_params import * # To handle fit parameters | ||
from tube_calib import * # For tube calibration functions | ||
from tube_spec import * # For tube specification class | ||
|
||
def CalibrateWish( RunNumber, PanelNumber ): | ||
''' | ||
RunNumber is the run number of the calibration. | ||
PanelNumber is a string of two-digit number of the panel being calibrated | ||
''' | ||
# == Set parameters for calibration == | ||
previousDefaultInstrument = config['default.instrument'] | ||
config['default.instrument']="WISH" | ||
filename = str(RunNumber) | ||
CalibratedComponent = 'WISH/panel'+PanelNumber | ||
|
||
|
||
# Get calibration raw file and integrate it | ||
print "Loading",filename | ||
rawCalibInstWS = Load(filename) #'raw' in 'rawCalibInstWS' means unintegrated. | ||
CalibInstWS = Integration( rawCalibInstWS, RangeLower=1, RangeUpper=20000 ) | ||
DeleteWorkspace(rawCalibInstWS) | ||
print "Created workspace (CalibInstWS) with integrated data from run and instrument to calibrate" | ||
|
||
#Create Calibration Table | ||
calibrationTable = CreateEmptyTableWorkspace(OutputWorkspace="CalibTable") | ||
calibrationTable.addColumn(type="int",name="Detector ID") # "Detector ID" column required by ApplyCalibration | ||
calibrationTable.addColumn(type="V3D",name="Detector Position") # "Detector Position" column required by ApplyCalibration | ||
|
||
# Specify panel of WISH instrument | ||
thisTubeSet = TubeSpec(CalibInstWS) | ||
print "Calibrating",CalibratedComponent | ||
thisTubeSet.setTubeSpecByString(CalibratedComponent) | ||
|
||
# Give y-positions of slit points (gotten for converting first tube's slit point to Y) | ||
iTube = IdealTube() | ||
iTube.setArray([-0.41,-0.31,-0.21,-0.11,-0.02, 0.09, 0.18, 0.28, 0.39 ]) | ||
|
||
# Set fitting parameters | ||
eP = [57.5, 107.0, 156.5, 206.0, 255.5, 305.0, 354.5, 404.0, 453.5] | ||
ExpectedHeight = 2000.0 # Expected Height of Gaussian Peaks (initial value of fit parameter) | ||
ExpectedWidth = 32.0 # Expected width of Gaussian peaks in pixels (initial value of fit parameter) | ||
|
||
fitPar = TubeCalibFitParams( eP, ExpectedHeight, ExpectedWidth ) | ||
|
||
|
||
print "Created objects needed for calibration." | ||
|
||
# Get the calibration and put it into the calibration table | ||
getCalibration( CalibInstWS, thisTubeSet, calibrationTable, fitPar, iTube) | ||
print "Got calibration (new positions of detectors)" | ||
|
||
#Apply the calibration | ||
ApplyCalibration( Workspace=CalibInstWS, PositionTable=calibrationTable) | ||
print "Applied calibration" | ||
|
||
# == Save workspace == | ||
nexusName = "TubeCalibDemoWish"+PanelNumber+"Result.nxs" | ||
SaveNexusProcessed( CalibInstWS, 'TubeCalibDemoWishResult.nxs',"Result of Running TubeCalibWishMerlin_Simple.py") | ||
print "saved calibrated workspace (CalibInstWS) into Nexus file",nexusName | ||
|
||
# == Reset dafault instrument == | ||
config['default.instrument'] = previousDefaultInstrument | ||
|
||
# ==== End of CalibrateWish() ==== | ||
|
||
CalibrateWish( 17701, '03' ) |