示例#1
0
    def _get_transmission_workspace(self, trans_ids):
        trans_ws = None
        file_path = None

        file_path, ws_name = getFileAndName(self._get_dark_file())
        alg_load = AlgorithmManager.createUnmanaged("LoadEventNexus")
        alg_load.initialize()
        alg_load.setChild(True)
        alg_load.setProperty("Filename", file_path)
        alg_load.setProperty("OutputWorkspace", ws_name)
        alg_load.execute()
        detector = alg_load.getProperty("OutputWorkspace").value

        trans_name = ws_name + "_monitor"
        alg_load_monitors = AlgorithmManager.createUnmanaged(
            "LoadNexusMonitors")
        alg_load_monitors.initialize()
        alg_load_monitors.setChild(True)
        alg_load_monitors.setProperty("Filename", file_path)
        alg_load_monitors.setProperty("MonitorsAsEvents", False)
        alg_load_monitors.setProperty("OutputWorkspace", trans_name)
        alg_load_monitors.execute()
        monitor = alg_load_monitors.getProperty("OutputWorkspace").value

        rebinned_name = ws_name + "_rebinned"
        alg_rebin = AlgorithmManager.createUnmanaged("RebinToWorkspace")
        alg_rebin.initialize()
        alg_rebin.setChild(True)
        alg_rebin.setProperty("WorkspaceToRebin", detector)
        alg_rebin.setProperty("WorkspaceToMatch", monitor)
        alg_rebin.setProperty("PreserveEvents", False)
        alg_rebin.setProperty("OutputWorkspace", rebinned_name)
        alg_rebin.execute()
        detector = alg_rebin.getProperty("OutputWorkspace").value

        alg_conjoined = AlgorithmManager.createUnmanaged("ConjoinWorkspaces")
        alg_conjoined.initialize()
        alg_conjoined.setChild(True)
        alg_conjoined.setProperty("InputWorkspace1", monitor)
        alg_conjoined.setProperty("InputWorkspace2", detector)
        alg_conjoined.setProperty("CheckOverlapping", True)
        alg_conjoined.execute()
        trans_ws = alg_conjoined.getProperty("InputWorkspace1").value

        # And now extract all the required trans ids
        extracted_name = "extracted"
        alg_extract = AlgorithmManager.createUnmanaged("ExtractSpectra")
        alg_extract.initialize()
        alg_extract.setChild(True)
        alg_extract.setProperty("InputWorkspace", trans_ws)
        alg_extract.setProperty("OutputWorkspace", extracted_name)
        alg_extract.setProperty("DetectorList", trans_ids)
        alg_extract.execute()
        return alg_extract.getProperty("OutputWorkspace").value
    def _get_sample_workspace_histo(self):
        # Load the event workspace and the monitor workspace. Rebin the event to the monitor
        # and conjoin them
        file_path, ws_name= getFileAndName(self._get_dark_file())
        alg_load = AlgorithmManager.createUnmanaged("LoadEventNexus")
        alg_load.initialize()
        alg_load.setChild(True)
        alg_load.setProperty("Filename", file_path)
        alg_load.setProperty("OutputWorkspace", ws_name)
        alg_load.execute()
        event_ws = alg_load.getProperty("OutputWorkspace").value

        monitor_name = ws_name + "_monitor"
        alg_load2 = AlgorithmManager.createUnmanaged("LoadNexusMonitors")
        alg_load2.initialize()
        alg_load2.setChild(True)
        alg_load2.setProperty("Filename", file_path)
        alg_load2.setProperty("MonitorsAsEvents", False)
        alg_load2.setProperty("OutputWorkspace", monitor_name)
        alg_load2.execute()
        monitor_ws = alg_load2.getProperty("OutputWorkspace").value

        rebinned_name = ws_name + "_rebinned"
        alg_rebin = AlgorithmManager.createUnmanaged("RebinToWorkspace")
        alg_rebin.initialize()
        alg_rebin.setChild(True)
        alg_rebin.setProperty("WorkspaceToRebin", event_ws)
        alg_rebin.setProperty("WorkspaceToMatch", monitor_ws)
        alg_rebin.setProperty("PreserveEvents", False)
        alg_rebin.setProperty("OutputWorkspace", rebinned_name)
        alg_rebin.execute()
        sample_ws = alg_rebin.getProperty("OutputWorkspace").value

        # We need to create a copy of the sample because it will be deleted/swallowed by
        # the conjoin below
        cloned_name = ws_name + "_cloned"
        alg_rebin = AlgorithmManager.createUnmanaged("CloneWorkspace")
        alg_rebin.initialize()
        alg_rebin.setChild(True)
        alg_rebin.setProperty("InputWorkspace", sample_ws)
        alg_rebin.setProperty("OutputWorkspace", cloned_name)
        alg_rebin.execute()
        sample_ws_copy = alg_rebin.getProperty("OutputWorkspace").value

        alg_conjoined = AlgorithmManager.createUnmanaged("ConjoinWorkspaces")
        alg_conjoined.initialize()
        alg_conjoined.setChild(True)
        alg_conjoined.setProperty("InputWorkspace1", monitor_ws)
        alg_conjoined.setProperty("InputWorkspace2", sample_ws_copy)
        alg_conjoined.setProperty("CheckOverlapping", True)
        alg_conjoined.execute()
        monitor_ws = alg_conjoined.getProperty("InputWorkspace1").value

        return sample_ws, monitor_ws
