def _normaliseToFlux(self, detWS, monWS): """Normalise ws to monitor counts or counting time.""" method = self.getProperty(Prop.FLUX_NORM_METHOD).value if method == FluxNormMethod.MONITOR: if monWS is None: raise RuntimeError( 'Cannot normalise to monitor data: no monitors in input data.' ) normalisedWSName = self._names.withSuffix('normalised_to_monitor') monIndex = normalisationMonitorWorkspaceIndex(monWS) monXs = monWS.readX(0) minX = monXs[0] maxX = monXs[-1] normalisedWS = NormaliseToMonitor( InputWorkspace=detWS, OutputWorkspace=normalisedWSName, MonitorWorkspace=monWS, MonitorWorkspaceIndex=monIndex, IntegrationRangeMin=minX, IntegrationRangeMax=maxX, EnableLogging=self._subalgLogging) self._cleanup.cleanup(detWS) return normalisedWS elif method == FluxNormMethod.TIME: t = detWS.run().getProperty('time').value normalisedWSName = self._names.withSuffix('normalised_to_time') scaledWS = Scale(InputWorkspace=detWS, OutputWorkspace=normalisedWSName, Factor=1.0 / t, EnableLogging=self._subalgLogging) self._cleanup.cleanup(detWS) return scaledWS return detWS
def _normalizeToMonitor(ws, monWS, monIndex, integrationBegin, integrationEnd, wsNames, wsCleanup, algorithmLogging): """Normalize to monitor counts.""" normalizedWSName = wsNames.withSuffix('normalized_to_monitor') normalizationFactorWsName = wsNames.withSuffix('normalization_factor_monitor') normalizedWS, normalizationFactorWS = NormaliseToMonitor(InputWorkspace=ws, OutputWorkspace=normalizedWSName, MonitorWorkspace=monWS, MonitorWorkspaceIndex=monIndex, IntegrationRangeMin=integrationBegin, IntegrationRangeMax=integrationEnd, NormFactorWS=normalizationFactorWsName, EnableLogging=algorithmLogging) wsCleanup.cleanup(normalizationFactorWS) return normalizedWS
def load_data_and_normalise(filename, spectrumMin=1, spectrumMax=19461, outputWorkspace="sample"): """ Function to load in raw data, crop and normalise :param filename: file path to .raw :param spectrumMin: min spec to load (default incl. all monitors) :param spectrumMax: max spec to load (default includes only bank 1) :param outputWorkspace: name of output workspace (can be specified to stop workspaces being overwritten) :return: normalised and cropped data with xunit wavelength (excl. monitors) """ sample, mon = LoadRaw(Filename=filename, SpectrumMin=spectrumMin, SpectrumMax=spectrumMax, LoadMonitors="Separate", OutputWorkspace=outputWorkspace) for ws in [sample, mon]: CropWorkspace(InputWorkspace=ws, OutputWorkspace=ws, XMin=6000, XMax=99000) NormaliseByCurrent(InputWorkspace=ws, OutputWorkspace=ws) ConvertUnits(InputWorkspace=ws, OutputWorkspace=ws, Target='Wavelength') NormaliseToMonitor(InputWorkspace=sample, OutputWorkspace=sample, MonitorWorkspaceIndex=3, MonitorWorkspace=mon) ReplaceSpecialValues(InputWorkspace=sample, OutputWorkspace=sample, NaNValue=0, InfinityValue=0) CropWorkspace(InputWorkspace=sample, OutputWorkspace=sample, XMin=0.8, XMax=9.3) return sample