Skip to content

Commit

Permalink
Simple translation of the previous example to the new interface
Browse files Browse the repository at this point in the history
  • Loading branch information
gesnerpassos committed Jul 12, 2013
1 parent 696710f commit ff4dabf
Show file tree
Hide file tree
Showing 11 changed files with 222 additions and 377 deletions.
38 changes: 12 additions & 26 deletions Code/Mantid/scripts/Calibration/Examples/TubeCalibDemoMaps_B1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,14 @@
# Here we run the calibration of a selected part of MAPS

#
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


import tube
from tube_calib_fit_params import TubeCalibFitParams
# == Set parameters for calibration ==

path = r"C:/Temp/" # Path name of folder containing input and output files
filename = 'MAPS14919.raw' # Calibration run ( found in \\isis\inst$\NDXMAPS\Instrument\data\cycle_09_5 )
filename = 'MAP14919.raw' # Calibration run ( found in \\isis\inst$\NDXMAPS\Instrument\data\cycle_09_5 )
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)
Expand All @@ -29,38 +22,29 @@


# Get calibration raw file and integrate it
rawCalibInstWS = Load(path+filename) #'raw' in 'rawCalibInstWS' means unintegrated.
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()
# The positions of the shadows and ends here are an intelligent guess.
# First array gives positions in Metres and second array gives type 1=Gaussian peak 2=edge.
# See http://www.mantidproject.org/IdealTube for details.
iTube.setPositionsAndForm([-0.50,-0.165,-0.00, 0.165, 0.50 ],[2,1,1,1,2])
knownPos = [-0.50,-0.165,-0.00, 0.165, 0.50 ]
funcForm = [2,1,1,1,2]

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

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' )
calibrationTable, peakTable = tube.calibrate(CalibInstWS, CalibratedComponent, knownPos, funcForm,
fitPar=fitPar, outputPeak=True)
print "Got calibration (new positions of detectors) "

# == Apply the Calibation ==
Expand All @@ -69,6 +53,8 @@


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

# == Save Peak File ==
tube.savePeak(peakTable, 'TubeDemoMaps01.txt')
39 changes: 12 additions & 27 deletions Code/Mantid/scripts/Calibration/Examples/TubeCalibDemoMaps_C4C3.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,47 @@
# by running setTubeSpecByString several times.

#
import tube
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
from tube_spec import TubeSpec
#from tube_calib_fit_params import # To handle fit parameters


# == Set parameters for calibration ==

path = r"C:/Temp/" # Path name of folder containing input and output files
filename = 'MAPS14919.raw' # Name of calibration run
filename = 'MAP14919.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 )
CalibratedComponent1 = 'C4_window' # Calibrate C4 window
CalibratedComponent2 = 'C3_window' # Calibrate C3 window


# Get calibration raw file and integrate it
rawCalibInstWS = Load(path+filename) #'raw' in 'rawCalibInstWS' means unintegrated.
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 components to calibrate
thisTubeSet = TubeSpec(CalibInstWS)
thisTubeSet.setTubeSpecByString(CalibratedComponent1)
thisTubeSet.setTubeSpecByString(CalibratedComponent2)

# 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 )
# Specify the known positions
knownPos = [-0.50,-0.16,-0.00, 0.16, 0.50 ]
funcForm = [2,1,1,1,2]

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' )

calibrationTable, peakTable = tube.calibrate(CalibInstWS, thisTubeSet, knownPos, funcForm,
outputPeak=True, margin=15)
print "Got calibration (new positions of detectors) "

# == Apply the Calibation ==
Expand All @@ -69,6 +54,6 @@


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

Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,38 @@
# 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

import tube

# == Set parameters for calibration ==

path = r"C:/Temp/" # Path name of folder containing input and output files
filename = 'MAPS14919.raw' # Name of calibration run
filename = 'MAP14919.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 )
# 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.
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 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 )
# Specify the known positions
knownPos = [-0.50,-0.16,-0.00, 0.16, 0.50 ]
funcForm = [2,1,1,1,2]

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' )

calibrationTable, peakTable = tube.calibrate(CalibInstWS, CalibratedComponents, knownPos, funcForm,
outputPeak=True, margin=15)
print "Got calibration (new positions of detectors) "

# == Apply the Calibation ==
Expand All @@ -66,6 +44,7 @@


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


59 changes: 20 additions & 39 deletions Code/Mantid/scripts/Calibration/Examples/TubeCalibDemoMaps_D2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,71 +4,52 @@
# Here we run the calibration of a selected part of MAPS

#
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


import tube
from tube_calib_fit_params import TubeCalibFitParams
# == Set parameters for calibration ==

path = r"C:/Temp/" # Path name of folder containing input and output files
filename = 'MAPS14919.raw' # Calibration run ( found in \\isis\inst$\NDXMAPS\Instrument\data\cycle_09_5 )
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, 161.0, 252.0] # Expected positions of the edges and Gaussian peaks in pixels (initial values of fit parameters)

filename = 'MAP14919.raw' # Calibration run ( found in \\isis\inst$\NDXMAPS\Instrument\data\cycle_09_5 )
# Set what we want to calibrate (e.g whole intrument or one door )
CalibratedComponent = 'D2_window' # Calibrate D2 window


# Get calibration raw file and integrate it
rawCalibInstWS = Load(path+filename) #'raw' in 'rawCalibInstWS' means unintegrated.
rawCalibInstWS = Load(filename) #'raw' in 'rawCalibInstWS' means unintegrated.
print "Integrating Workspace"
rangeLower = 2000 # Integrate counts in each spectra from rangeLower to rangeUpper
rangeUpper = 10000 #
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()
# The positions of the shadows and ends here are an intelligent guess.
# First array gives positions in Metres and second array gives type 1=Gaussian peak 2=edge.
# See http://www.mantidproject.org/IdealTube for details.
iTube.setPositionsAndForm([-0.65,-0.22,-0.00, 0.22, 0.65 ],[2,1,1,1,2])

knownPos = [-0.65,-0.22,-0.00, 0.22, 0.65 ]
funcForm = [2,1,1,1,2]

# Get fitting parameters
fitPar = TubeCalibFitParams( ExpectedPositions, ExpectedHeight, ExpectedWidth )
# 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, 161.0, 252.0] # Expected positions of the edges and Gaussian peaks in pixels (initial values of fit parameters)
fitPar = TubeCalibFitParams( ExpectedPositions, ExpectedHeight, ExpectedWidth)
fitPar.setAutomatic(True)

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' )
calibrationTable = tube.calibrate(CalibInstWS, CalibratedComponent, knownPos, funcForm,
fitPar = fitPar)
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"
#SaveNexusProcessed( CalibInstWS, 'TubeCalibDemoMapsResult.nxs',"Result of Running TCDemoMaps.py")
#print "saved calibrated workspace (CalibInstWS) into Nexus file TubeCalibDemoMapsResult.nxs"

0 comments on commit ff4dabf

Please sign in to comment.