示例#1
0
def handle_saving_event_workspace_when_saving_as_histogram(binning, runs, def_type, inst):
    ws_in_monitor = mtd[ADD_FILES_SUM_TEMPORARY_MONITORS]
    if binning == 'Monitors':
        mon_x = ws_in_monitor.dataX(0)
        binning = str(mon_x[0])
        bin_gap = mon_x[1] - mon_x[0]
        binning = binning + "," + str(bin_gap)
        for j in range(2, len(mon_x)):
            next_bin_gap = mon_x[j] - mon_x[j-1]
            if next_bin_gap != bin_gap:
                bin_gap = next_bin_gap
                binning = binning + "," + str(mon_x[j-1]) + "," + str(bin_gap)
        binning = binning + "," + str(mon_x[len(mon_x)-1])

    sanslog.notice(binning)
    Rebin(InputWorkspace=ADD_FILES_SUM_TEMPORARY, OutputWorkspace='AddFilesSumTemporary_Rebin', Params=binning,
          PreserveEvents=False)

    # loading the nexus file using LoadNexus is necessary because it has some metadata
    # that is not in LoadEventNexus. This must be fixed.
    filename, ext = _make_filename(runs[0], def_type, inst)
    workspace_type = get_workspace_type(filename)
    if workspace_type is WorkspaceType.MultiperiodEvent:
        # If we are dealing with multi-period event workspaces then there is no way of getting any other
        # sample log information hence we use make a copy of the monitor workspace and use that instead
        # of the reloading the first file again
        CloneWorkspace(InputWorkspace=ADD_FILES_SUM_TEMPORARY_MONITORS, OutputWorkspace=ADD_FILES_SUM_TEMPORARY)
    else:
        LoadNexus(Filename=filename, OutputWorkspace=ADD_FILES_SUM_TEMPORARY,
                  SpectrumMax=ws_in_monitor.getNumberHistograms())
    # User may have selected a binning which is different from the default
    Rebin(InputWorkspace=ADD_FILES_SUM_TEMPORARY, OutputWorkspace=ADD_FILES_SUM_TEMPORARY, Params=binning)
    # For now the monitor binning must be the same as the detector binning
    # since otherwise both cannot exist in the same output histogram file
    Rebin(InputWorkspace=ADD_FILES_SUM_TEMPORARY_MONITORS, OutputWorkspace=ADD_FILES_SUM_TEMPORARY_MONITORS,
          Params=binning)

    ws_in_monitor = mtd[ADD_FILES_SUM_TEMPORARY_MONITORS]
    wsOut = mtd[ADD_FILES_SUM_TEMPORARY]
    ws_in_detector = mtd['AddFilesSumTemporary_Rebin']

    # We loose added sample log information since we reload a single run workspace
    # and conjoin with the added workspace. In order to preserve some added sample
    # logs we need to transfer them at this point
    transfer_special_sample_logs(from_ws=ws_in_detector, to_ws=wsOut)

    mon_n = ws_in_monitor.getNumberHistograms()
    for i in range(mon_n):
        wsOut.setY(i, ws_in_monitor.dataY(i))
        wsOut.setE(i, ws_in_monitor.dataE(i))
    ConjoinWorkspaces(wsOut, ws_in_detector, CheckOverlapping=True)

    if 'AddFilesSumTemporary_Rebin' in mtd:
        DeleteWorkspace('AddFilesSumTemporary_Rebin')
