Exemple #1
0
    def _load_and_sum_runs(self, spectra):
        """Load the input set of runs & sum them if there
        is more than one.
            @param spectra :: The list of spectra to load
            @returns a tuple of length 2 containing (main_detector_ws, monitor_ws)
        """
        isis = config.getFacility("ISIS")
        inst_prefix = isis.instrument("VESUVIO").shortName()

        runs = self._get_runs()

        self.summed_ws, self.summed_mon = "__loadraw_evs", "__loadraw_evs_monitors"
        for index, run in enumerate(runs):
            run = inst_prefix + str(run)
            if index == 0:
                out_name, out_mon = SUMMED_WS, SUMMED_MON
            else:
                out_name, out_mon = SUMMED_WS + 'tmp', SUMMED_MON + 'tmp'
            # Load data
            LoadRaw(Filename=run,
                    SpectrumList=spectra,
                    OutputWorkspace=out_name,
                    LoadMonitors='Exclude',
                    EnableLogging=_LOGGING_)
            LoadRaw(Filename=run,
                    SpectrumList=self._mon_spectra,
                    OutputWorkspace=out_mon,
                    EnableLogging=_LOGGING_)
            if index > 0:  # sum
                Plus(LHSWorkspace=SUMMED_WS,
                     RHSWorkspace=out_name,
                     OutputWorkspace=SUMMED_WS,
                     EnableLogging=_LOGGING_)
                Plus(LHSWorkspace=SUMMED_MON,
                     RHSWorkspace=out_mon,
                     OutputWorkspace=SUMMED_MON,
                     EnableLogging=_LOGGING_)
                DeleteWorkspace(out_name, EnableLogging=_LOGGING_)
                DeleteWorkspace(out_mon, EnableLogging=_LOGGING_)

        CropWorkspace(Inputworkspace=SUMMED_WS,
                      OutputWorkspace=SUMMED_WS,
                      XMax=self._tof_max,
                      EnableLogging=_LOGGING_)
        CropWorkspace(Inputworkspace=SUMMED_MON,
                      OutputWorkspace=SUMMED_MON,
                      XMax=self._mon_tof_max,
                      EnableLogging=_LOGGING_)
        return mtd[SUMMED_WS], mtd[SUMMED_MON]
Exemple #2
0
 def monitorTransfit(self, files, foilType, divE):
     isFirstFile = True
     isSingleFile = len(files) == 1
     firstFileName = ""
     for file in files:
         discard, fileName = path.split(file)
         fnNoExt = path.splitext(fileName)[0]
         if isFirstFile:
             firstFileName = fnNoExt
         fileName_Raw = fnNoExt + '_raw'
         fileName_3 = fnNoExt + '_3'
         LoadRaw(Filename=file, OutputWorkspace=fileName_Raw)
         CropWorkspace(InputWorkspace=fileName_Raw, OutputWorkspace=fileName_Raw, XMin=100, XMax=19990)
         NormaliseByCurrent(InputWorkspace=fileName_Raw, OutputWorkspace=fileName_Raw)
         ExtractSingleSpectrum(InputWorkspace=fileName_Raw, OutputWorkspace=fileName_3, WorkspaceIndex=3)
         DeleteWorkspace(fileName_Raw)
         ConvertUnits(InputWorkspace=fileName_3, Target='Energy', OutputWorkspace=fileName_3)
         self.TransfitRebin(fileName_3, fileName_3, foilType, divE)
         if not isFirstFile:
             Plus(LHSWorkspace=firstFileName + '_3', RHSWorkspace=fileName_3, OutputWorkspace=firstFileName + '_3')
             DeleteWorkspace(fileName_3)
         else:
             isFirstFile = False
     if isSingleFile:
         RenameWorkspace(InputWorkspace=firstFileName + '_3', OutputWorkspace=firstFileName + '_monitor')
     else:
         noFiles = len(files) ** (-1)
         CreateSingleValuedWorkspace(OutputWorkspace='scale', DataValue=noFiles)
         Multiply(LHSWorkspace=firstFileName + '_3', RHSWorkspace='scale',
                  OutputWorkspace=firstFileName + '_monitor')
         DeleteWorkspace('scale')
         DeleteWorkspace(firstFileName + '_3')
    def runTest(self):
        ws = LoadRaw(Filename='WISH00038237.raw', OutputWorkspace='38237')
        ws = ConvertUnits(ws, 'dSpacing', OutputWorkspace='38237')
        UB = np.array([[-0.00601763,  0.07397297,  0.05865706],
                       [ 0.05373321,  0.050198,   -0.05651455],
                       [-0.07822144,  0.0295911,  -0.04489172]])

        SetUB(ws, UB=UB)

        self._peaks = PredictPeaks(ws, WavelengthMin=0.1, WavelengthMax=100,
                                   OutputWorkspace='peaks')
        # We specifically want to check peak -5 -1 -7 exists, so filter for it
        self._filtered = FilterPeaks(self._peaks, "h^2+k^2+l^2", 75, '=',
                                     OutputWorkspace='filtered')

        SaveIsawPeaks(self._peaks, Filename='WISHSXReductionPeaksTest.peaks')
