def CalibrateWish( run_per_panel_list): ''' :param run_per_panel_list: is a list of tuples with the run number and the associated panel run_per_panel_list = [ (17706, 'panel01'), (17705, 'panel02'), (17701, 'panel03'), (17702, 'panel04'), (17695, 'panel05')] ''' # == Set parameters for calibration == previousDefaultInstrument = config['default.instrument'] config['default.instrument']="WISH" # definition of the parameters static for the calibration lower_tube = numpy.array([-0.41,-0.31,-0.21,-0.11,-0.02, 0.09, 0.18, 0.28, 0.39 ]) upper_tube = numpy.array(lower_tube+0.003) funcForm = 9*[1] # 9 gaussian peaks margin = 15 low_range = range(0,76) high_range = range(76,152) kwargs = {'margin':margin} # it will copy all the data from the runs to have a single instrument with the calibrated data. whole_instrument = LoadRaw(str(run_per_panel_list[0][0])) whole_instrument = Integration(whole_instrument) for (run_number, panel_name) in run_per_panel_list: panel_name = str(panel_name) run_number = str(run_number) # load your data and integrate it ws = LoadRaw(run_number, OutputWorkspace=panel_name) ws = Integration(ws, 1, 20000, OutputWorkspace=panel_name) # use the TubeSpec object to be able to copy the data to the whole_instrument tube_set = TubeSpec(ws) tube_set.setTubeSpecByString(panel_name) # update kwargs argument before calling calibrate kwargs['rangeList'] = low_range # calibrate only the lower tubes calibrationTable = tube.calibrate(ws, tube_set, lower_tube, funcForm, **kwargs) # update kwargs kwargs['calibTable'] = calibrationTable # append calib to calibrationtable kwargs['rangeList'] = high_range # calibrate only the upper tubes calibrationTable = tube.calibrate(ws, tube_set, upper_tube, funcForm, **kwargs) kwargs['calibTable'] = calibrationTable ApplyCalibration(ws, calibrationTable) # copy data from the current panel to the whole_instrument for i in range(tube_set.getNumTubes()): for spec_num in tube_set.getTube(i): whole_instrument.setY(spec_num,ws.dataY(spec_num)) # calibrate the whole_instrument with the last calibrated panel which has the calibration accumulation # of all the others CopyInstrumentParameters(run_per_panel_list[-1][1],whole_instrument) config['default.instrument'] = previousDefaultInstrument
def CalibrateWish(run_per_panel_list): ''' :param run_per_panel_list: is a list of tuples with the run number and the associated panel run_per_panel_list = [ (17706, 'panel01'), (17705, 'panel02'), (17701, 'panel03'), (17702, 'panel04'), (17695, 'panel05')] ''' # == Set parameters for calibration == previousDefaultInstrument = config['default.instrument'] config['default.instrument']="WISH" # definition of the parameters static for the calibration lower_tube = numpy.array([-0.41,-0.31,-0.21,-0.11,-0.02, 0.09, 0.18, 0.28, 0.39 ]) upper_tube = numpy.array(lower_tube+0.003) funcForm = 9*[1] # 9 gaussian peaks margin = 15 low_range = range(0,76) high_range = range(76,152) kwargs = {'margin':margin} # it will copy all the data from the runs to have a single instrument with the calibrated data. whole_instrument = LoadRaw(str(run_per_panel_list[0][0])) whole_instrument = Integration(whole_instrument) for (run_number, panel_name) in run_per_panel_list: panel_name = str(panel_name) run_number = str(run_number) # load your data and integrate it ws = LoadRaw(run_number, OutputWorkspace=panel_name) ws = Integration(ws, 1, 20000, OutputWorkspace=panel_name) # use the TubeSpec object to be able to copy the data to the whole_instrument tube_set = TubeSpec(ws) tube_set.setTubeSpecByString(panel_name) # update kwargs argument before calling calibrate kwargs['rangeList'] = low_range # calibrate only the lower tubes calibrationTable = tube.calibrate(ws, tube_set, lower_tube, funcForm, **kwargs) # update kwargs kwargs['calibTable'] = calibrationTable # append calib to calibrationtable kwargs['rangeList'] = high_range # calibrate only the upper tubes calibrationTable = tube.calibrate(ws, tube_set, upper_tube, funcForm, **kwargs) kwargs['calibTable'] = calibrationTable ApplyCalibration(ws, calibrationTable) # copy data from the current panel to the whole_instrument for i in range(tube_set.getNumTubes()): for spec_num in tube_set.getTube(i): whole_instrument.setY(spec_num,ws.dataY(spec_num)) # calibrate the whole_instrument with the last calibrated panel which has the calibration accumulation # of all the others CopyInstrumentParameters(run_per_panel_list[-1][1],whole_instrument) config['default.instrument'] = previousDefaultInstrument
def getCalibrationFromPeakFile(ws, calibTable, iTube, PeakFile): """ Get the results the calibration and put them in the calibration table provided. @param ws: Integrated Workspace with tubes to be calibrated @param calibTable: Calibration table into which the calibration results are placed @param iTube: The ideal tube @param PeakFile: File of peaks for calibration """ # Get Ideal Tube ideal_tube = iTube.getArray() # Read Peak File peak_array = read_peak_file(PeakFile) n_tubes = len(peak_array) print("Number of tubes read from file =", n_tubes) for i in range(n_tubes): # Deal with (i+1)st tube got from file tube_name = peak_array[i][0] # e.g. 'MERLIN/door3/tube_3_1' tube = TubeSpec(ws) tube.setTubeSpecByString(tube_name) actual_tube = peak_array[i][1] # e.g. [2.0, 512.5, 1022.0] wht, _ = tube.getTube(0) print("Calibrating tube", i + 1, "of", n_tubes, tube_name) if len(wht) < 1: print( "Unable to get any workspace indices for this tube. Calibration abandoned." ) return det_id_list, det_pos_list = getCalibratedPixelPositions( ws, actual_tube, ideal_tube, wht) if len(det_id_list) == len(wht): # We have corrected positions for j in range(len(wht)): next_row = { 'Detector ID': det_id_list[j], 'Detector Position': det_pos_list[j] } calibTable.addRow(next_row) if n_tubes == 0: return # Delete temporary workspaces for getting new detector positions DeleteWorkspace('PolyFittingWorkspace') DeleteWorkspace('QF_NormalisedCovarianceMatrix') DeleteWorkspace('QF_Parameters') DeleteWorkspace('QF_Workspace')
def getCalibrationFromPeakFile ( ws, calibTable, iTube, PeakFile ): """ Get the results the calibration and put them in the calibration table provided. @param ws: Integrated Workspace with tubes to be calibrated @param calibTable: Calibration table into which the calibration results are placed @param iTube: The ideal tube @param PeakFile: File of peaks for calibtation """ # Get Ideal Tube idealTube = iTube.getArray() # Read Peak File PeakArray = readPeakFile( PeakFile ) nTubes = len(PeakArray) print "Number of tubes read from file =",nTubes for i in range(nTubes): # Deal with (i+1)st tube got from file TubeName = PeakArray[i][0] # e.g. 'MERLIN/door3/tube_3_1' tube = TubeSpec(ws) tube.setTubeSpecByString(TubeName) actualTube = PeakArray[i][1] # e.g. [2.0, 512.5, 1022.0] wht, _ = tube.getTube(0) print "Calibrating tube", i+1 ,"of", nTubes, TubeName #, " length", tubeSet.getTubeLength(i) if len(wht) < 1 : print "Unable to get any workspace indices for this tube. Calibration abandoned." return detIDList, detPosList = getCalibratedPixelPositions( ws, actualTube, idealTube, wht) #print len(wht) if len(detIDList) == len(wht): # We have corrected positions for j in range(len(wht)): nextRow = {'Detector ID': detIDList[j], 'Detector Position': detPosList[j] } calibTable.addRow ( nextRow ) if nTubes == 0: return # Delete temporary workspaces for getting new detector positions DeleteWorkspace('PolyFittingWorkspace') DeleteWorkspace('QF_NormalisedCovarianceMatrix') DeleteWorkspace('QF_Parameters') DeleteWorkspace('QF_Workspace')