Exemplo n.º 1
0
    def _can_merge(self, wsnames):
        """
        Checks whether given workspaces can be merged
        """
        # mandatory properties must be identical
        result = api.CompareSampleLogs(wsnames, self.mandatory_properties, 0.01)
        if len(result) > 0:
            raise RuntimeError("Sample logs " + result + " do not match!")

        # timing (x-axis binning) must match
        # is it possible to use WorkspaceHelpers::matchingBins from python?
        self.timingsMatch(wsnames)

        # Check sample logs for must have properties
        for wsname in wsnames:
            wks = api.AnalysisDataService.retrieve(wsname)
            run = wks.getRun()
            for prop in self.must_have_properties:
                if not run.hasProperty(prop):
                    message = "Error: Workspace " + wsname + " does not have property " + prop +\
                        ". Cannot merge."
                    self.log().error(message)
                    raise RuntimeError(message)

        # warnig if optional properties are not identical must be given
        result = api.CompareSampleLogs(wsnames, self.optional_properties, 0.01)
        if len(result) > 0:
            self.log().warning("Sample logs " + result + " do not match!")

        return True
Exemplo n.º 2
0
    def PyExec(self):
        # Input
        vana_input = self.getProperty("VanadiumWorkspaces").value
        bg_input = self.getProperty("BackgroundWorkspaces").value
        vana_workspaces = self._expand_groups(vana_input)
        bg_workspaces = self._expand_groups(bg_input)
        self.log().notice("Input Vanadium workspaces: " + str(vana_workspaces))
        self.log().notice("Input Background workspaces: " + str(bg_workspaces))

        # number of vanadium and background workspaces must match
        if len(vana_workspaces) != len(bg_workspaces):
            raise RuntimeError("Number of Vanadium and background workspaces doe not match!")

        # compare optional sample logs, throw warnings
        result = api.CompareSampleLogs(vana_workspaces+bg_workspaces, self.properties_to_compare, 5e-3)
        if result:
            self.log().warning("Following properties do not match: " + result)

        # split input workspaces to groups SF/NSF and detector angles
        deterota = self._get_detector_positions(vana_workspaces)
        sfvana, nsfvana = self._sort_workspaces(vana_workspaces, deterota)
        sfbg, nsfbg = self._sort_workspaces(bg_workspaces, deterota)

        # subract background
        sfv = self._subtract_background(sfvana, sfbg, deterota)
        nsfv = self._subtract_background(nsfvana, nsfbg, deterota)
        total = self._sum_signal(sfv, nsfv, deterota)

        # compute vmean
        _mean_ws_ = api.Mean(",".join(list(total.values())))     # Mean takes string
        self.toremove.append(_mean_ws_.name())
        num =  self._get_notmasked_detectors_number(_mean_ws_)
        if num == 0:
            self.cleanup(self.toremove)
            raise RuntimeError("All detectors are masked! Cannot compute coefficients.")
        _vana_mean_ = api.SumSpectra(_mean_ws_)/num
        self.toremove.append(_vana_mean_.name())

        # compute coefficients k_i = (VSF_i + VNSF_i)/Vmean
        outws_name = self.getPropertyValue("OutputWorkspace")
        # for only one detector position only one workspace will be created
        if len(deterota) == 1:
            api.Divide(list(total.values())[0], _vana_mean_, OutputWorkspace=outws_name)
        else:
            # for many detector positions group of workspaces will be created
            results = []
            for angle in deterota:
                wsname = outws_name + '_2theta' + str(angle)
                api.Divide(total[angle], _vana_mean_, OutputWorkspace=wsname)
                results.append(wsname)

            api.GroupWorkspaces(results, OutputWorkspace=outws_name)

        self.cleanup(self.toremove)
        outws = api.AnalysisDataService.retrieve(outws_name)
        self.setProperty("OutputWorkspace", outws)

        return