def load_data_and_normalise(filename,
                            spectrumMin=1,
                            spectrumMax=19461,
                            outputWorkspace="sample"):
    """
    Function to load in raw data, crop and normalise
    :param filename: file path to .raw
    :param spectrumMin: min spec to load (default incl. all monitors)
    :param spectrumMax: max spec to load (default includes only bank 1)
    :param outputWorkspace: name of output workspace (can be specified to stop workspaces being overwritten)
    :return: normalised and cropped data with xunit wavelength (excl. monitors)
    """
    sample, mon = LoadRaw(Filename=filename,
                          SpectrumMin=spectrumMin,
                          SpectrumMax=spectrumMax,
                          LoadMonitors="Separate",
                          OutputWorkspace=outputWorkspace)
    for ws in [sample, mon]:
        CropWorkspace(InputWorkspace=ws,
                      OutputWorkspace=ws,
                      XMin=6000,
                      XMax=99000)
        NormaliseByCurrent(InputWorkspace=ws, OutputWorkspace=ws)
        ConvertUnits(InputWorkspace=ws,
                     OutputWorkspace=ws,
                     Target='Wavelength')
    NormaliseToMonitor(InputWorkspace=sample,
                       OutputWorkspace=sample,
                       MonitorWorkspaceIndex=3,
                       MonitorWorkspace=mon)
    ReplaceSpecialValues(InputWorkspace=sample,
                         OutputWorkspace=sample,
                         NaNValue=0,
                         InfinityValue=0)
    CropWorkspace(InputWorkspace=sample,
                  OutputWorkspace=sample,
                  XMin=0.8,
                  XMax=9.3)
    return sample
    def runTest(self):
        config["default.instrument"] = "LOQ"
        LOQ()
        MaskFile('MASK.094AA')
        Gravity(False)
        Set2D()
        Detector("main-detector-bank")
        Sample = LoadRaw('54431.raw')
        AssignSample(Sample, False)
        Can = LoadRaw('54432.raw')
        AssignCan(Can, False)
        LimitsWav(3, 4, 0.2, 'LIN')
        TransFit('LOG', 3.0, 8.0)
        Sample_Trans = LoadRaw('54435.raw')
        Sample_Direct = LoadRaw('54433.raw')
        TransmissionSample(Sample_Trans, Sample_Direct, False)
        Can_Trans = LoadRaw('54434.raw')
        Can_Direct = LoadRaw('54433.raw')
        TransmissionCan(Can_Trans, Can_Direct, False)

        #run the reduction
        WavRangeReduction(3, 4, False, '_suff')
    def runTest(self):
        config["default.instrument"] = "LOQ"
        LOQ()

        Set1D()
        Detector("rear-detector")
        MaskFile('MASK.094AA')
        Gravity(False)
        Sample = LoadRaw('54431.raw')
        Trans_Sample = LoadRaw('54435.raw')
        Trans_Direct = LoadRaw('54433.raw')
        Can = LoadRaw('54432.raw')
        CanTrans_Sample = LoadRaw('54434.raw')
        CanTrans_Direct = LoadRaw('54433.raw')

        SetCentre(324.765, 327.670)

        AssignSample(Sample, False)
        TransmissionSample(Trans_Sample, Trans_Direct, False)
        AssignCan(Can, False)
        TransmissionCan(CanTrans_Sample, CanTrans_Direct, False)

        WavRangeReduction(3, 9, DefaultTrans)