示例#2
0
 def setUpClass(cls):
     cls.g1da = config['graph1d.autodistribution']
     config['graph1d.autodistribution'] = 'On'
     cls.ws2d_non_distribution = CreateWorkspace(
         DataX=[10, 20, 30, 10, 20, 30],
         DataY=[2, 3, 4, 5],
         DataE=[1, 2, 3, 4],
         NSpec=2,
         Distribution=False,
         UnitX='Wavelength',
         YUnitLabel='Counts per microAmp.hour',
         VerticalAxisUnit='DeltaE',
         VerticalAxisValues=[4, 6, 8],
         OutputWorkspace='ws2d_non_distribution')
     cls.ws2d_distribution = CreateWorkspace(
         DataX=[10, 20, 30, 10, 20, 30],
         DataY=[2, 3, 4, 5, 6],
         DataE=[1, 2, 3, 4, 6],
         NSpec=1,
         Distribution=True,
         UnitX='Wavelength',
         YUnitLabel='Counts per microAmp.hour',
         OutputWorkspace='ws2d_distribution')
     cls.ws2d_histo = CreateWorkspace(DataX=[10, 20, 30, 10, 20, 30],
                                      DataY=[2, 3, 4, 5],
                                      DataE=[1, 2, 3, 4],
                                      NSpec=2,
                                      Distribution=True,
                                      UnitX='Wavelength',
                                      VerticalAxisUnit='DeltaE',
                                      VerticalAxisValues=[4, 6, 8],
                                      OutputWorkspace='ws2d_histo')
     cls.ws2d_point = CreateWorkspace(
         DataX=[1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4],
         DataY=[2] * 12,
         NSpec=3,
         OutputWorkspace='ws2d_point')
     cls.ws1d_point = CreateWorkspace(DataX=[1, 2],
                                      DataY=[1, 2],
                                      NSpec=1,
                                      Distribution=False,
                                      OutputWorkspace='ws1d_point')
     cls.ws2d_histo_rag = CreateWorkspace(
         DataX=[1, 2, 3, 4, 5, 2, 4, 6, 8, 10],
         DataY=[2] * 8,
         NSpec=2,
         VerticalAxisUnit='DeltaE',
         VerticalAxisValues=[5, 7, 9],
         OutputWorkspace='ws2d_histo_rag')
     cls.ws2d_point_rag = CreateWorkspace(DataX=[1, 2, 3, 4, 2, 4, 6, 8],
                                          DataY=[2] * 8,
                                          NSpec=2,
                                          OutputWorkspace='ws2d_point_rag')
     cls.ws_MD_2d = CreateMDHistoWorkspace(
         Dimensionality=3,
         Extents='-3,3,-10,10,-1,1',
         SignalInput=range(25),
         ErrorInput=range(25),
         NumberOfEvents=10 * np.ones(25),
         NumberOfBins='5,5,1',
         Names='Dim1,Dim2,Dim3',
         Units='MomentumTransfer,EnergyTransfer,Angstrom',
         OutputWorkspace='ws_MD_2d')
     cls.ws_MD_1d = CreateMDHistoWorkspace(
         Dimensionality=3,
         Extents='-3,3,-10,10,-1,1',
         SignalInput=range(5),
         ErrorInput=range(5),
         NumberOfEvents=10 * np.ones(5),
         NumberOfBins='1,5,1',
         Names='Dim1,Dim2,Dim3',
         Units='MomentumTransfer,EnergyTransfer,Angstrom',
         OutputWorkspace='ws_MD_1d')
     cls.ws2d_point_uneven = CreateWorkspace(
         DataX=[10, 20, 30],
         DataY=[1, 2, 3],
         NSpec=1,
         OutputWorkspace='ws2d_point_uneven')
     cls.ws2d_high_counting_detector = CreateWorkspace(
         DataX=[1, 2, 3, 4] * 1000,
         DataY=[2] * 4 * 12 + [200] * 4 + [2] * 987 * 4,
         NSpec=1000,
         OutputWorkspace='ws2d_high_counting_detector')
     wp = CreateWorkspace(DataX=[15, 25, 35, 45],
                          DataY=[1, 2, 3, 4],
                          NSpec=1)
     ConjoinWorkspaces(cls.ws2d_point_uneven, wp, CheckOverlapping=False)
     cls.ws2d_point_uneven = mantid.mtd['ws2d_point_uneven']
     cls.ws2d_histo_uneven = CreateWorkspace(
         DataX=[10, 20, 30, 40],
         DataY=[1, 2, 3],
         NSpec=1,
         OutputWorkspace='ws2d_histo_uneven')
     wp = CreateWorkspace(DataX=[15, 25, 35, 45, 55],
                          DataY=[1, 2, 3, 4],
                          NSpec=1)
     ConjoinWorkspaces(cls.ws2d_histo_uneven, wp, CheckOverlapping=False)
     cls.ws2d_histo_uneven = mantid.mtd['ws2d_histo_uneven']
     newYAxis = mantid.api.NumericAxis.create(3)
     newYAxis.setValue(0, 10)
     newYAxis.setValue(1, 15)
     newYAxis.setValue(2, 25)
     cls.ws2d_histo_uneven.replaceAxis(1, newYAxis)
     AddTimeSeriesLog(cls.ws2d_histo,
                      Name="my_log",
                      Time="2010-01-01T00:00:00",
                      Value=100)
     AddTimeSeriesLog(cls.ws2d_histo,
                      Name="my_log",
                      Time="2010-01-01T00:30:00",
                      Value=15)
     AddTimeSeriesLog(cls.ws2d_histo,
                      Name="my_log",
                      Time="2010-01-01T00:50:00",
                      Value=100.2)