Exemplo n.º 3
0
    def _can_merge(self, wsnames):
        """
        Checks whether given workspaces can be merged
        """
        # mandatory properties must be identical
        result = api.CompareSampleLogs(wsnames, self.mandatory_properties[1:],
                                       0.01)
        if len(result) > 0:
            raise RuntimeError("Sample logs " + result + " do not match!")

        # chopper_speed can vary about 10 and for some reason it is string (will be corrected in the future)
        cstable = api.CreateLogPropertyTable(wsnames, 'chopper_speed')
        chopper_speeds = [int(val) for val in cstable.column(0)]
        if max(chopper_speeds) - min(
                chopper_speeds) > 10:  # not within tolerance of 10 rpm
            self.log().warning(
                "Chopper speeds do not match! Chopper speeds are: " +
                " ,".join([str(val) for val in chopper_speeds]))
        api.DeleteWorkspace(cstable)

        # timing (x-axis binning) must match
        # is it possible to use WorkspaceHelpers::matchingBins from python?
        self.timingsMatch(wsnames)

        # Check sample logs for must have properties
        for wsname in wsnames:
            wks = api.AnalysisDataService.retrieve(wsname)
            run = wks.getRun()
            for prop in self.must_have_properties:
                if not run.hasProperty(prop):
                    message = "Error: Workspace " + wsname + " does not have property " + prop +\
                        ". Cannot merge."
                    self.log().error(message)
                    raise RuntimeError(message)

        # warnig if optional properties are not identical must be given
        result = api.CompareSampleLogs(wsnames, self.optional_properties, 0.01)
        if len(result) > 0:
            self.log().warning("Sample logs " + result + " do not match!")

        return True
    def validateInputs(self):
        issues = dict()

        choice_tof = self.getProperty("ChoiceElasticTof").value
        vanaws_name = self.getPropertyValue("VanadiumWorkspace")
        inws = self.getProperty("InputWorkspace").value

        # instrument must be set, this can be moved to validator
        # after validators will work for WorkspaceGroups
        if not inws.getInstrument().getName():
            issues['InputWorkspace'] = "Instrument must be set."

        # X units must be TOF
        xunit = inws.getAxis(0).getUnit().unitID()
        if xunit != 'TOF':
            issues['InputWorkspace'] = "X axis units must be TOF. "

        # input workspace must have required sample logs
        err = api.CheckForSampleLogs(inws, ",".join(self.logs_to_check))
        if err:
            issues['InputWorkspace'] = err

        # if Vanadium will be used to find EPP, workspace must exist and have required sample logs
        if choice_tof == 'FitVanadium':
            if not api.AnalysisDataService.doesExist(vanaws_name):
                issues[
                    'VanadiumWorkspace'] = "Valid Vanadium Workspace must be given for choosen ElasticTof option."

            else:
                vanaws = api.AnalysisDataService.retrieve(vanaws_name)
                xunit = vanaws.getAxis(0).getUnit().unitID()
                if xunit != 'TOF':
                    issues['VanadiumWorkspace'] = "X axis units must be TOF. "
                err = api.CheckForSampleLogs(vanaws,
                                             ",".join(self.logs_to_check))
                if err:
                    issues['VanadiumWorkspace'] = err
                # required sample logs for sample and vanadium must be identical
                else:
                    result = api.CompareSampleLogs(
                        [inws.getName(), vanaws_name], self.logs_to_check,
                        0.01)
                    if len(result) > 0:
                        issues[
                            'VanadiumWorkspace'] = "Sample logs " + result + " must match for Vanadium and sample workspaces."
        # if EPP will be taken from sample logs, it must be > 0
        epp = inws.getRun().getProperty('EPP').value
        if float(epp) <= 0:
            issues['InputWorkspace'] = "EPP must be a positive number."

        return issues
Exemplo n.º 5
0
    def validateInputs(self):
        issues = dict()

        workspaces = {
            "NSFDataWorkspace": None,
            "SFNiCrWorkspace": None,
            "NSFNiCrWorkspace": None,
            "SFBkgrWorkspace": None,
            "NSFBkgrWorkspace": None
        }

        for key in workspaces.keys():
            workspaces[key] = self.getProperty(key).value

        # dimensions must match
        datasf = self.getProperty("SFDataWorkspace").value
        ndims = datasf.getNumDims()
        nhists = datasf.getNumberHistograms()
        nblocks = datasf.blocksize()

        for key in workspaces.keys():
            if workspaces[key].getNumDims() != ndims:
                issues[
                    key] = "Number of dimensions does not match to the data workspace."
            if workspaces[key].getNumberHistograms() != nhists:
                issues[
                    key] = "Number of histograms does not match to the data workspace."
            if workspaces[key].blocksize() != nblocks:
                issues[
                    key] = "Number of blocks does not match to the data workspace."

        # normalizations must match and must be either monitor or duration, polarisations must match
        lognames = "normalized,polarisation,polarisation_comment"
        wslist = list(workspaces.values())
        wslist.append(datasf)
        result = api.CompareSampleLogs(wslist, lognames)
        if len(result) > 0:
            issues[
                'SFDataWorkspace'] = "Cannot apply correction to workspaces with different " + result
        else:
            norm = datasf.getRun().getProperty('normalized').value
            if norm == 'no':
                issues[
                    'SFDataWorkspace'] = "Data must be normalized before correction."

        return issues
