1 | # |
---|
2 | # TUBE CALIBRATION DEMONSTRATION PROGRAM FOR WISH |
---|
3 | # |
---|
4 | # Here we run the calibration of WISH panel03 using a simple CalibrateWish function. |
---|
5 | # |
---|
6 | import numpy |
---|
7 | import tube |
---|
8 | from mantid.simpleapi import * |
---|
9 | |
---|
10 | from tube_calib_fit_params import TubeCalibFitParams |
---|
11 | |
---|
12 | def CalibrateWish( RunNumber, PanelNumber, fitpolyn=2): |
---|
13 | ''' |
---|
14 | :param RunNumber: is the run number of the calibration. |
---|
15 | :param PanelNumber: is a string of two-digit number of the panel being calibrated |
---|
16 | ''' |
---|
17 | # == Set parameters for calibration == |
---|
18 | previousDefaultInstrument = config['default.instrument'] |
---|
19 | config['default.instrument']="WISH" |
---|
20 | filename = str(RunNumber) |
---|
21 | CalibratedComponent = 'WISH/panel'+PanelNumber |
---|
22 | |
---|
23 | # Get calibration raw file and integrate it |
---|
24 | print "Loading",filename |
---|
25 | rawCalibInstWS = Load(filename) #'raw' in 'rawCalibInstWS' means unintegrated. |
---|
26 | CalibInstWS = Integration( rawCalibInstWS, RangeLower=1, RangeUpper=20000 ) |
---|
27 | DeleteWorkspace(rawCalibInstWS) |
---|
28 | print "Created workspace (CalibInstWS) with integrated data from run and instrument to calibrate" |
---|
29 | |
---|
30 | # Give y-positions of slit points (gotten for converting first tube's slit point to Y) |
---|
31 | |
---|
32 | # WISH instrument has a particularity. It is composed by a group of upper tubes and lower tubes, |
---|
33 | # they are disposed 3 milimiters in difference one among the other |
---|
34 | lower_tube = numpy.array([-0.41,-0.31,-0.21,-0.11,-0.02, 0.09, 0.18, 0.28, 0.39 ]) |
---|
35 | upper_tube = numpy.array(lower_tube+0.003) |
---|
36 | funcForm = 9*[1] # 9 gaussian peaks |
---|
37 | margin = 15 |
---|
38 | print "Created objects needed for calibration." |
---|
39 | |
---|
40 | # Get the calibration and put it into the calibration table |
---|
41 | |
---|
42 | #calibrate the lower tubes |
---|
43 | calibrationTable, peakTable = tube.calibrate(CalibInstWS, CalibratedComponent, lower_tube, funcForm, |
---|
44 | rangeList = range(0,76), outputPeak=True, margin=margin, fitPolyn=fitpolyn) |
---|
45 | |
---|
46 | #calibrate the upper tubes |
---|
47 | calibrationTable, peakTable = tube.calibrate(CalibInstWS, CalibratedComponent, upper_tube, funcForm, |
---|
48 | rangeList = range(76,152), margin = margin, |
---|
49 | calibTable=calibrationTable, #give the calibration table to append data |
---|
50 | outputPeak = peakTable, #give peak table to append data |
---|
51 | fitPolyn=fitpolyn ) |
---|
52 | |
---|
53 | print "Got calibration (new positions of detectors)" |
---|
54 | |
---|
55 | #Apply the calibration |
---|
56 | ApplyCalibration( Workspace=CalibInstWS, PositionTable=calibrationTable) |
---|
57 | print "Applied calibration" |
---|
58 | |
---|
59 | # == Save workspace == |
---|
60 | #uncomment these lines to save the workspace |
---|
61 | #nexusName = "TubeCalibDemoWish"+PanelNumber+"Result.nxs" |
---|
62 | #SaveNexusProcessed( CalibInstWS, 'TubeCalibDemoWishResult.nxs',"Result of Running TubeCalibWishMerlin_Simple.py") |
---|
63 | #print "saved calibrated workspace (CalibInstWS) into Nexus file",nexusName |
---|
64 | |
---|
65 | # == Reset dafault instrument == |
---|
66 | config['default.instrument'] = previousDefaultInstrument |
---|
67 | |
---|
68 | # ==== End of CalibrateWish() ==== |
---|
69 | if __name__ == "__main__": |
---|
70 | # this file is found on cycle_11_1 |
---|
71 | RunNumber = 17701 |
---|
72 | PanelNumber = '03' |
---|
73 | fitPolyn = 2 # change these values to 1, 2 and 3 |
---|
74 | CalibrateWish(RunNumber, PanelNumber, fitPolyn) |
---|