Exemple #7
0
    def _exec_single_foil_state_mode(self):
        """
        Execution path when a single foil state is requested
        """
        runs = self._get_runs()
        if len(runs) > 1:
            raise RuntimeError(
                "Single soil state mode does not currently support summing multiple files"
            )

        isis = config.getFacility("ISIS")
        inst_prefix = isis.instrument("VESUVIO").shortName()

        try:
            run = int(runs[0])
            run_str = inst_prefix + runs[0]
        except ValueError:
            run_str = runs[0]

        all_spectra = [item for sublist in self._spectra for item in sublist]
        LoadRaw(Filename=run_str,
                OutputWorkspace=SUMMED_WS,
                SpectrumList=all_spectra,
                EnableLogging=_LOGGING_)
        raw_group = mtd[SUMMED_WS]
        self._nperiods = raw_group.size()
        first_ws = raw_group[0]
        foil_out = WorkspaceFactory.create(first_ws)
        x_values = first_ws.readX(0)
        self.foil_out = foil_out

        foil_map = SpectraToFoilPeriodMap(self._nperiods)
        for ws_index, spectrum_no in enumerate(all_spectra):
            self._set_spectra_type(spectrum_no)
            foil_out_periods, foil_thin_periods, foil_thick_periods = self._get_foil_periods(
            )

            if self._diff_opt == "FoilOut":
                raw_grp_indices = foil_map.get_indices(spectrum_no,
                                                       foil_out_periods)
            elif self._diff_opt == "FoilIn":
                indices_thin = foil_map.get_indices(spectrum_no,
                                                    foil_thin_periods)
                indices_thick = foil_map.get_indices(spectrum_no,
                                                     foil_thin_periods)
                raw_grp_indices = indices_thin + indices_thick
            elif self._diff_opt == "FoilInOut":
                raw_grp_indices = range(0, self._nperiods)
            else:
                raise RuntimeError("Unknown single foil mode: %s." %
                                   (self._diff_opt))

            dataY = foil_out.dataY(ws_index)
            dataE = foil_out.dataE(ws_index)
            for group_index in raw_grp_indices:
                dataY += raw_group[group_index].readY(ws_index)
                dataE += np.square(raw_group[group_index].readE(ws_index))
            np.sqrt(dataE, dataE)
            foil_out.setX(ws_index, x_values)

        DeleteWorkspace(Workspace=SUMMED_WS)
        self._store_results()
Exemple #8
0
 def test_get_bin_indices_returns_a_numpy_ndarray_with_monitors(self):
     ConfigService.Instance().setString("default.facility", "ISIS")
     ws = LoadRaw("GEM40979", SpectrumMin=1, SpectrumMax=102)
     bin_indices = funcs.get_bin_indices(ws)
     self.assertTrue(isinstance(bin_indices, np.ndarray))
     ConfigService.Instance().setString("default.facility", " ")
 def test_get_bin_indices_returns_a_numpy_ndarray_with_monitors(self):
     ws = LoadRaw("GEM40979", SpectrumMin=1, SpectrumMax=102)
     bin_indices = funcs.get_bin_indices(ws)
     self.assertTrue(isinstance(bin_indices, np.ndarray))