Ejemplo n.º 1
0
 def _prepare_trans_data(self, ws, value):
     rebin_string = "{0}, {1}, {2}".format(self.test_tof_min,
                                           self.test_tof_width,
                                           self.test_tof_max)
     ws = Rebin(InputWorkspace=ws, Params=rebin_string, StoreInADS=False)
     # Set all entries to value
     for hist in range(ws.getNumberHistograms()):
         data_y = ws.dataY(hist)
         for index in range(len(data_y)):
             data_y[index] = value
         # This will be the background bin
         data_y[0] = 0.1
     return ws
 def _create_flat_background_test_workspace(workspace_name):
     LoadNexusProcessed(Filename="LOQ48127", OutputWorkspace=workspace_name)
     workspace = AnalysisDataService.retrieve(workspace_name)
     # Rebin to only have four values at 11, 31, 51, 70.5
     workspace = Rebin(workspace, "1,20,80")
     # For each spectrum we set the first two entries to 2 and the other two entries to 4.
     for index in range(workspace.getNumberHistograms()):
         data_y = workspace.dataY(index)
         data_y[0] = 2.
         data_y[1] = 2.
         data_y[2] = 4.
         data_y[3] = 4.
     return workspace
Ejemplo n.º 3
0
 def _create_flat_background_test_workspace(workspace_name):
     LoadNexusProcessed(Filename="LOQ48127", OutputWorkspace=workspace_name)
     workspace = AnalysisDataService.retrieve(workspace_name)
     # Rebin to only have four values at 11, 31, 51, 70.5
     workspace = Rebin(workspace, "1,20,80")
     # For each spectrum we set the first two entries to 2 and the other two entries to 4.
     for index in range(workspace.getNumberHistograms()):
         data_y = workspace.dataY(index)
         data_y[0] = 2.
         data_y[1] = 2.
         data_y[2] = 4.
         data_y[3] = 4.
     return workspace
Ejemplo n.º 4
0
def save_banks(InputWorkspace,
               Filename,
               Title,
               OutputDir,
               Binning=None,
               GroupingWorkspace=None):
    """
    Saves input workspace to processed NeXus file in specified
    output directory with optional rebinning and grouping
    (to coarsen) the output in a bank-by-bank manner. Mainly
    wraps Mantid `SaveNexusProcessed` algorithm.

    :param InputWorkspace: Mantid workspace to save out
    :type InputWorkspace: MatrixWorkspace
    :param Filename: Filename to save output
    :type Filename: str
    :param Title: A title to describe the saved workspace
    :type Title: str
    :param OutputDir: Output directory to save the processed NeXus file
    :type OutputDir: path str
    :param Binning: Optional rebinning of event workspace.
                    See `Rebin` in Mantid for options
    :type Binning: dbl list
    :param GroupingWorkspace: A workspace with grouping
                              information for the output spectra
    :type GroupWorkspace: GroupWorkspace
    """

    # Make a local clone
    CloneWorkspace(InputWorkspace=InputWorkspace, OutputWorkspace="__tmp")
    tmp_wksp = mtd["__tmp"]

    # Rebin if requested
    if Binning:
        tmp_wksp = Rebin(InputWorkspace=tmp_wksp,
                         Params=Binning,
                         PreserveEvents=True)

    # Convert to distributions to remove bin width dependence
    yunit = tmp_wksp.YUnit()
    if yunit == "Counts":
        try:
            ConvertToDistribution(tmp_wksp)
        except BaseException:
            pass

    # Output to desired level of grouping
    isEventWksp = isinstance(tmp_wksp, IEventWorkspace)
    if isEventWksp and GroupingWorkspace and yunit == "Counts":
        tmp_wksp = DiffractionFocussing(InputWorkspace=tmp_wksp,
                                        GroupingWorkspace=GroupingWorkspace,
                                        PreserveEvents=False)

    # Save out wksp to file
    filename = os.path.join(os.path.abspath(OutputDir), Filename)
    SaveNexusProcessed(InputWorkspace=tmp_wksp,
                       Filename=filename,
                       Title=Title,
                       Append=True,
                       PreserveEvents=False,
                       WorkspaceIndexList=range(
                           tmp_wksp.getNumberHistograms()))
    DeleteWorkspace(tmp_wksp)