示例#3
0
    def _get_sample_workspace_histo(self):
        # Load the event workspace and the monitor workspace. Rebin the event to the monitor
        # and conjoin them
        file_path, ws_name = getFileAndName(self._get_dark_file())
        alg_load = AlgorithmManager.createUnmanaged("LoadEventNexus")
        alg_load.initialize()
        alg_load.setChild(True)
        alg_load.setProperty("Filename", file_path)
        alg_load.setProperty("OutputWorkspace", ws_name)
        alg_load.execute()
        event_ws = alg_load.getProperty("OutputWorkspace").value

        monitor_name = ws_name + "_monitor"
        alg_load2 = AlgorithmManager.createUnmanaged("LoadNexusMonitors")
        alg_load2.initialize()
        alg_load2.setChild(True)
        alg_load2.setProperty("Filename", file_path)
        alg_load2.setProperty("MonitorsAsEvents", False)
        alg_load2.setProperty("OutputWorkspace", monitor_name)
        alg_load2.execute()
        monitor_ws = alg_load2.getProperty("OutputWorkspace").value

        rebinned_name = ws_name + "_rebinned"
        alg_rebin = AlgorithmManager.createUnmanaged("RebinToWorkspace")
        alg_rebin.initialize()
        alg_rebin.setChild(True)
        alg_rebin.setProperty("WorkspaceToRebin", event_ws)
        alg_rebin.setProperty("WorkspaceToMatch", monitor_ws)
        alg_rebin.setProperty("PreserveEvents", False)
        alg_rebin.setProperty("OutputWorkspace", rebinned_name)
        alg_rebin.execute()
        sample_ws = alg_rebin.getProperty("OutputWorkspace").value

        # We need to create a copy of the sample because it will be deleted/swallowed by
        # the conjoin below
        cloned_name = ws_name + "_cloned"
        alg_rebin = AlgorithmManager.createUnmanaged("CloneWorkspace")
        alg_rebin.initialize()
        alg_rebin.setChild(True)
        alg_rebin.setProperty("InputWorkspace", sample_ws)
        alg_rebin.setProperty("OutputWorkspace", cloned_name)
        alg_rebin.execute()
        sample_ws_copy = alg_rebin.getProperty("OutputWorkspace").value

        alg_conjoined = AlgorithmManager.createUnmanaged("ConjoinWorkspaces")
        alg_conjoined.initialize()
        alg_conjoined.setChild(True)
        alg_conjoined.setProperty("InputWorkspace1", monitor_ws)
        alg_conjoined.setProperty("InputWorkspace2", sample_ws_copy)
        alg_conjoined.setProperty("CheckOverlapping", True)
        alg_conjoined.execute()
        monitor_ws = alg_conjoined.getProperty("InputWorkspace1").value

        return sample_ws, monitor_ws
    def _get_transmission_workspace(self, trans_ids):
        trans_ws = None
        file_path = None

        file_path, ws_name= getFileAndName(self._get_dark_file())
        alg_load = AlgorithmManager.createUnmanaged("LoadEventNexus")
        alg_load.initialize()
        alg_load.setChild(True)
        alg_load.setProperty("Filename", file_path)
        alg_load.setProperty("OutputWorkspace", ws_name)
        alg_load.execute()
        detector = alg_load.getProperty("OutputWorkspace").value

        trans_name = ws_name + "_monitor"
        alg_load_monitors = AlgorithmManager.createUnmanaged("LoadNexusMonitors")
        alg_load_monitors.initialize()
        alg_load_monitors.setChild(True)
        alg_load_monitors.setProperty("Filename", file_path)
        alg_load_monitors.setProperty("MonitorsAsEvents", False)
        alg_load_monitors.setProperty("OutputWorkspace", trans_name)
        alg_load_monitors.execute()
        monitor = alg_load_monitors.getProperty("OutputWorkspace").value

        rebinned_name = ws_name + "_rebinned"
        alg_rebin = AlgorithmManager.createUnmanaged("RebinToWorkspace")
        alg_rebin.initialize()
        alg_rebin.setChild(True)
        alg_rebin.setProperty("WorkspaceToRebin", detector)
        alg_rebin.setProperty("WorkspaceToMatch", monitor)
        alg_rebin.setProperty("PreserveEvents", False)
        alg_rebin.setProperty("OutputWorkspace", rebinned_name)
        alg_rebin.execute()
        detector = alg_rebin.getProperty("OutputWorkspace").value

        alg_conjoined = AlgorithmManager.createUnmanaged("ConjoinWorkspaces")
        alg_conjoined.initialize()
        alg_conjoined.setChild(True)
        alg_conjoined.setProperty("InputWorkspace1", monitor)
        alg_conjoined.setProperty("InputWorkspace2", detector)
        alg_conjoined.setProperty("CheckOverlapping", True)
        alg_conjoined.execute()
        trans_ws = alg_conjoined.getProperty("InputWorkspace1").value

        # And now extract all the required trans ids
        extracted_name  = "extracted"
        alg_extract = AlgorithmManager.createUnmanaged("ExtractSpectra")
        alg_extract.initialize()
        alg_extract.setChild(True)
        alg_extract.setProperty("InputWorkspace", trans_ws)
        alg_extract.setProperty("OutputWorkspace", extracted_name)
        alg_extract.setProperty("DetectorList", trans_ids)
        alg_extract.execute()
        return alg_extract.getProperty("OutputWorkspace").value
