Skip to content

Commit

Permalink
Final (hopefully) Changes for Release re #5414
Browse files Browse the repository at this point in the history
Signed-off-by: Karl Palmen <karl.palmen@stfc.ac.uk>
  • Loading branch information
KarlPalmen committed Oct 29, 2012
1 parent a9aaed5 commit db5659d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def CalibrateMerlin( RunNumber, UsePeakFile=False ):

# == Set parameters for calibration ==

path = r"C:/Temp/" # Path name of folder containing input and output files
filename = 'MER'+RunNumber+'.raw' # Name of calibration run
# File details
filename = 'MER'+str(RunNumber) # Name of calibration run
rangeLower = 3000 # Integrate counts in each spectra from rangeLower to rangeUpper
rangeUpper = 20000 #

Expand All @@ -41,7 +41,7 @@ def CalibrateMerlin( RunNumber, UsePeakFile=False ):
CalibratedComponent = 'MERLIN' # Calibrate whole instrument

# 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)
Expand Down Expand Up @@ -70,24 +70,24 @@ def CalibrateMerlin( RunNumber, UsePeakFile=False ):
# == Get the calibration and put results into calibration table ==
# also put peaks into PeakFile
if(not UsePeakFile):
getCalibration( CalibInstWS, thisTubeSet, calibrationTable, fitPar, iTube, ExcludeShortTubes=ActiveLength, PeakFile=path+'TubeCalibDemoMerlin_Peaks.txt' )
getCalibration( CalibInstWS, thisTubeSet, calibrationTable, fitPar, iTube, ExcludeShortTubes=ActiveLength, PeakFile='TubeCalibDemoMerlin_Peaks.txt' )
else:
getCalibrationFromPeakFile( CalibInstWS, calibrationTable, iTube, path+'TubeCalibDemoMerlin_Peaks.txt' )
getCalibrationFromPeakFile( CalibInstWS, calibrationTable, iTube, 'TubeCalibDemoMerlin_Peaks.txt' )
print "Got calibration (new positions of detectors) and put slit peaks into file TubeCalibDemoMerlin_Peaks.txt"

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

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

# ==== End of CalibrateMerlin() ====
# INITIALLY EXECUTE THE CODE FROM THE BEGINNING TO HERE, THEN EACH OF THE TWO CALLS BELOW IN ORDER SEPARATELY

# Run this one first
CalibrateMerlin( '12024' )
CalibrateMerlin( 12024 )

#Then edit the path+'TubeCalibDemoMerlin_Peaks.txt' file, then run
CalibrateMerlin( '12024', True)
#Then edit the'TubeCalibDemoMerlin_Peaks.txt' file, then run
CalibrateMerlin( 12024, True)
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ def CalibrateMerlin( RunNumber ):

# == Set parameters for calibration ==

path = r"C:/Temp/" # Path name of folder containing input and output files
filename = 'MER'+RunNumber+'.raw' # Name of calibration run.
filename = 'MER'+str(RunNumber) # Name of calibration run.
rangeLower = 3000 # Integrate counts in each spectra from rangeLower to rangeUpper
rangeUpper = 20000 #

Expand Down Expand Up @@ -69,17 +68,17 @@ def CalibrateMerlin( RunNumber ):

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

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

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

# ==== End of CalibrateMerlin() ====

CalibrateMerlin( '12024' )
CalibrateMerlin( 12024 )
49 changes: 27 additions & 22 deletions Code/Mantid/scripts/Calibration/tube_calib.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from tube_spec import * # For tube specification class
import math
import re
import os