Exemplo n.º 6
0
    def _can_correct(self):
        """
        checks whether FR correction is possible with the given list of workspaces
        """
        # list of workspaces must not be empty
        if not self.input_workspaces:
            message = "No workspace names has been specified! Nothing for FR correction."
            self.log().error(message)
            raise RuntimeError(message)

        # check validity of flipper status
        self._flipper_valid()

        # algorithm must warn if some properties_to_compare are different
        result = api.CompareSampleLogs(list(self.input_workspaces.values()), self.properties_to_compare, 5e-3)
        if len(result) > 0:
            self.log().warning("Sample logs " + result + " do not match!")
        return True
Exemplo n.º 7
0
    def validateInputs(self):
        issues = dict()
        # workspaces or groups must exist
        vana_workspaces = self.getProperty("VanadiumWorkspaces").value
        for wsname in vana_workspaces:
            if not api.AnalysisDataService.doesExist(wsname):
                issues["VanadiumWorkspaces"] = "Workspace " + wsname + " does not exist!"
        bg_workspaces = self.getProperty("BackgroundWorkspaces").value
        for wsname in bg_workspaces:
            if not api.AnalysisDataService.doesExist(wsname):
                issues["BackgroundWorkspaces"] = "Workspace " + wsname + " does not exist!"

        workspace_names = self._expand_groups(vana_workspaces)
        workspace_names.extend(self._expand_groups(bg_workspaces))

        # workspaces must have the same normalization
        result = api.CompareSampleLogs(workspace_names, 'normalized', 0.01)
        if len(result) > 0:
            issues["WorkspaceNames"] = "Workspaces must have the same normalization."

        return issues
Exemplo n.º 8
0
    def PyExec(self):
        # Input
        input_list = self.getProperty("WorkspaceNames").value
        self.outws_name = self.getProperty("OutputWorkspace").valueAsStr
        self.xaxis = self.getProperty("HorizontalAxis").value

        self.workspace_names = self._expand_groups(input_list)
        self.log().information("Workspaces to merge: %i" %
                               (len(self.workspace_names)))
        # produce warnings is some optional sample logs do not match
        result = api.CompareSampleLogs(self.workspace_names,
                                       self.properties_to_compare, 1e-2)

        self._merge_workspaces()

        outws = api.AnalysisDataService.retrieve(self.outws_name)
        api.CopyLogs(self.workspace_names[0], outws)
        # remove logs which do not match
        if result:
            api.RemoveLogs(outws, result)

        self.setProperty("OutputWorkspace", outws)
        return
Exemplo n.º 9
0
    def validateInputs(self):
        issues = dict()
        input_list = self.getProperty("WorkspaceNames").value

        for wsname in input_list:
            if not api.AnalysisDataService.doesExist(wsname):
                issues[
                    "WorkspaceNames"] = "Workspace " + wsname + " does not exist"

        workspace_names = self._expand_groups(input_list)
        if len(workspace_names) < 2:
            issues["WorkspaceNames"] = "At least 2 workspaces required."

        ws0 = api.AnalysisDataService.retrieve(workspace_names[0])
        ndims = ws0.getNumDims()
        nhists = ws0.getNumberHistograms()
        nblocks = ws0.blocksize()
        # workspaces must exist and have the same dimensions
        for wsname in workspace_names[1:]:
            wks = api.AnalysisDataService.retrieve(wsname)
            if wks.getNumDims() != ndims:
                issues["WorkspaceNames"] = "Number of dimensions for workspace " + wks.name() + \
                    " does not match to one for " + ws0.name()
            if wks.getNumberHistograms() != nhists:
                issues["WorkspaceNames"] = "Number of histohrams for workspace " + wks.name() + \
                    " does not match to one for " + ws0.name()
            if wks.blocksize() != nblocks:
                issues["WorkspaceNames"] = "Number of blocks for workspace " + wks.name() + \
                    " does not match to one for " + ws0.name()
        # workspaces must have the same wavelength and normalization
        result = api.CompareSampleLogs(workspace_names,
                                       'wavelength,normalized', 0.01)
        if len(result) > 0:
            issues[
                "WorkspaceNames"] = "Cannot merge workspaces with different " + result

        return issues