Ejemplo n.º 1
0
    def test_history(self):
        ws_name = "GEM38370_Focussed_Legacy"
        file_name = FileFinder.getFullPath(ws_name + ".nxs")
        Load(file_name, OutputWorkspace=ws_name)

        ws = mtd[ws_name]
        history = ws.getHistory()

        self.assertEquals(history.empty(), False)
        self.assertEquals(history.size(), 4)

        alg_hists = history.getAlgorithmHistories()
        self.assertEquals(len(alg_hists), 4)
        self.assertEquals(alg_hists[0].name(), "LoadRaw")
        self.assertEquals(alg_hists[1].name(), "AlignDetectors")
        self.assertEquals(alg_hists[2].name(), "DiffractionFocussing")
        self.assertEquals(alg_hists[3].name(), "Load")

        self.assertEquals(history.getAlgorithmHistory(0).name(), "LoadRaw")
        self.assertEquals(history.getAlgorithmHistory(1).name(), "AlignDetectors")
        self.assertEquals(history.getAlgorithmHistory(2).name(), "DiffractionFocussing")
        self.assertEquals(history.getAlgorithmHistory(3).name(), "Load")

        alg = history.lastAlgorithm()
        self.assertEquals(alg.name(), "Load")

        alg = history.getAlgorithm(history.size()-1)
        self.assertEquals(alg.name(), "Load")
Ejemplo n.º 2
0
    def test_history(self):
        ws_name = "GEM38370_Focussed_Legacy"
        file_name = FileFinder.getFullPath(ws_name + ".nxs")
        Load(file_name, OutputWorkspace=ws_name)

        ws = mtd[ws_name]
        history = ws.getHistory()

        self.assertEqual(history.empty(), False)
        self.assertEqual(history.size(), 4)

        alg_hists = history.getAlgorithmHistories()
        self.assertEqual(len(alg_hists), 4)
        self.assertEqual(alg_hists[0].name(), "LoadRaw")
        self.assertEqual(alg_hists[1].name(), "AlignDetectors")
        self.assertEqual(alg_hists[2].name(), "DiffractionFocussing")
        self.assertEqual(alg_hists[3].name(), "Load")

        self.assertEqual(history.getAlgorithmHistory(0).name(), "LoadRaw")
        self.assertEqual(
            history.getAlgorithmHistory(1).name(), "AlignDetectors")
        self.assertEqual(
            history.getAlgorithmHistory(2).name(), "DiffractionFocussing")
        self.assertEqual(history.getAlgorithmHistory(3).name(), "Load")

        alg = history.lastAlgorithm()
        self.assertEqual(alg.name(), "Load")

        alg = history.getAlgorithm(history.size() - 1)
        self.assertEqual(alg.name(), "Load")
Ejemplo n.º 3
0
 def test_get_history_chained_calls(self):
     ws_name = "GEM38370_Focussed_Legacy"
     file_name = FileFinder.getFullPath(ws_name + ".nxs")
     Load(file_name, OutputWorkspace=ws_name)
     ws = mtd[ws_name]
     load_filename = ws.getHistory().lastAlgorithm().getProperty(
         "Filename").value
     self.assertEqual(file_name, load_filename[0])
Ejemplo n.º 4
0
 def find_all_from_query(self, query_string):
     try:
         results = FileFinder.findRuns(query_string)
         return ('', [self.find_from_file_path(file_path)
                      for file_path in results])
     except RuntimeError:
         return ('', [])
     except ValueError as ex:
         return (str(ex), [])
Ejemplo n.º 5
0
 def find_all_from_query(self, query_string):
     try:
         results = FileFinder.findRuns(query_string)
         return ('', [
             self.find_from_file_path(file_path) for file_path in results
         ])
     except RuntimeError:
         return ('', [])
     except ValueError as ex:
         return (str(ex), [])
