コード例 #1
0
ファイル: data_model.py プロジェクト: stuartcampbell/mantid
 def load_files(self, filenames_string):
     self._last_added = []
     filenames = [name.strip() for name in filenames_string.split(",")]
     for filename in filenames:
         ws_name = self._generate_workspace_name(filename)
         if ws_name not in self._loaded_workspaces:
             try:
                 if not ADS.doesExist(ws_name):
                     ws = Load(filename, OutputWorkspace=ws_name)
                 else:
                     ws = ADS.retrieve(ws_name)
                 if ws.getNumberHistograms() == 1:
                     self._loaded_workspaces[ws_name] = ws
                     if ws_name not in self._bg_sub_workspaces:
                         self._bg_sub_workspaces[ws_name] = None
                     if ws_name not in self._bg_params:
                         self._bg_params[ws_name] = []
                     self._last_added.append(ws_name)
                 else:
                     logger.warning(
                         f"Invalid number of spectra in workspace {ws_name}. Skipping loading of file.")
             except RuntimeError as e:
                 logger.error(
                     f"Failed to load file: {filename}. Error: {e}. \n Continuing loading of other files.")
         else:
             logger.warning(f"File {ws_name} has already been loaded")
     self.update_log_workspace_group()
コード例 #2
0
ファイル: data_model.py プロジェクト: TakudzwaMakoni/mantid
 def load_files(self, filenames_string, xunit):
     self._last_added = []
     filenames = [name.strip() for name in filenames_string.split(",")]
     for filename in filenames:
         ws_name = self._generate_workspace_name(filename, xunit)
         if ws_name not in self._loaded_workspaces:
             try:
                 if not ADS.doesExist(ws_name):
                     ws = Load(filename, OutputWorkspace=ws_name)
                     if xunit != "TOF":
                         ConvertUnits(InputWorkspace=ws, OutputWorkspace=ws_name, Target=xunit)
                 else:
                     ws = ADS.retrieve(ws_name)
                 if ws.getNumberHistograms() == 1:
                     self._loaded_workspaces[ws_name] = ws
                     if ws_name not in self._background_workspaces:
                         self._background_workspaces[ws_name] = None
                     self._last_added.append(ws_name)
                     self.add_log_to_table(ws_name, ws)
                 else:
                     logger.warning(
                         f"Invalid number of spectra in workspace {ws_name}. Skipping loading of file.")
             except RuntimeError as e:
                 logger.error(
                     f"Failed to load file: {filename}. Error: {e}. \n Continuing loading of other files.")
         else:
             logger.warning(f"File {ws_name} has already been loaded")
コード例 #3
0
ファイル: SimpleAPILoadTest.py プロジェクト: trnielsen/mantid
 def test_Load_call_with_args_that_do_not_apply_executes_correctly(self):
     try:
         raw = Load('IRS21360.raw', SpectrumMax=1, Append=True)
     except RuntimeError:
         self.fail(
             "Load with a filename and extra args should not raise an exception"
         )
     self.assertEquals(1, raw.getNumberHistograms())
コード例 #4
0
 def test_Load_call_with_args_that_do_not_apply_executes_correctly(self):
     try:
         raw = Load('IRS21360.raw', SpectrumMax=1, Append=True)
     except RuntimeError:
         self.fail(
             "Load with a filename and extra args should not raise an exception"
         )
     self.assertEquals(1, raw.getNumberHistograms())
コード例 #5
0
ファイル: LoadTest.py プロジェクト: samueljackson92/mantid
    def test_sum_range_operator_with_step_sums_to_single_workspace(self):
        data = Load("TSC15352-15354:2.raw", OutputWorkspace = self.wsname)

        self.assertTrue(isinstance(data, MatrixWorkspace))
        self.assertEquals(149, data.getNumberHistograms())
        self.assertEquals(24974, data.blocksize())

        self.assertAlmostEqual(9.0, data.readX(2)[1], places = DIFF_PLACES)
        self.assertAlmostEqual(35640.0, data.readY(2)[1], places = DIFF_PLACES)
        self.assertAlmostEqual(188.78559267062727, data.readE(2)[1], places = DIFF_PLACES)
コード例 #6
0
ファイル: LoadTest.py プロジェクト: samueljackson92/mantid
    def test_sum_range_operator_sums_to_single_workspace(self):
        data = Load("TSC15352-15353.raw", OutputWorkspace = self.wsname)

        self.assertTrue(isinstance(data, MatrixWorkspace))
        self.assertEquals(149, data.getNumberHistograms())
        self.assertEquals(24974, data.blocksize())

        self.assertAlmostEqual(9.0, data.readX(2)[1], places = DIFF_PLACES)
        self.assertAlmostEqual(46352.0, data.readY(2)[1], places = DIFF_PLACES)
        self.assertAlmostEqual(215.29514625276622, data.readE(2)[1], places = DIFF_PLACES)