示例#3
0
    def PyExec(self):
        data = self._expand_groups()
        bkg = self.getProperty(
            "BackgroundWorkspace").valueAsStr  # same background for all
        cal = self.getProperty(
            "CalibrationWorkspace").value  # same calibration for all
        numberBins = self.getProperty("NumberBins").value
        outWS = self.getPropertyValue("OutputWorkspace")
        summing = self.getProperty("Sum").value  # [Yes or No]

        # convert all of the input workspaces into spectrum of "target" units (generally angle)
        data, masks = self._convert_data(data)

        # determine x-range
        xMin, xMax = self._locate_global_xlimit(data)

        # BEGIN_FOR: prcess_spectra
        for n, (_wsn, _mskn) in enumerate(zip(data, masks)):
            # resample spectra
            ResampleX(
                InputWorkspace=_wsn,
                OutputWorkspace=_wsn,
                XMin=xMin,
                XMax=xMax,
                NumberBins=numberBins,
                EnableLogging=False,
            )

            # calibration
            if cal is not None:
                _ws_cal_resampled = self._resample_calibration(
                    _wsn, _mskn, xMin, xMax)
                Divide(
                    LHSWorkspace=_wsn,
                    RHSWorkspace=_ws_cal_resampled,
                    OutputWorkspace=_wsn,
                    EnableLogging=False,
                )
            else:
                _ws_cal_resampled = None

            Scale(
                InputWorkspace=_wsn,
                OutputWorkspace=_wsn,
                Factor=self._get_scale(cal) / self._get_scale(_wsn),
                EnableLogging=False,
            )

            # background
            if bkg:
                _ws_bkg_resampled = self._resample_background(
                    bkg, _wsn, _mskn, xMin, xMax, _ws_cal_resampled)

                Minus(
                    LHSWorkspace=_wsn,
                    RHSWorkspace=_ws_bkg_resampled,
                    OutputWorkspace=_wsn,
                    EnableLogging=False,
                )

            if summing:
                # conjoin
                if n < 1:
                    RenameWorkspace(
                        InputWorkspace=_wsn,
                        OutputWorkspace="__ws_conjoined",
                        EnableLogging=False,
                    )
                else:
                    # this adds to `InputWorkspace1`
                    ConjoinWorkspaces(
                        InputWorkspace1="__ws_conjoined",
                        InputWorkspace2=_wsn,
                        CheckOverlapping=False,
                        EnableLogging=False,
                    )

        # END_FOR: prcess_spectra
        # Step_3: sum all spectra
        # ref: https://docs.mantidproject.org/nightly/algorithms/SumSpectra-v1.html
        if summing:
            if cal is not None:
                outWS = SumSpectra(
                    InputWorkspace="__ws_conjoined",
                    OutputWorkspace=outWS,
                    WeightedSum=True,
                    MultiplyBySpectra=not bool(cal),
                    EnableLogging=False,
                )
            else:
                outWS = SumSpectra(
                    InputWorkspace="__ws_conjoined",
                    OutputWorkspace=outWS,
                    WeightedSum=True,
                    MultiplyBySpectra=True,
                    EnableLogging=False,
                )
        else:
            if len(data) == 1:
                outWS = RenameWorkspace(InputWorkspace=data[0],
                                        OutputWorkspace=outWS)
            else:
                outWS = GroupWorkspaces(InputWorkspaces=data,
                                        OutputWorkspace=outWS)

        self.setProperty("OutputWorkspace", outWS)

        # Step_4: remove temp workspaces
        [
            DeleteWorkspace(ws, EnableLogging=False)
            for ws in self.temp_workspace_list if mtd.doesExist(ws)
        ]