コード例 #1
0
    def reduceSpicePDData(self,
                          exp,
                          scan,
                          unit,
                          xmin,
                          xmax,
                          binsize,
                          wavelength=None,
                          excludeddetlist=None,
                          scalefactor=None):
        """ Reduce SPICE powder diffraction data from MDEventWorkspaces
        Return - Boolean as reduction is successful or not
        """
        # Get reduction manager
        try:
            ws_manager = self._myWorkspaceDict[(int(exp), int(scan))]
        except KeyError:
            raise NotImplementedError(
                "SPICE data for Exp %d Scan %d has not been loaded." %
                (int(exp), int(scan)))

        datamdws = ws_manager.datamdws
        monitormdws = ws_manager.monitormdws

        # binning from MD to single spectrum ws
        # set up binning parameters
        if xmin is None or xmax is None:
            binpar = "%.7f" % (binsize)
        else:
            binpar = "%.7f, %.7f, %.7f" % (xmin, binsize, xmax)

        # scale-factor
        if scalefactor is None:
            scalefactor = 1.
        else:
            scalefactor = float(scalefactor)
            print "[DB] Scale factor is %f." % (scalefactor)

        # Excluded detectors
        if excludeddetlist is None:
            excludeddetlist = []
        else:
            print "[DB] Excluded detectors: %s"%(excludeddetlist), "Convert to numpy array", \
                numpy.array(excludeddetlist)

        basewsname = datamdws.name().split("_DataMD")[0]
        outwsname = basewsname + "_Reduced"
        api.ConvertCWPDMDToSpectra(
            InputWorkspace=datamdws,
            InputMonitorWorkspace=monitormdws,
            OutputWorkspace=outwsname,
            BinningParams=binpar,
            UnitOutput=unit,
            NeutronWaveLength=wavelength,
            ExcludedDetectorIDs=numpy.array(excludeddetlist),
            ScaleFactor=scalefactor)

        print "[DB] Reduction is finished.  Data is in workspace %s. " % (
            outwsname)

        # Set up class variable for min/max and
        outws = AnalysisDataService.retrieve(outwsname)
        if outws is None:
            raise NotImplementedError(
                "Failed to bin the MDEventWorkspaces to MatrixWorkspace.")

        # Manager:
        if self._myWorkspaceDict.has_key((exp, scan)) is False:
            raise NotImplementedError(
                'Exp %d Scan %d has not been initialized.  ' % (exp, scan))
        # wsmanager = PDRManager(exp, scan)
        ws_manager = self._myWorkspaceDict[(exp, scan)]
        ws_manager.setup(datamdws, monitormdws, outws, unit, binsize)
        ws_manager.setWavelength(wavelength)

        # self._myWorkspaceDict[(exp, scan)] = wsmanager

        return True
コード例 #2
0
    def mergeReduceSpiceData(self, expno, scannolist, unit, xmin, xmax,
                             binsize):
        """ Merge and reduce SPICE data files
        Arguements:
         - expscanfilelist: list of 3 tuples: expnumber, scannumber and file name
        """
        # Collect data MD workspaces and monitor MD workspaces
        datamdwslist = []
        monitormdwslist = []
        self._lastWkspToMerge = []

        print "[Checkpoint 0] Scans = ", str(scannolist)
        for scanno in sorted(scannolist):
            try:
                wsmanager = self.getWorkspace(expno, scanno, True)
                datamdwslist.append(wsmanager.datamdws)
                monitormdwslist.append(wsmanager.monitormdws)
                self._lastWkspToMerge.append(wsmanager)
            except KeyError as ne:
                print '[Error] Unable to retrieve MDWorkspaces for Exp %d Scan %d due to %s.' % (
                    expno, scanno, str(ne))
                scannolist.remove(scanno)
        # ENDFOR

        print "[Checkpoing 1] Scans = ", str(scannolist)

        # Merge and binning
        if len(datamdwslist) > 1:
            mg_datamdws = datamdwslist[0] + datamdwslist[1]
            mg_monitormdws = monitormdwslist[0] + monitormdwslist[1]
        else:
            mg_datamdws = datamdwslist[0]
            mg_monitormdws = monitormdwslist[0]
        for iw in xrange(2, len(datamdwslist)):
            mg_datamdws += datamdwslist[iw]
            mg_monitormdws += monitormdwslist[iw]

        # Set up binning parameters
        if xmin is None or xmax is None:
            binpar = "%.7f" % (binsize)
        else:
            binpar = "%.7f, %.7f, %.7f" % (xmin, binsize, xmax)

        # set up output workspace's name
        scannolist = sorted(scannolist)
        outwsname = "Merged_Exp%d_Scan%s_%s" % (expno, scannolist[0],
                                                scannolist[-1])

        # Merge
        wavelength = self.getWavelength(expno, scannolist[0])
        api.ConvertCWPDMDToSpectra(InputWorkspace=mg_datamdws,
                                   InputMonitorWorkspace=mg_monitormdws,
                                   OutputWorkspace=outwsname,
                                   BinningParams=binpar,
                                   UnitOutput=unit,
                                   NeutronWaveLength=wavelength)
        moutws = AnalysisDataService.retrieve(outwsname)
        if moutws is None:
            raise NotImplementedError("Merge failed.")

        key = (expno, str(scannolist))
        self._myMergedWSDict[key] = moutws

        return key