def PyExec(self): ''' Averages the bin widths at X. ''' inputWs = self.getProperty(self._PROP_INPUT_WS).value x = self.getProperty(self._PROP_X_VALUE).value roundingMode = self.getProperty( roundinghelper.PROP_NAME_ROUNDING_MODE).value n = inputWs.getNumberHistograms() widths = numpy.empty(n) for wsIndex in range(n): xs = inputWs.readX(wsIndex) lowerBound = xs[0] upperBound = xs[-1] if lowerBound > upperBound: lowerBound, upperBound = upperBound, lowerBound if x <= lowerBound or x > upperBound: raise RuntimeError( self._PROP_X_VALUE + ' = {0} out of range for workspace index {1}'.format( x, wsIndex)) binIndex = inputWs.binIndexOf(x, wsIndex) dx = xs[binIndex + 1] - xs[binIndex] widths[wsIndex] = dx binWidth = numpy.mean(widths) binWidth = roundinghelper.round(binWidth, roundingMode) self.setProperty(self._PROP_BIN_WIDTH, numpy.abs(binWidth))
def PyExec(self): ''' Averages the bin widths at X. ''' inputWs = self.getProperty(self._PROP_INPUT_WS).value x = self.getProperty(self._PROP_X_VALUE).value roundingMode = self.getProperty( roundinghelper.PROP_NAME_ROUNDING_MODE).value n = inputWs.getNumberHistograms() widths = numpy.empty(n) for wsIndex in range(n): xs = inputWs.readX(wsIndex) lowerBound = xs[0] upperBound = xs[-1] if lowerBound > upperBound: lowerBound, upperBound = upperBound, lowerBound if x <= lowerBound or x > upperBound: raise RuntimeError( self._PROP_X_VALUE + ' = {0} out of range for workspace index {1}' .format(x, wsIndex)) binIndex = inputWs.binIndexOf(x, wsIndex) dx = xs[binIndex + 1] - xs[binIndex] widths[wsIndex] = dx binWidth = numpy.mean(widths) binWidth = roundinghelper.round(binWidth, roundingMode) self.setProperty(self._PROP_BIN_WIDTH, numpy.abs(binWidth))
def PyExec(self): ''' Averages the median bin widths of the input workspace. ''' inputWs = self.getProperty(self._PROP_INPUT_WS).value roundingMode = self.getProperty( roundinghelper.PROP_NAME_ROUNDING_MODE).value xs = inputWs.extractX() dxs = numpy.diff(xs) medians = numpy.median(dxs, axis=1) binWidth = numpy.mean(medians) binWidth = roundinghelper.round(binWidth, roundingMode) self.setProperty(self._PROP_BIN_WIDTH, numpy.abs(binWidth))
def _sOfQW(self, mainWS, wsNames, wsCleanup, report, subalgLogging): """Run the SofQWNormalisedPolygon algorithm.""" sOfQWWSName = wsNames.withSuffix('sofqw') if self.getProperty(common.PROP_BINNING_PARAMS_Q).isDefault: qMin, qMax = _minMaxQ(mainWS) dq = _deltaQ(mainWS) dq = 10 * roundinghelper.round(dq, roundinghelper.ROUNDING_TEN_TO_INT) params = [qMin, dq, qMax] report.notice('Binned momentum transfer axis to bin width {0}.'.format(dq)) else: params = self.getProperty(common.PROP_BINNING_PARAMS_Q).value Ei = mainWS.run().getLogData('Ei').value sOfQWWS = SofQWNormalisedPolygon(InputWorkspace=mainWS, OutputWorkspace=sOfQWWSName, QAxisBinning=params, EMode='Direct', EFixed=Ei, ReplaceNaNs=False, EnableLogging=subalgLogging) wsCleanup.cleanup(mainWS) return sOfQWWS