示例#5
0
    def _get_sample_workspaces(self, run_number=None):
        monitor_ws = None
        file_path = None
        ws_name = None
        sample_ws = None
        if run_number is not None:
            file_path, ws_name = getFileAndName(run_number)
            alg_load = AlgorithmManager.createUnmanaged("LoadNexusProcessed")
            alg_load.initialize()
            alg_load.setChild(True)
            alg_load.setProperty("Filename", file_path)
            alg_load.setProperty("EntryNumber", 1)
            alg_load.setProperty("OutputWorkspace", ws_name)
            alg_load.execute()
            sample_ws = alg_load.getProperty("OutputWorkspace").value
        else:
            file_path, ws_name = getFileAndName(self._get_dark_file())
            alg_load = AlgorithmManager.createUnmanaged("Load")
            alg_load.initialize()
            alg_load.setChild(True)
            alg_load.setProperty("Filename", file_path)
            alg_load.setProperty("OutputWorkspace", ws_name)
            alg_load.execute()
            sample_ws = alg_load.getProperty("OutputWorkspace").value

        # Now get the monitor
        monitor_ws = None
        if run_number is not None:
            monitors_name = ws_name + "_monitors"
            alg_load2 = AlgorithmManager.createUnmanaged("LoadNexusProcessed")
            alg_load2.initialize()
            alg_load2.setChild(True)
            alg_load2.setProperty("Filename", file_path)
            alg_load2.setProperty("EntryNumber", 2)
            alg_load2.setProperty("OutputWorkspace", monitors_name)
            alg_load2.execute()
            monitor_ws = alg_load2.getProperty("OutputWorkspace").value
        else:
            # Load the monitor workspace
            monitors_name = ws_name + "_monitors"
            alg_load_monitors = AlgorithmManager.createUnmanaged(
                "LoadNexusMonitors")
            alg_load_monitors.initialize()
            alg_load_monitors.setChild(True)
            alg_load_monitors.setProperty("Filename", file_path)
            alg_load_monitors.setProperty("MonitorsAsEvents", False)
            alg_load_monitors.setProperty("OutputWorkspace", monitors_name)
            alg_load_monitors.execute()
            monitor_ws = alg_load_monitors.getProperty("OutputWorkspace").value

        # Rebin the scatter data to match the monitor binning
        rebinned_name = "monitor_rebinned"
        alg_rebin = AlgorithmManager.createUnmanaged("RebinToWorkspace")
        alg_rebin.initialize()
        alg_rebin.setChild(True)
        alg_rebin.setProperty("WorkspaceToRebin", sample_ws)
        alg_rebin.setProperty("WorkspaceToMatch", monitor_ws)
        alg_rebin.setProperty("PreserveEvents", False)
        alg_rebin.setProperty("OutputWorkspace", rebinned_name)
        alg_rebin.execute()
        sample_ws = alg_rebin.getProperty("OutputWorkspace").value

        return sample_ws, monitor_ws