コード例 #7
0
ファイル: LoadTest.py プロジェクト: mantidproject/systemtests
    def test_sum_range_operator_with_step_sums_to_single_workspace(self):
        data = Load("TSC15352-15354:2.raw", OutputWorkspace=self.wsname)

        self.assertTrue(isinstance(data, MatrixWorkspace))
        self.assertEquals(149, data.getNumberHistograms())
        self.assertEquals(24974, data.blocksize())

        self.assertAlmostEqual(9.0, data.readX(2)[1], places=DIFF_PLACES)
        self.assertAlmostEqual(35640.0, data.readY(2)[1], places=DIFF_PLACES)
        self.assertAlmostEqual(188.78559267062727, data.readE(2)[1], places=DIFF_PLACES)
コード例 #8
0
ファイル: LoadTest.py プロジェクト: mantidproject/systemtests
    def test_sum_range_operator_sums_to_single_workspace(self):
        data = Load("TSC15352-15353.raw", OutputWorkspace=self.wsname)

        self.assertTrue(isinstance(data, MatrixWorkspace))
        self.assertEquals(149, data.getNumberHistograms())
        self.assertEquals(24974, data.blocksize())

        self.assertAlmostEqual(9.0, data.readX(2)[1], places=DIFF_PLACES)
        self.assertAlmostEqual(46352.0, data.readY(2)[1], places=DIFF_PLACES)
        self.assertAlmostEqual(215.29514625276622, data.readE(2)[1], places=DIFF_PLACES)
コード例 #9
0
ファイル: LoadTest.py プロジェクト: samueljackson92/mantid
    def test_plus_operator_sums_single_set_files(self):
        data = Load("TSC15352+15353.raw", OutputWorkspace = self.wsname)

        self.assertTrue(isinstance(data, MatrixWorkspace))
        self.assertEquals(149, data.getNumberHistograms())
        self.assertEquals(24974, data.blocksize())

        self.assertAlmostEqual(9.0, data.readX(2)[1], places = DIFF_PLACES)
        self.assertAlmostEqual(46352.0, data.readY(2)[1], places = DIFF_PLACES)
        self.assertAlmostEqual(215.29514625276622, data.readE(2)[1], places = DIFF_PLACES)

        deleted_names = ["TSC15352", "TSC15353"]
        for name in deleted_names:
            self.assertTrue(name not in AnalysisDataService)
コード例 #10
0
ファイル: LoadTest.py プロジェクト: mantidproject/systemtests
    def test_plus_operator_sums_single_set_files(self):
        data = Load("TSC15352+15353.raw", OutputWorkspace=self.wsname)

        self.assertTrue(isinstance(data, MatrixWorkspace))
        self.assertEquals(149, data.getNumberHistograms())
        self.assertEquals(24974, data.blocksize())

        self.assertAlmostEqual(9.0, data.readX(2)[1], places=DIFF_PLACES)
        self.assertAlmostEqual(46352.0, data.readY(2)[1], places=DIFF_PLACES)
        self.assertAlmostEqual(215.29514625276622, data.readE(2)[1], places=DIFF_PLACES)

        deleted_names = ["TSC15352", "TSC15353"]
        for name in deleted_names:
            self.assertTrue(name not in AnalysisDataService)
コード例 #11
0
ファイル: data_model.py プロジェクト: ethoeng/mantid
 def load_files(self, filenames_string):
     self._last_added = []
     filenames = [name.strip() for name in filenames_string.split(",")]
     for filename in filenames:
         ws_name = self._generate_workspace_name(filename)
         try:
             ws = Load(filename, OutputWorkspace=ws_name)
             if ws.getNumberHistograms() == 1:
                 self._loaded_workspaces[ws_name] = ws
                 self._last_added.append(ws_name)
             else:
                 logger.warning(
                     "Invalid number of spectra in workspace {}. Skipping loading of file."
                     .format(ws_name))
         except RuntimeError as e:
             logger.error(
                 "Failed to load file: {}. Error: {}. \n Continuing loading of other files."
                 .format(filename, e))
