Skip to content

Commit

Permalink
Refs #9097 - Print only one "detectors missing" warning per call.
Browse files Browse the repository at this point in the history
Also, only print the number of detectors that were missing rather than the
indices of each and every histogram.
  • Loading branch information
PeterParker committed Mar 7, 2014
1 parent 2db8f32 commit 66979da
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
13 changes: 10 additions & 3 deletions Code/Mantid/scripts/Calibration/tube_calib.py
Expand Up @@ -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."
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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."
Expand Down Expand Up @@ -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
Expand Down
13 changes: 5 additions & 8 deletions Code/Mantid/scripts/Calibration/tube_spec.py
Expand Up @@ -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()

Expand All @@ -324,37 +325,33 @@ 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):
startDet = firstDet - numDet + 1
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):
Expand Down

0 comments on commit 66979da

Please sign in to comment.