示例#6
0
文件: SANSadd2.py 项目: dpaj/mantid
def _loadWS(entry, ext, inst, wsName, rawTypes, period=_NO_INDIVIDUAL_PERIODS):
    filename, ext = _makeFilename(entry, ext, inst)
    sanslog.notice('reading file:     ' + filename)

    isDataSetEvent = False
    workspace_type = get_workspace_type(filename)
    if workspace_type is WorkspaceType.MultiperiodHistogram:
        if period != _NO_INDIVIDUAL_PERIODS:
            outWs = Load(Filename=filename,
                         OutputWorkspace=wsName,
                         EntryNumber=period)
        else:
            outWs = Load(Filename=filename, OutputWorkspace=wsName)
    elif workspace_type is WorkspaceType.Histogram:
        outWs = Load(Filename=filename, OutputWorkspace=wsName)
    elif workspace_type is WorkspaceType.Event or workspace_type is WorkspaceType.MultiperiodEvent:
        isDataSetEvent = True
        temp_ws_name = wsName + "_event_temp"
        temp_ws_name_monitors = temp_ws_name + "_monitors"
        ws_name_monitors = wsName + "_monitors"

        LoadEventNexus(Filename=filename,
                       OutputWorkspace=temp_ws_name,
                       LoadMonitors=True)
        outWs = mtd[temp_ws_name]
        # If we are dealing with a multiperid workspace then we must can only use a single period at a
        # time, hence we reload from disk the whole data set every time which is very bad and must be
        # cached in the future
        if isinstance(outWs, WorkspaceGroup):
            remove_unwanted_workspaces(wsName, temp_ws_name, period)
            remove_unwanted_workspaces(ws_name_monitors, temp_ws_name_monitors,
                                       period)
        else:
            RenameWorkspace(InputWorkspace=temp_ws_name,
                            OutputWorkspace=wsName)
            RenameWorkspace(InputWorkspace=temp_ws_name_monitors,
                            OutputWorkspace=ws_name_monitors)

        runDetails = mtd[wsName].getRun()
        timeArray = runDetails.getLogData("proton_charge").times
        # There should never be a time increment in the proton charge larger than say "two weeks"
        # SANS2D currently is run at 10 frames per second. This may be increated to 5Hz
        # (step of 0.2 sec). Although time between frames may be larger due to having the SMP veto switched on,
        # but hopefully not longer than two weeks!
        for i in range(len(timeArray) - 1):
            # cal time dif in seconds
            timeDif = (timeArray[i + 1] - timeArray[i]) / np.timedelta64(
                1, 's')
            if timeDif > 172800:
                sanslog.warning(
                    'Time increments in the proton charge log of ' + filename +
                    ' are suspicious large.' +
                    ' For example a time difference of ' + str(timeDif) +
                    " seconds has been observed.")
                break
    else:
        outWs = Load(Filename=filename, OutputWorkspace=wsName)

    full_path, __ = getFileAndName(filename)
    path, fName = os.path.split(full_path)
    if path.find('/') == -1:
        #looks like we're on a windows system, convert the directory separators
        path = path.replace('\\', '/')

    if _isType(ext, rawTypes):
        LoadSampleDetailsFromRaw(InputWorkspace=wsName,
                                 Filename=path + '/' + fName)

    logFile = None
    #change below when logs in Nexus files work  file types of .raw need their log files to be copied too
    if True:  #_isType(ext, rawTypes):
        logFile = os.path.splitext(fName)[0] + '.log'

    try:
        outWs = mtd[wsName]
        run = outWs.getRun()
        numPeriods = run.getLogData('nperiods').value
    except:
        #assume the run file didn't support multi-period data and so there is only one period
        numPeriods = 1

    return path, fName, logFile, numPeriods, isDataSetEvent