コード例 #12
0
    def PyExec(self):
        from mantid.simpleapi import Load, ConvertUnits, Rebin, DeleteWorkspace

        # Load file to workspace
        _tmpws = Load(Filename=self.getPropertyValue("Filename"))

        # Convert to units to DeltaE
        ei = self.getProperty("Ei").value
        _tmpws = ConvertUnits(InputWorkspace=_tmpws,
                              Target="DeltaE",
                              EMode="Direct",
                              EFixed=ei)

        # Rebin to requested units
        bins = self.getProperty("BinParams").value
        _tmpws = Rebin(InputWorkspace=_tmpws, Params=bins)

        # Create the new output workspace
        _summed = WorkspaceFactory.create(_tmpws, NVectors=1)
        # Set the X values for the new workspace
        _summed.setX(0, _tmpws.readX(0))

        # Sum the rows to a single row. Two methods demonstrated:

        #----- 1: Direct workspace access -----
        # Uses less memory as it avoids a copy of the data

        # readY returns read only array. dataY returns an array we can modify on the new workspace
        # note _summed at this point has all its y-values = 0
        sumy = _summed.dataY(0)  # initialise sumy with zeros
        for i in range(_tmpws.getNumberHistograms()):
            sumy += _tmpws.readY(i)

        #----- 2: Extract to numpy and sum ----
        # Uses more memory as extract copies to data (uncomment to see working)
        #yin = __tmpsws.extractY()
        #npsum = numpy.sum(yin,axis=0) # Axis 0 = summing down the columns
        # and put the data to the workspace
        #_summed.setY(0, npsum)

        # Store reference outside of algorithm
        self.setProperty("OutputWorkspace", _summed)

        DeleteWorkspace(_tmpws)
コード例 #13
0
    def PyExec(self):
        from mantid.simpleapi import Load, ConvertUnits, Rebin, DeleteWorkspace

        # Load file to workspace
        _tmpws = Load(Filename=self.getPropertyValue("Filename"))

        # Convert to units to DeltaE
        ei = self.getProperty("Ei").value
        _tmpws = ConvertUnits(InputWorkspace=_tmpws, Target="DeltaE", EMode="Direct", EFixed=ei)

        # Rebin to requested units
        bins = self.getProperty("BinParams").value
        _tmpws = Rebin(InputWorkspace=_tmpws, Params=bins)

        # Create the new output workspace
        _summed = WorkspaceFactory.create(_tmpws, NVectors=1)
        # Set the X values for the new workspace
        _summed.setX(0, _tmpws.readX(0))

        # Sum the rows to a single row. Two methods demonstrated:

        # ----- 1: Direct workspace access -----
        # Uses less memory as it avoids a copy of the data

        # readY returns read only array. dataY returns an array we can modify on the new workspace
        # note _summed at this point has all its y-values = 0
        sumy = _summed.dataY(0)  # initialise sumy with zeros
        for i in range(_tmpws.getNumberHistograms()):
            sumy += _tmpws.readY(i)

        # ----- 2: Extract to numpy and sum ----
        # Uses more memory as extract copies to data (uncomment to see working)
        # yin = __tmpsws.extractY()
        # npsum = numpy.sum(yin,axis=0) # Axis 0 = summing down the columns
        # and put the data to the workspace
        # _summed.setY(0, npsum)

        # Store reference outside of algorithm
        self.setProperty("OutputWorkspace", _summed)

        DeleteWorkspace(_tmpws)
コード例 #14
0
ファイル: SimpleAPILoadTest.py プロジェクト: trnielsen/mantid
 def test_Load_call_with_all_keyword_args_executes_correctly(self):
     raw = Load(Filename='IRS21360.raw', SpectrumMax=1)
     self.assertEquals(1, raw.getNumberHistograms())
コード例 #15
0
ファイル: SimpleAPILoadTest.py プロジェクト: trnielsen/mantid
 def test_Load_call_with_just_filename_executes_correctly(self):
     try:
         raw = Load('IRS21360.raw')
     except RuntimeError:
         self.fail("Load with a filename should not raise an exception")
     self.assertEquals(116, raw.getNumberHistograms())
コード例 #16
0
 def test_Load_call_with_all_keyword_args_executes_correctly(self):
     raw = Load(Filename='IRS21360.raw', SpectrumMax=1)
     self.assertEqual(1, raw.getNumberHistograms())
コード例 #17
0
 def test_Load_call_with_just_filename_executes_correctly(self):
     try:
         raw = Load('IRS21360.raw')
     except RuntimeError:
         self.fail("Load with a filename should not raise an exception")
     self.assertEqual(116, raw.getNumberHistograms())
コード例 #18
0
ファイル: SimpleAPILoadTest.py プロジェクト: trnielsen/mantid
 def test_Load_call_with_other_args_executes_correctly(self):
     try:
         raw = Load("IRS21360.raw", SpectrumMax=1)
     except RuntimeError:
         self.fail("Load with a filename and extra args should not raise an exception")
     self.assertEquals(1, raw.getNumberHistograms())