| 1 | import numpy |
|---|
| 2 | from mantid.simpleapi import * |
|---|
| 3 | import tube |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | filename = 'MER12024.raw' # Calibration run ( found in \\isis\inst$\NDXMERLIN\Instrument\data\cycle_11_5 ) |
|---|
| 8 | |
|---|
| 9 | # == Set parameters for calibration == |
|---|
| 10 | |
|---|
| 11 | rangeLower = 3000 # Integrate counts in each spectra from rangeLower to rangeUpper |
|---|
| 12 | rangeUpper = 20000 # |
|---|
| 13 | |
|---|
| 14 | # Get calibration raw file and integrate it |
|---|
| 15 | rawCalibInstWS = LoadRaw(filename) #'raw' in 'rawCalibInstWS' means unintegrated. |
|---|
| 16 | print "Integrating Workspace" |
|---|
| 17 | CalibInstWS = Integration( rawCalibInstWS, RangeLower=rangeLower, RangeUpper=rangeUpper ) |
|---|
| 18 | DeleteWorkspace(rawCalibInstWS) |
|---|
| 19 | print "Created workspace (CalibInstWS) with integrated data from run and instrument to calibrate" |
|---|
| 20 | |
|---|
| 21 | # the known positions are given in pixels inside the tubes and transformed to provide the positions |
|---|
| 22 | # with the center of the tube as the origin |
|---|
| 23 | knownPositions = 2.92713867188*(numpy.array([ 27.30074322, 92.5, 294.65178585, 362.37861919 , 512.77103043 ,663.41425323, 798.3223896, 930.9, 997.08480835])/1024 - 0.5) |
|---|
| 24 | funcForm = numpy.array([2,2,1,1,1,1,1,2,2],numpy.int8) |
|---|
| 25 | # The calibration will follow different steps for sets of tubes |
|---|
| 26 | |
|---|
| 27 | # For the door9, the best points to define the known positions are the 1st edge, 5 peaks, last edge. |
|---|
| 28 | points7 = knownPositions[[0,2,3,4,5,6,8]] |
|---|
| 29 | points7func = funcForm[[0,2,3,4,5,6,8]] |
|---|
| 30 | |
|---|
| 31 | door9pos = points7 |
|---|
| 32 | door9func = points7func |
|---|
| 33 | CalibratedComponent = 'MERLIN/door9' # door9 |
|---|
| 34 | # == Get the calibration and put results into calibration table == |
|---|
| 35 | # also put peaks into PeakFile |
|---|
| 36 | calibrationTable, peakTable = tube.calibrate(CalibInstWS, CalibratedComponent, door9pos, door9func, |
|---|
| 37 | outputPeak=True, |
|---|
| 38 | margin=30, |
|---|
| 39 | rangeList=range(20) # because 20, 21, 22, 23 are defective detectors |
|---|
| 40 | ) |
|---|
| 41 | ApplyCalibration( Workspace=CalibInstWS, PositionTable=calibrationTable) |
|---|
| 42 | #################################### |
|---|
| 43 | # Pause and see the instrument check |
|---|
| 44 | #################################### |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | # For the door8, the best points to define the known positions are the 1st edge, 5 peaks, last_edge |
|---|
| 49 | door8pos = points7 |
|---|
| 50 | door8func = points7func |
|---|
| 51 | CalibratedComponent = 'MERLIN/door8' |
|---|
| 52 | calibrationTable, peakTable = tube.calibrate(CalibInstWS, CalibratedComponent, door8pos, |
|---|
| 53 | door8func, |
|---|
| 54 | outputPeak = True, #change to peakTable to append to peakTable |
|---|
| 55 | margin = 30) |
|---|
| 56 | analisePeakTable(peakTable, 'door8_peaks') |
|---|
| 57 | |
|---|
| 58 | # For the doors 7,6,5,4, 2, 1 we may use the 9 points |
|---|
| 59 | doorpos = knownPositions |
|---|
| 60 | doorfunc = funcForm |
|---|
| 61 | CalibratedComponent = ['MERLIN/door%d'%(i) for i in [7,6,5,4, 2, 1]] |
|---|
| 62 | calibrationTable, peakTable = tube.calibrate(CalibInstWS, CalibratedComponent, doorpos, |
|---|
| 63 | doorfunc, |
|---|
| 64 | outputPeak = True, |
|---|
| 65 | margin = 30) |
|---|
| 66 | ApplyCalibration( Workspace=CalibInstWS, PositionTable=calibrationTable) |
|---|
| 67 | #################################### |
|---|
| 68 | # Pause and see the instrument check |
|---|
| 69 | #################################### |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | # The door 3 is a special case, because it is composed by diffent kind of tubes. |
|---|
| 74 | # door 3 tubes: 5_8, 5_7, 5_6, 5_5, 5_4, 5_3, 5_2, 5_1, 4_8, 4_7, 4_6, 4_5, 4_4, 4_3, 4_2, 4_1, 3_8, 3_7, 3_6, 3_5, 3_4 |
|---|
| 75 | # obeys the same rules as the doors 7, 6, 5, 4, 2, 1 |
|---|
| 76 | # For the tubes 3_3, 3_2, 3_1 -> it is better to skip the central peak |
|---|
| 77 | # For the tubes 1_x (smaller tube below), it is better to take the final part of known positions: peak4,peak5,edge6,edge7 |
|---|
| 78 | # For the tubes 2_x (smaller tube above, it is better to take the first part of known positions: edge1, edge2, peak1,peak2 |
|---|
| 79 | |
|---|
| 80 | # NOTE: the smaller tubes they have length = 1.22879882813, but 1024 detectors |
|---|
| 81 | # so we have to correct the known positiosn by multiplying by its lenght and dividing by the longer dimension |
|---|
| 82 | |
|---|
| 83 | from tube_calib_fit_params import TubeCalibFitParams |
|---|
| 84 | |
|---|
| 85 | # calibrating tubes 1_x |
|---|
| 86 | CalibratedComponent = ['MERLIN/door3/tube_1_%d'%(i) for i in range(1,9)] |
|---|
| 87 | |
|---|
| 88 | half_diff_center = (2.92713867188 -1.22879882813)/2 # difference among the expected center position for both tubes |
|---|
| 89 | |
|---|
| 90 | # here a little bit of attempts is necessary. The efective center position and lengh is different for the calibrated tube, that |
|---|
| 91 | # is the reason, the calibrated values of the smaller tube does not seems aligned with the others. By, finding the 'best' half_diff_center |
|---|
| 92 | # value, the alignment occurs nicely. |
|---|
| 93 | half_diff_center = 0.835 # |
|---|
| 94 | |
|---|
| 95 | # the knownpositions were given with the center of the bigger tube as origin, to convert |
|---|
| 96 | # to the center of the upper tube as origin is necessary to subtract them with the half_diff_center |
|---|
| 97 | doorpos = knownPositions[[5,6,7,8]] - half_diff_center |
|---|
| 98 | doorfunc = [1,1,2,2] |
|---|
| 99 | # for the smal tubes, automatically searching for the peak position in pixel was not working quite well, |
|---|
| 100 | # so we will give the aproximate position for these tubes through fitPar argument |
|---|
| 101 | fitPar = TubeCalibFitParams([216, 527, 826, 989]) |
|---|
| 102 | fitPar.setAutomatic(True) |
|---|
| 103 | |
|---|
| 104 | calibrationTable, peakTable = tube.calibrate(CalibInstWS, CalibratedComponent, doorpos, |
|---|
| 105 | doorfunc, |
|---|
| 106 | outputPeak = True, |
|---|
| 107 | fitPar = fitPar, |
|---|
| 108 | margin = 30) |
|---|
| 109 | ApplyCalibration( Workspace=CalibInstWS, PositionTable=calibrationTable) |
|---|
| 110 | #################################### |
|---|
| 111 | # Pause and see the instrument check |
|---|
| 112 | #################################### |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | # calibrating tubes 2_x |
|---|
| 116 | CalibratedComponent = ['MERLIN/door3/tube_2_%d'%(i) for i in range(1,9)] |
|---|
| 117 | # the knownpositions were given with the center of the bigger tube as origin, to convert |
|---|
| 118 | # to the center of the lower tube as origin is necessary to sum them with (len_big - len_small)/2 |
|---|
| 119 | doorpos = knownPositions[[0,1,2,3]] + half_diff_center |
|---|
| 120 | # print doorpos |
|---|
| 121 | doorfunc = [2,2,1,1] |
|---|
| 122 | |
|---|
| 123 | # for the smal tubes, automatically searching for the peak position in pixel was not working quite well, |
|---|
| 124 | # so we will give the aproximate position for these tubes through fitPar argument |
|---|
| 125 | fitPar = TubeCalibFitParams([50, 202, 664, 815]) |
|---|
| 126 | fitPar.setAutomatic(True) |
|---|
| 127 | |
|---|
| 128 | calibrationTable, peakTable = tube.calibrate(CalibInstWS, CalibratedComponent, doorpos, |
|---|
| 129 | doorfunc, |
|---|
| 130 | outputPeak = True, |
|---|
| 131 | fitPar = fitPar, |
|---|
| 132 | margin = 30) |
|---|
| 133 | ApplyCalibration( Workspace=CalibInstWS, PositionTable=calibrationTable) |
|---|
| 134 | #################################### |
|---|
| 135 | # Pause and see the instrument check |
|---|
| 136 | #################################### |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | # calibrating tubes 3_3,3_2,3_1 |
|---|
| 140 | CalibratedComponent = ['MERLIN/door3/tube_3_%d'%(i) for i in [1,2,3]] |
|---|
| 141 | doorpos = knownPositions[[0,1,2,3,5,6,7,8]] |
|---|
| 142 | doorfunc = funcForm[[0,1,2,3,5,6,7,8]] |
|---|
| 143 | calibrationTable, peakTable = tube.calibrate(CalibInstWS, CalibratedComponent, doorpos, |
|---|
| 144 | doorfunc, |
|---|
| 145 | outputPeak = True, |
|---|
| 146 | margin = 30) |
|---|
| 147 | ApplyCalibration( Workspace=CalibInstWS, PositionTable=calibrationTable) |
|---|
| 148 | #################################### |
|---|
| 149 | # Pause and see the instrument check |
|---|
| 150 | #################################### |
|---|
| 151 | |
|---|
| 152 | |
|---|
| 153 | # calibrating others inside door3 |
|---|
| 154 | # 5_8, 5_7, 5_6, 5_5, 5_4, 5_3, 5_2, 5_1, 4_8, 4_7, 4_6, 4_5, 4_4, 4_3, 4_2, 4_1, 3_8, 3_7, 3_6, 3_5, 3_4 |
|---|
| 155 | part_3 = ['MERLIN/door3/tube_3_%d'%(i) for i in [4,5,6]] |
|---|
| 156 | part_4 = ['MERLIN/door3/tube_4_%d'%(i) for i in range(1,9)] |
|---|
| 157 | part_5 = ['MERLIN/door3/tube_5_%d'%(i) for i in range(1,9)] |
|---|
| 158 | CalibratedComponent = part_3 + part_4 + part_5 |
|---|
| 159 | doorpos = knownPositions |
|---|
| 160 | doorfunc = funcForm |
|---|
| 161 | calibrationTable, peakTable = tube.calibrate(CalibInstWS, CalibratedComponent, doorpos, |
|---|
| 162 | doorfunc, |
|---|
| 163 | outputPeak = True, |
|---|
| 164 | margin = 30) |
|---|
| 165 | ApplyCalibration( Workspace=CalibInstWS, PositionTable=calibrationTable) |
|---|
| 166 | #################################### |
|---|
| 167 | # Pause and see the instrument check |
|---|
| 168 | #################################### |
|---|
| 169 | |
|---|