def test_retrieve_workspaces_accepts_unrolling_groups_argument(self):
        ws_names = ["test_retrieve_workspaces_1", "test_retrieve_workspaces_2"]
        for name in ws_names:
            self._run_createws(name)
        group_name = 'group1'
        alg = run_algorithm('GroupWorkspaces', InputWorkspaces=ws_names,
                            OutputWorkspace=group_name)

        workspaces = AnalysisDataService.retrieveWorkspaces([group_name], True)
        self.assertEquals(2, len(workspaces))
        self.assertTrue(isinstance(workspaces[0], MatrixWorkspace))
        self.assertTrue(isinstance(workspaces[1], MatrixWorkspace))
    def test_retrieve_workspaces_accepts_unrolling_groups_argument(self):
        ws_names = ["test_retrieve_workspaces_1", "test_retrieve_workspaces_2"]
        for name in ws_names:
            self._run_createws(name)
        group_name = 'group1'
        alg = run_algorithm('GroupWorkspaces', InputWorkspaces=ws_names,
                            OutputWorkspace=group_name)

        workspaces = AnalysisDataService.retrieveWorkspaces([group_name], True)
        self.assertEqual(2, len(workspaces))
        self.assertTrue(isinstance(workspaces[0], MatrixWorkspace))
        self.assertTrue(isinstance(workspaces[1], MatrixWorkspace))
Exemplo n.º 3
0
 def _get_workspace_names_to_save():
     """
     Get a list of the names of top level workspaces (workspaces not in groups) by getting every workspace,
     checking if the workspace is in a group, and removing it from the full list.
     :return: A list of the top level workspaces in the ADS
     """
     workspace_names = AnalysisDataService.getObjectNames()
     workspaces_in_ads = AnalysisDataService.retrieveWorkspaces(workspace_names)
     group_workspaces = [workspace for workspace in workspaces_in_ads if isinstance(workspace, WorkspaceGroup)]
     workspaces_in_groups_names = []
     for group_ws in group_workspaces:
         workspaces_in_groups_names.extend(group_ws.getNames())
     return [name for name in workspace_names if name not in workspaces_in_groups_names]
Exemplo n.º 4
0
def pcolormesh_from_names(names, fig=None):
    """
    Create a figure containing pcolor subplots

    :param names: A list of workspace names
    :param fig: An optional figure to contain the new plots. Its current contents will be cleared
    :returns: The figure containing the plots
    """
    try:
        return pcolormesh(AnalysisDataService.retrieveWorkspaces(names, unrollGroups=True),
                          fig=fig)
    except Exception as exc:
        LOGGER.warning(format(str(exc)))
        return None
Exemplo n.º 5
0
    def _filter_unaltered_workspaces(workspace_names):
        """
        Removes workspaces whose history contains Load and nothing else.
        :param workspace_names: a list of workspace names
        :return: the filtered list of workspace names.
        """
        workspaces = AnalysisDataService.retrieveWorkspaces(workspace_names)
        altered_workspace_names = []
        for ws in workspaces:
            history = ws.getHistory()
            if not (history.size() == 1 and history.getAlgorithm(0).name() == "Load"):
                altered_workspace_names.append(ws.name())

        return altered_workspace_names
Exemplo n.º 6
0
def pcolormesh_from_names(names, fig=None):
    """
    Create a figure containing pcolor subplots

    :param names: A list of workspace names
    :param fig: An optional figure to contain the new plots. Its current contents will be cleared
    :returns: The figure containing the plots
    """
    try:
        return pcolormesh(AnalysisDataService.retrieveWorkspaces(
            names, unrollGroups=True),
                          fig=fig)
    except Exception as exc:
        LOGGER.warning(format(str(exc)))
        return None
Exemplo n.º 7
0
    def test_retrieve_workspaces_uses_weak_ptrs(self):
        ws_names = ["test_retrieve_workspaces_1", "test_retrieve_workspaces_2"]
        for name in ws_names:
            self._run_createws(name)
        workspaces = AnalysisDataService.retrieveWorkspaces(ws_names)
        self.assertEqual(len(workspaces), 2)

        AnalysisDataService.remove(ws_names[0])
        # even though workspace has been deleted this should not affect workspaces size
        self.assertEqual(len(workspaces), 2)

        # check that the second workspace pointer in workspaces exists and can be used
        str(workspaces[1])

        # if a weak pointer has been used we expect a RuntimeError. Any other pointer will result in a different error
        with self.assertRaises(RuntimeError):
            str(workspaces[0])
Exemplo n.º 8
0
def pcolormesh_from_names(names, fig=None, ax=None):
    """
    Create a figure containing pcolor subplots

    :param names: A list of workspace names
    :param fig: An optional figure to contain the new plots. Its current contents will be cleared
    :param ax: An optional axis instance on which to put new plots. It's current contents will be cleared
    :returns: The figure containing the plots
    """
    try:
        if ax:
            pcolormesh_on_axis(ax, AnalysisDataService.retrieve(names[0]))
            fig.canvas.draw()
            fig.show()
            return fig
        else:
            return pcolormesh(AnalysisDataService.retrieveWorkspaces(names, unrollGroups=True),
                              fig=fig)
    except Exception as exc:
        LOGGER.warning(format(str(exc)))
        return None
def add_to_group(instrument, extension):
    str_names = AnalysisDataService.getObjectNames()
    # only group things for the current instrument
    ws_list =  AnalysisDataService.retrieveWorkspaces(str_names)

    #just the groups
    groups = [ws for ws in ws_list if ws.isGroup()]

    # just the workspaces
    def string_name(ws):
        if isinstance(ws, str):
            return ws
        return ws.name()

    names = [string_name(ws) for ws in ws_list if safe_to_add_to_group(ws, instrument, groups, extension)]
    # make sure we include the groups that we already have in the ADS
    group_names = {key.name():[] for key in groups}
    # put ws into groups
    for name in names:
        run = get_run_number_from_workspace_name(name, instrument)
        tmp = instrument+run
        # check the names are not already group workspaces
        if tmp in list(group_names.keys()):
            group_names[tmp] += [name]
        else:
            group_names[tmp] = [name]

    # add to the groups that already exist
    for group in groups:
        if group.name() in group_names.keys():
            add_list_to_group(group_names[group.name()], group)

    # create new groups
    for group in group_names.keys():
        if group not in [group.name() for group in groups] :
            make_group(group_names[group], group)
 def test_retrieve_workspaces_respects_default_not_unrolling_groups(self):
     ws_names = ["test_retrieve_workspaces_1", "test_retrieve_workspaces_2"]
     for name in ws_names:
         self._run_createws(name)
     workspaces = AnalysisDataService.retrieveWorkspaces(ws_names)
     self.assertEqual(2, len(workspaces))
Exemplo n.º 11
0
 def test_retrieve_workspaces_respects_default_not_unrolling_groups(self):
     ws_names = ["test_retrieve_workspaces_1", "test_retrieve_workspaces_2"]
     for name in ws_names:
         self._run_createws(name)
     workspaces = AnalysisDataService.retrieveWorkspaces(ws_names)
     self.assertEquals(2, len(workspaces))