Ejemplo n.º 6
0
def run_file(run_number: Union[str, int],
             instrument: Optional[str] = None,
             oncat: Optional[bool] = True) -> Optional[None]:
    r"""
    @brief Test whether the file for a run number exists.
    @details Search first the datasearch directories and if file is not found, use the locations
    provided by ONCat
    @param run_number : just the bare run number, e.g. 12345
    @param instrument : if None, retrieve the default instrument from the configuration service
    @param oncat : whether to use the ONCat archiving service
    @returns None if file not found, otherwise absolute path to events file
    """
    if isinstance(
            run_number,
            str):  # verify run_number represents a positive integer number
        try:
            int(run_number)
        except ValueError:
            raise ValueError(f'{run_number} does not represent a number')
        assert int(
            run_number
        ) > 0, f'{run_number} does not represent an positive integer number'
    if instrument is None:
        instrument = config['default.instrument']
    root_name = f'{instrument}_{run_number}'
    # check in 'datasearch.directories'
    for extension in ('.h5', '.nxs', '.nxs.h5'):
        file_path = FileFinder.getFullPath(root_name + extension)
        if Path(file_path).is_file():
            return file_path
    # check via locations provided by ONCat
    if oncat:
        try:
            for option in FileFinder.findRuns(root_name):
                if Path(option).is_file():
                    return option
        except RuntimeError:
            return None  # no suggestions found
    return None
Ejemplo n.º 7
0
    def test_history(self):
        ws_name = "GEM38370_Focussed_Legacy"
        file_name = FileFinder.getFullPath(ws_name + ".nxs")
        Load(file_name, OutputWorkspace=ws_name)

        ws = mtd[ws_name]
        history = ws.getHistory()
        alg_hist = history.getAlgorithmHistory(0)

        self.assertEquals(alg_hist.name(), "LoadRaw")

        properties = alg_hist.getProperties()
        self.assertEquals(len(properties), 7)
        self.assertEquals(properties[0].name(), "Filename")
        self.assertEquals(
            properties[0].value(),
            "/home/dmn58364/Mantid/trunk/Test/Data/GEM38370.raw")
        self.assertEquals(properties[0].isDefault(), False)
        self.assertEquals(properties[0].direction(), 0)

        self.assertEquals(properties[1].name(), "OutputWorkspace")
        self.assertEquals(properties[1].value(), "GEM38370")
        self.assertEquals(properties[1].isDefault(), False)
        self.assertEquals(properties[1].direction(), 1)

        self.assertEquals(properties[2].name(), "SpectrumMin")
        self.assertEquals(properties[2].value(), '1')
        self.assertEquals(properties[2].isDefault(), True)
        self.assertEquals(properties[2].direction(), 0)

        self.assertEquals(properties[3].name(), "SpectrumMax")
        self.assertEquals(properties[3].value(), '2147483632')
        self.assertEquals(properties[3].isDefault(), True)
        self.assertEquals(properties[3].direction(), 0)

        self.assertEquals(properties[4].name(), "SpectrumList")
        self.assertEquals(properties[4].value(), "")
        self.assertEquals(properties[4].isDefault(), True)
        self.assertEquals(properties[4].direction(), 0)

        self.assertEquals(properties[5].name(), "Cache")
        self.assertEquals(properties[5].value(), "If Slow")
        self.assertEquals(properties[5].isDefault(), True)
        self.assertEquals(properties[5].direction(), 0)

        self.assertEquals(properties[6].name(), "LoadLogFiles")
        self.assertEquals(properties[6].value(), '1')
        self.assertEquals(properties[6].isDefault(), True)
        self.assertEquals(properties[6].direction(), 0)
Ejemplo n.º 8
0
 def _load_current_state(self, file_information, row_user_file):
     if row_user_file:
         # Has a custom user file so ignore any settings from GUI
         user_file_path = FileFinder.getFullPath(row_user_file)
         if not os.path.exists(user_file_path):
             raise ValueError(
                 f"The user path {user_file_path}\n"
                 " does not exist. Make sure a valid user file has been specified."
             )
         state = FileLoading.load_user_file(
             user_file_path, file_information=file_information)
         gui_state = StateGuiModel(state)
     else:
         # We want to copy our master GUI state to set any row options (see prototype pattern)
         gui_state = copy.deepcopy(self._state_gui_model)
     return gui_state
