parameters: (self, mainWS, maskWS)
return_statement: return beamStopDiagnosticsWS
docstring: Diagnose beam stop and return a mask workspace.
docstring_summary: Diagnose beam stop and return a mask workspace.
docstring_tokens: Diagnose beam stop and return a mask workspace .
function: def _beamStopDiagnostics(self, mainWS, maskWS):
          """Diagnose beam stop and return a mask workspace."""
          import operator
  
          def thresholdIndex(ws, maskWS, begin, end, threshold):
              """Return an index where the threshold is crossed."""
              step = -1 if begin < end else 1
              comp = operator.ge if begin < end else operator.le
              Ys = numpy.empty(abs(end - begin))
              i = end + step
              indexShift = -min(begin, end + 1)
              while comp(i, begin):
                  index = i + indexShift
                  if maskWS.readY(i) == 0:
                      Ys[index] = numpy.sum(ws.readY(i))
                  else:
                      Ys[index] = 0.
                  i += step
              maxIndex = int(numpy.argmax(Ys))
              thresholdVal = threshold * Ys[maxIndex]
              i = maxIndex - indexShift + step
              while comp(i, begin):
                  index = i + indexShift
                  if Ys[index] < thresholdVal:
                      return i
                  i += step
              return i
          beamStopDiagnosticsWSName = self._names.withSuffix('beam_stop_diagnostics')
          beamStopDiagnosticsWS = _createMaskWS(mainWS, beamStopDiagnosticsWSName, self._subalgLogging)
          threshold = self.getProperty(common.PROP_BEAM_STOP_THRESHOLD).value
          beginIndices, endIndices = _beamStopRanges(mainWS)
          for i in range(len(beginIndices)):
              begin = beginIndices[i]
              end = endIndices[i]
              mid = int((end + begin) / 2)
              lowerIdx = thresholdIndex(mainWS, maskWS, mid, begin, threshold)
              upperIdx = thresholdIndex(mainWS, maskWS, mid, end, threshold)
              if lowerIdx != upperIdx:
                  for j in range(upperIdx - lowerIdx + 1):
                      ys = beamStopDiagnosticsWS.dataY(lowerIdx + j)
                      ys[0] = 1.0
          return beamStopDiagnosticsWS
function_tokens: def _beamStopDiagnostics ( self , mainWS , maskWS ) : import operator def thresholdIndex ( ws , maskWS , begin , end , threshold ) : """Return an index where the threshold is crossed.""" step = - 1 if begin < end else 1 comp = operator . ge if begin < end else operator . le Ys = numpy . empty ( abs ( end - begin ) ) i = end + step indexShift = - min ( begin , end + 1 ) while comp ( i , begin ) : index = i + indexShift if maskWS . readY ( i ) == 0 : Ys [ index ] = numpy . sum ( ws . readY ( i ) ) else : Ys [ index ] = 0. i += step maxIndex = int ( numpy . argmax ( Ys ) ) thresholdVal = threshold * Ys [ maxIndex ] i = maxIndex - indexShift + step while comp ( i , begin ) : index = i + indexShift if Ys [ index ] < thresholdVal : return i i += step return i beamStopDiagnosticsWSName = self . _names . withSuffix ( 'beam_stop_diagnostics' ) beamStopDiagnosticsWS = _createMaskWS ( mainWS , beamStopDiagnosticsWSName , self . _subalgLogging ) threshold = self . getProperty ( common . PROP_BEAM_STOP_THRESHOLD ) . value beginIndices , endIndices = _beamStopRanges ( mainWS ) for i in range ( len ( beginIndices ) ) : begin = beginIndices [ i ] end = endIndices [ i ] mid = int ( ( end + begin ) / 2 ) lowerIdx = thresholdIndex ( mainWS , maskWS , mid , begin , threshold ) upperIdx = thresholdIndex ( mainWS , maskWS , mid , end , threshold ) if lowerIdx != upperIdx : for j in range ( upperIdx - lowerIdx + 1 ) : ys = beamStopDiagnosticsWS . dataY ( lowerIdx + j ) ys [ 0 ] = 1.0 return beamStopDiagnosticsWS