From 66979da7cffb4e23627182581ce91485d150dff1 Mon Sep 17 00:00:00 2001 From: Peter Parker Date: Fri, 7 Mar 2014 16:28:01 +0000 Subject: [PATCH] Refs #9097 - Print only one "detectors missing" warning per call. Also, only print the number of detectors that were missing rather than the indices of each and every histogram. --- Code/Mantid/scripts/Calibration/tube_calib.py | 13 ++++++++++--- Code/Mantid/scripts/Calibration/tube_spec.py | 13 +++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Code/Mantid/scripts/Calibration/tube_calib.py b/Code/Mantid/scripts/Calibration/tube_calib.py index 20be6bfb8fa5..19e9968c3cab 100644 --- a/Code/Mantid/scripts/Calibration/tube_calib.py +++ b/Code/Mantid/scripts/Calibration/tube_calib.py @@ -492,10 +492,14 @@ def getCalibration( ws, tubeSet, calibTable, fitPar, iTube, peaksTable, if rangeList is None: rangeList = range(nTubes) + all_skipped = set() + for i in rangeList: # Deal with (i+1)st tube specified - wht = tubeSet.getTube(i) + wht, skipped = tubeSet.getTube(i) + all_skipped.update(skipped) + print "Calibrating tube", i+1,"of",nTubes, tubeSet.getTubeName(i) if ( len(wht) < 1 ): print "Unable to get any workspace indices (spectra) for this tube. Tube",tubeSet.getTubeName(i),"not calibrated." @@ -537,6 +541,9 @@ def getCalibration( ws, tubeSet, calibTable, fitPar, iTube, peaksTable, nextRow = {'Detector ID': detIDList[j], 'Detector Position': detPosList[j] } calibTable.addRow ( nextRow ) + if len(all_skipped) > 0: + print "%i histogram(s) were excluded from the calibration since they did not have an assigned detector." % len(all_skipped) + # Delete temporary workspaces used in the calibration for ws_name in ('TubePlot','CalibPoint_NormalisedCovarianceMatrix', 'CalibPoint_NormalisedCovarianceMatrix','CalibPoint_NormalisedCovarianceMatrix', @@ -577,7 +584,7 @@ def getCalibrationFromPeakFile ( ws, calibTable, iTube, PeakFile ): tube.setTubeSpecByString(TubeName) actualTube = PeakArray[i][1] # e.g. [2.0, 512.5, 1022.0] - wht = tube.getTube(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." @@ -623,7 +630,7 @@ def constructIdealTubeFromRealTube( ws, tube, fitPar, funcForm ): elif(nTubes > 1): print "Specification has several tubes. The ideal tube will be based on the first tube",tube.getTubeName(0) - wht = tube.getTube(0) + wht, _ = tube.getTube(0) # print wht # Check tube diff --git a/Code/Mantid/scripts/Calibration/tube_spec.py b/Code/Mantid/scripts/Calibration/tube_spec.py index ba2b5e7a01c0..26eca911bcc6 100644 --- a/Code/Mantid/scripts/Calibration/tube_spec.py +++ b/Code/Mantid/scripts/Calibration/tube_spec.py @@ -313,6 +313,7 @@ def getTubeByString(self, tubeIx): """ firstDet, numDet, step = self.getDetectorInfoFromTube( tubeIx ) wkIds = [] + skipped = [] # print " First dectector", firstDet," Last detector", firstDet+numDet-1, "Number of detectors", numDet # print "Histograms", self.ws.getNumberHistograms() @@ -324,7 +325,7 @@ def getTubeByString(self, tubeIx): if( numDetsPerWkID != 1): print "We have",numDetsPerWkID,"detectors per workspace index. 1 is required." print "cannot obtain range of workspace indices for this tube in this workspace" - return wkIds + return wkIds, skipped # Go and get workspace Indices if(step == -1): @@ -332,29 +333,25 @@ def getTubeByString(self, tubeIx): else: startDet = firstDet if( numDet > 0): - skipped_histograms = [] for i in range (0, self.ws.getNumberHistograms(), numDet): try: deti = self.ws.getDetector(i) except: - skipped_histograms.append(i) + skipped.append(i) continue detID = deti.getID() if (detID >= startDet and detID < startDet+numDet): iPixel = detID - firstDet wkIds = range( i - iPixel, i - iPixel + step*numDet, step) # print "Workspace indices",i-iPixel,"to",i-iPixel+numDet-1 - if len(skipped_histograms) > 0: - print "The following histogram(s) were skipped since they did not " \ - "have an assigned detector:\n" + str(skipped_histograms) #print firstDet, numDet if (numDet > 0): - return wkIds + return wkIds, skipped else: print "specified tube has no detectors." self.numTubes = 0 - return wkIds + return wkIds, skipped def getTube(self, tubeIx):