Ejemplo n.º 9
0
    def test_history(self):
        ws_name = "GEM38370_Focussed_Legacy"
        file_name = FileFinder.getFullPath(ws_name + ".nxs")
        Load(file_name, OutputWorkspace=ws_name)

        ws = mtd[ws_name]
        history = ws.getHistory()
        alg_hist = history.getAlgorithmHistory(0)

        self.assertEquals(alg_hist.name(), "LoadRaw")

        properties = alg_hist.getProperties()
        self.assertEquals(len(properties), 7)
        self.assertEquals(properties[0].name(), "Filename")
        self.assertEquals(properties[0].value(), "/home/dmn58364/Mantid/trunk/Test/Data/GEM38370.raw")
        self.assertEquals(properties[0].isDefault(), False)
        self.assertEquals(properties[0].direction(), 0)

        self.assertEquals(properties[1].name(), "OutputWorkspace")
        self.assertEquals(properties[1].value(), "GEM38370")
        self.assertEquals(properties[1].isDefault(), False)
        self.assertEquals(properties[1].direction(), 1)

        self.assertEquals(properties[2].name(), "SpectrumMin")
        self.assertEquals(properties[2].value(), '1')
        self.assertEquals(properties[2].isDefault(), True)
        self.assertEquals(properties[2].direction(), 0)

        self.assertEquals(properties[3].name(), "SpectrumMax")
        self.assertEquals(properties[3].value(), '2147483632')
        self.assertEquals(properties[3].isDefault(), True)
        self.assertEquals(properties[3].direction(), 0)

        self.assertEquals(properties[4].name(), "SpectrumList")
        self.assertEquals(properties[4].value(), "")
        self.assertEquals(properties[4].isDefault(), True)
        self.assertEquals(properties[4].direction(), 0)

        self.assertEquals(properties[5].name(), "Cache")
        self.assertEquals(properties[5].value(), "If Slow")
        self.assertEquals(properties[5].isDefault(), True)
        self.assertEquals(properties[5].direction(), 0)

        self.assertEquals(properties[6].name(), "LoadLogFiles")
        self.assertEquals(properties[6].value(), '1')
        self.assertEquals(properties[6].isDefault(), True)
        self.assertEquals(properties[6].direction(), 0)
Ejemplo n.º 10
0
def getFilePath(run,ext,instr):
    path = None
    fname = None
    if(os.path.isfile(run)):
        #using full file path
        path = run
        #base name less extension
        base = os.path.basename(path)
        fname = os.path.splitext(base)[0]
    else:
        #using run number
        path = FileFinder.getFullPath(instr + "_" + run + ext)
        fname = instr + "_" + run

    if path:
        return path, fname
    else:
        error = 'ERROR *** Could not find ' + ext + ' file: ' + fname
        sys.exit(error)
Ejemplo n.º 11
0
def getFilePath(run, ext, instr):
    path = None
    fname = None
    if os.path.isfile(run):
        # using full file path
        path = run
        # base name less extension
        base = os.path.basename(path)
        fname = os.path.splitext(base)[0]
    else:
        # using run number
        path = FileFinder.getFullPath(instr + "_" + run + ext)
        fname = instr + "_" + run

    if path:
        return path, fname
    else:
        error = 'ERROR *** Could not find ' + ext + ' file: ' + fname
        sys.exit(error)
Ejemplo n.º 12
0
    def runTest(self):
        UseCompatibilityMode()
        SANS2D()
        Set1D()
        Detector("rear-detector")
        MaskFile('Mask_SANS2D_Batch_Toml.toml')
        Gravity(True)

        csv_file = FileFinder.getFullPath('SANS2D_periodTests.csv')

        BatchReduce(csv_file,
                    'nxs',
                    plotresults=False,
                    saveAlgs={
                        'SaveCanSAS1D': 'xml',
                        'SaveNexus': 'nxs'
                    })
        xml_path = os.path.join(
            config['defaultsave.directory'],
            '5512p7_SANS2DBatch_p7rear_1D_2.0_14.0Phi-45.0_45.0.xml')
        if os.path.exists(xml_path):
            os.remove(xml_path)
Ejemplo n.º 13
0
    def runTest(self):
        UseCompatibilityMode()
        LOQ()

        csv_file = FileFinder.getFullPath("toml_v1_file_m4.csv")
        BatchReduce(csv_file, 'raw')