示例#7
0
def _loadWS(entry, ext, inst, wsName, rawTypes, period=_NO_INDIVIDUAL_PERIODS) :
    filename, ext = _makeFilename(entry, ext, inst)
    sanslog.notice('reading file:     '+filename)

    isDataSetEvent = False
    workspace_type = get_workspace_type(filename)
    if workspace_type is WorkspaceType.MultiperiodHistogram:
        if period != _NO_INDIVIDUAL_PERIODS:
            outWs = Load(Filename=filename, OutputWorkspace=wsName, EntryNumber=period)
        else:
            outWs = Load(Filename=filename, OutputWorkspace=wsName)
    elif workspace_type is WorkspaceType.Histogram:
        outWs = Load(Filename=filename, OutputWorkspace=wsName)
    elif workspace_type is WorkspaceType.Event or workspace_type is WorkspaceType.MultiperiodEvent:
        isDataSetEvent = True
        temp_ws_name = wsName + "_event_temp"
        temp_ws_name_monitors = temp_ws_name + "_monitors"
        ws_name_monitors = wsName + "_monitors"

        LoadEventNexus(Filename=filename, OutputWorkspace=temp_ws_name, LoadMonitors=True)
        outWs = mtd[temp_ws_name]
        # If we are dealing with a multiperid workspace then we must can only use a single period at a
        # time, hence we reload from disk the whole data set every time which is very bad and must be
        # cached in the future
        if isinstance(outWs, WorkspaceGroup):
            remove_unwanted_workspaces(wsName, temp_ws_name, period)
            remove_unwanted_workspaces(ws_name_monitors, temp_ws_name_monitors, period)
        else:
            RenameWorkspace(InputWorkspace=temp_ws_name, OutputWorkspace=wsName)
            RenameWorkspace(InputWorkspace=temp_ws_name_monitors, OutputWorkspace=ws_name_monitors)

        runDetails = mtd[wsName].getRun()
        timeArray = runDetails.getLogData("proton_charge").times
        # There should never be a time increment in the proton charge larger than say "two weeks"
        # SANS2D currently is run at 10 frames per second. This may be increated to 5Hz
        # (step of 0.2 sec). Although time between frames may be larger due to having the SMP veto switched on,
        # but hopefully not longer than two weeks!
        for i in range(len(timeArray)-1):
        # cal time dif in seconds
            timeDif = (timeArray[i+1]-timeArray[i]) / np.timedelta64(1, 's')
            if timeDif > 172800:
                sanslog.warning('Time increments in the proton charge log of ' + filename + ' are suspicious large.' +
                                ' For example a time difference of ' + str(timeDif) + " seconds has been observed.")
                break
    else:
        outWs = Load(Filename=filename,OutputWorkspace=wsName)

    full_path, __ = getFileAndName(filename)
    path, fName = os.path.split(full_path)
    if path.find('/') == -1:
    #looks like we're on a windows system, convert the directory separators
        path = path.replace('\\', '/')

    if _isType(ext, rawTypes):
        LoadSampleDetailsFromRaw(InputWorkspace=wsName,Filename= path+'/'+fName)

    logFile = None
  #change below when logs in Nexus files work  file types of .raw need their log files to be copied too
    if True:#_isType(ext, rawTypes):
        logFile = os.path.splitext(fName)[0]+'.log'

    try:
        outWs = mtd[wsName]
        run = outWs.getRun()
        numPeriods = run.getLogData('nperiods').value
    except:
    #assume the run file didn't support multi-period data and so there is only one period
        numPeriods = 1

    return path, fName, logFile, numPeriods, isDataSetEvent
    def _get_sample_workspaces(self, run_number = None):
        monitor_ws = None
        file_path = None
        ws_name = None
        sample_ws = None
        if run_number is not None:
            file_path, ws_name= getFileAndName(run_number)
            alg_load = AlgorithmManager.createUnmanaged("LoadNexusProcessed")
            alg_load.initialize()
            alg_load.setChild(True)
            alg_load.setProperty("Filename", file_path)
            alg_load.setProperty("EntryNumber", 1)
            alg_load.setProperty("OutputWorkspace", ws_name)
            alg_load.execute()
            sample_ws = alg_load.getProperty("OutputWorkspace").value
        else:
            file_path, ws_name= getFileAndName(self._get_dark_file())
            alg_load = AlgorithmManager.createUnmanaged("Load")
            alg_load.initialize()
            alg_load.setChild(True)
            alg_load.setProperty("Filename", file_path)
            alg_load.setProperty("OutputWorkspace", ws_name)
            alg_load.execute()
            sample_ws = alg_load.getProperty("OutputWorkspace").value

        # Now get the monitor
        monitor_ws = None
        if run_number is not None:
            monitors_name = ws_name + "_monitors"
            alg_load2 = AlgorithmManager.createUnmanaged("LoadNexusProcessed")
            alg_load2.initialize()
            alg_load2.setChild(True)
            alg_load2.setProperty("Filename", file_path)
            alg_load2.setProperty("EntryNumber", 2)
            alg_load2.setProperty("OutputWorkspace", monitors_name)
            alg_load2.execute()
            monitor_ws = alg_load2.getProperty("OutputWorkspace").value
        else:
            # Load the monitor workspace
            monitors_name = ws_name + "_monitors"
            alg_load_monitors = AlgorithmManager.createUnmanaged("LoadNexusMonitors")
            alg_load_monitors.initialize()
            alg_load_monitors.setChild(True)
            alg_load_monitors.setProperty("Filename", file_path)
            alg_load_monitors.setProperty("MonitorsAsEvents", False)
            alg_load_monitors.setProperty("OutputWorkspace", monitors_name)
            alg_load_monitors.execute()
            monitor_ws = alg_load_monitors.getProperty("OutputWorkspace").value

        # Rebin the scatter data to match the monitor binning
        rebinned_name = "monitor_rebinned"
        alg_rebin = AlgorithmManager.createUnmanaged("RebinToWorkspace")
        alg_rebin.initialize()
        alg_rebin.setChild(True)
        alg_rebin.setProperty("WorkspaceToRebin", sample_ws)
        alg_rebin.setProperty("WorkspaceToMatch", monitor_ws)
        alg_rebin.setProperty("PreserveEvents", False)
        alg_rebin.setProperty("OutputWorkspace", rebinned_name)
        alg_rebin.execute()
        sample_ws = alg_rebin.getProperty("OutputWorkspace").value

        return sample_ws, monitor_ws