def createTubeCalibtationWorkspaceByWorkspaceIndexList ( integratedWorkspace, outputWorkspace, workspaceIndexList, xUnit='Pixel', showPlot=False):
Expand Down Expand Up @@ -357,7 +358,7 @@ def getCalibratedPixelPositions( ws, tubePts, idealTubePts, whichTube, peakTestM
return detIDs, detPositions


def readPeakFile(file_path):
def readPeakFile(file_name):
"""Load the file calibration
It returns a list of tuples, where the first value is the detector identification
Expand All @@ -376,7 +377,9 @@ def readPeakFile(file_path):
# Will be splited as:
# ['MERLIN/door1/tube_1_1', '', '34.199347724575574', '', '525.5864438725401', '', '1001.7456248836971', '', '', '']
pattern = re.compile('[\[\],\s\r]')
for line in open(file_path,'r'):
saveDirectory = config['defaultsave.directory']
pfile = os.path.join(saveDirectory, file_name)
for line in open(pfile,'r'):
#check if the entry is a comment line
if line.startswith('#'):
continue
Expand Down Expand Up @@ -431,7 +434,8 @@ def getCalibration ( ws, tubeSet, calibTable, fitPar, iTube, PeakTestMode=False,

# Open Peaks File if specificed
if( PeakFile != ""):
pFile = open(PeakFile,'w')
saveDirectory = config['defaultsave.directory']
pFile = open(os.path.join(saveDirectory, PeakFile),'w')

for i in range(nTubes):

Expand Down Expand Up @@ -480,25 +484,26 @@ def getCalibration ( ws, tubeSet, calibTable, fitPar, iTube, PeakTestMode=False,
return

# Delete temporary workspaces for obtaining slit points
if( fitPar.isThreePointMethod() ):
DeleteWorkspace( 'get3pointsFor3pointMethod')
DeleteWorkspace('Z1_NormalisedCovarianceMatrix')
DeleteWorkspace('Z1_Parameters')
DeleteWorkspace('Z1_Workspace')
DeleteWorkspace('CentrePoint_NormalisedCovarianceMatrix')
DeleteWorkspace('CentrePoint_Parameters')
DeleteWorkspace('CentrePoint_Workspace')
DeleteWorkspace('LeftPoint_NormalisedCovarianceMatrix')
DeleteWorkspace('LeftPoint_Parameters')
DeleteWorkspace('LeftPoint_Workspace')
DeleteWorkspace('RightPoint_NormalisedCovarianceMatrix')
DeleteWorkspace('RightPoint_Parameters')
DeleteWorkspace('RightPoint_Workspace')
else:
DeleteWorkspace('getPeaksForNSlitsMethod')
DeleteWorkspace('CalibPeak_NormalisedCovarianceMatrix')
DeleteWorkspace('CalibPeak_Parameters')
DeleteWorkspace('CalibPeak_Workspace')
if( OverridePeaks == []):
if( fitPar.isThreePointMethod() ):
DeleteWorkspace( 'get3pointsFor3pointMethod')
DeleteWorkspace('Z1_NormalisedCovarianceMatrix')
DeleteWorkspace('Z1_Parameters')
DeleteWorkspace('Z1_Workspace')
DeleteWorkspace('CentrePoint_NormalisedCovarianceMatrix')
DeleteWorkspace('CentrePoint_Parameters')
DeleteWorkspace('CentrePoint_Workspace')
DeleteWorkspace('LeftPoint_NormalisedCovarianceMatrix')
DeleteWorkspace('LeftPoint_Parameters')
DeleteWorkspace('LeftPoint_Workspace')
DeleteWorkspace('RightPoint_NormalisedCovarianceMatrix')
DeleteWorkspace('RightPoint_Parameters')
DeleteWorkspace('RightPoint_Workspace')
else:
DeleteWorkspace('getPeaksForNSlitsMethod')
DeleteWorkspace('CalibPeak_NormalisedCovarianceMatrix')
DeleteWorkspace('CalibPeak_Parameters')
DeleteWorkspace('CalibPeak_Workspace')

# Delete temporary workspaces for getting new detector positions
DeleteWorkspace('QuadraticFittingWorkspace')
Expand Down

0 comments on commit db5659d

Please sign in to comment.