示例#1
0
文件: __init__.py 项目: mducle/mantid
def plot2D(source, style=DEFAULT_2D_STYLE, window=None):
    """Open a 2D plot of the given workspace(s)

    Produces a 2D histogram for each of the given workspaces

    Args:
        source: workspace or name of a workspace
        style: Indicates the type of plot required. Default=ColorMap
        window: window used for plotting. If None a new one will be created
    Returns:
        If a single workspace is specified then the handle is returned, otherwise a list
        of handles for each new window is returned
    """
    names = getWorkspaceNames(source)
    if len(names) == 0:
        raise ValueError("No workspace names given to plot")

    # Unwrap the window object, if any specified
    if window != None:
        window = window._getHeldObject()

    handles = []
    cfunc = _qti.app.mantidUI.drawSingleColorFillPlot
    for name in names:
        g = proxies.Graph(threadsafe_call(cfunc, name, style, window))
        if g:
            handles.append(g)
        else:
            raise RuntimeError("Cannot create graph from workspace '%s'" % name)

    if len(handles) == 1:
        return handles[0]
    else:
        return handles
示例#2
0
def getSliceViewer(source, label=""):
    """Retrieves a handle to a previously-open SliceViewerWindow.
    This allows you to get a handle on, e.g., a SliceViewer that was open
    by the MultiSlice view in VATES Simple Interface.
    Will raise an exception if not found.

    Args:
        source :: name of the workspace that was open
        label :: additional label string that was used to identify the window.

    Returns:
        a handle to the SliceViewerWindow object that was created before.
    """
    import mantidqtpython
    workspace_names = getWorkspaceNames(source)
    if len(workspace_names) != 1:
        raise Exception("Please specify only one workspace.")
    else:
        svw = threadsafe_call(
            mantidqtpython.MantidQt.Factory.WidgetFactory.Instance().
            getSliceViewerWindow, workspace_names[0], label)
        if svw is not None:
            return proxies.SliceViewerWindowProxy(svw)
        else:
            return None
示例#3
0
def plot2D(source, style=DEFAULT_2D_STYLE, window=None):
    """Open a 2D plot of the given workspace(s)

    Produces a 2D histogram for each of the given workspaces

    Args:
        source: workspace or name of a workspace
        style: Indicates the type of plot required. Default=ColorMap
        window: window used for plotting. If None a new one will be created
    Returns:
        If a single workspace is specified then the handle is returned, otherwise a list
        of handles for each new window is returned
    """
    names = getWorkspaceNames(source)
    if len(names) == 0:
        raise ValueError("No workspace names given to plot")

    # Unwrap the window object, if any specified
    if window is not None:
        window = window._getHeldObject()

    handles = []
    cfunc = _qti.app.mantidUI.drawSingleColorFillPlot
    for name in names:
        g = proxies.Graph(threadsafe_call(cfunc, name, style, window))
        if g:
            handles.append(g)
        else:
            raise RuntimeError("Cannot create graph from workspace '%s'" %
                               name)

    if len(handles) == 1:
        return handles[0]
    else:
        return handles
示例#4
0
def plotSubplots(source,
                 indices,
                 distribution=mantidqtpython.MantidQt.DistributionDefault,
                 error_bars=False,
                 window=None):
    """Open a tiled plot.

    This plots one or more spectra, with X as the bin boundaries,
    and Y as the counts in each bin.

    If one workspace, each spectrum gets its own tile.
    Otherwise, each workspace gets its own tile.

    Args:
        source: list of workspace names
        indices: workspace index, or tuple or list of workspace indices to plot
        distribution: whether or not to plot as a distribution
        error_bars: bool, set to True to add error bars.
        window: window used for plotting. If None a new one will be created
    Returns:
        A handle to window if one was specified, otherwise a handle to the created one. None in case of error.
    """

    workspace_names = getWorkspaceNames(source)

    # Deal with workspace groups that may contain various types:
    # Only want to plot MatrixWorkspaces
    to_plot = []
    for name in workspace_names:
        if isinstance(mantid.api.mtd[name], mantid.api.MatrixWorkspace):
            to_plot.append(name)

    __checkPlotWorkspaces(to_plot)
    # check spectrum indices
    index_list = __getWorkspaceIndices(indices)
    if len(index_list) == 0:
        raise ValueError("No spectrum indices given")
    for idx in index_list:
        if idx < 0:
            raise ValueError("Wrong spectrum index (<0): %d" % idx)
    for name in to_plot:
        max_spec = workspace(name).getNumberHistograms() - 1
        for idx in index_list:
            if idx > max_spec:
                raise ValueError(
                    "Wrong spectrum index for workspace '%s': %d, which is bigger than the"
                    " number of spectra in this workspace - 1 (%d)" %
                    (name, idx, max_spec))

    # Unwrap the window object, if any specified
    if window is not None:
        window = window._getHeldObject()

    graph = proxies.Graph(
        threadsafe_call(_qti.app.mantidUI.plotSubplots, to_plot, index_list,
                        distribution, error_bars, window))
    if graph._getHeldObject() == None:
        raise RuntimeError("Cannot create graph, see log for details.")
    else:
        return graph
示例#5
0
def plotBin(source,
            indices,
            error_bars=False,
            type=-1,
            window=None,
            clearWindow=False,
            waterfall=False):
    """Create a 1D Plot of bin count vs spectrum in a workspace.

    This puts the spectrum number as the X variable, and the
    count in the particular bin # (in 'indices') as the Y value.

    If indices is a tuple or list, then several curves are created, one
    for each bin index.

    Args:
        source: workspace or name of a workspace
        indices: bin number(s) to plot
        error_bars: bool, set to True to add error bars.
        type: Plot style
        window: window used for plotting. If None a new one will be created
        clearWindow: if is True, the window specified will be cleared before adding new curve
        waterfall: if True, plot as a waterfall if there is more than 1 curve
    Returns:
        A handle to window if one was specified, otherwise a handle to the created one. None in case of error.
    """
    workspace_names = getWorkspaceNames(source)
    __checkPlotWorkspaces(workspace_names)
    index_list = __getWorkspaceIndices(indices)
    if len(index_list) == 0:
        raise ValueError("No indices given")

    for idx in index_list:
        if idx < 0:
            raise ValueError("Wrong bin index (<0): %d" % idx)
    for name in workspace_names:
        max_bin = workspace(name).blocksize() - 1
        for idx in index_list:
            if idx > max_bin:
                raise ValueError(
                    "Wrong bin index for workspace '%s': %d, which is bigger than the"
                    " number of bins in this workspace - 1 (%d)" %
                    (name, idx, max_bin))

    # Unwrap the window object, if any specified
    if window is not None:
        window = window._getHeldObject()

    graph = proxies.Graph(
        threadsafe_call(_qti.app.mantidUI.plot1D, workspace_names, index_list,
                        False, mantidqtpython.MantidQt.DistributionDefault,
                        error_bars, type, window, clearWindow, waterfall))
    if graph._getHeldObject() == None:
        raise RuntimeError("Cannot create graph, see log for details.")
    else:
        return graph
示例#6
0
def plotSlice(source,
              label="",
              xydim=None,
              slicepoint=None,
              colormin=None,
              colormax=None,
              colorscalelog=False,
              normalization=1,
              limits=None,
              **kwargs):
    """Opens the SliceViewer with the given MDWorkspace(s).

    Args:
        source :: one workspace, or a list of workspaces

    Optional Keyword Args:
        label :: label for the window title
        xydim :: indexes or names of the dimensions to plot, as an (X,Y) list or tuple. See `SliceViewer::setXYDim()`
        slicepoint :: list with the slice point in each dimension.Must be the same length as the number of \
dimensions of the workspace. See SliceViewer::setSlicePoint()
        colormin :: value of the minimum color in the scale. See `SliceViewer::setColorScaleMin()`
        colormax :: value of the maximum color in the scale. See `SliceViewer::setColorScaleMax()`
        colorscalelog :: value of the maximum color in the scale. See `SliceViewer::setColorScaleLog()`
        limits :: list with the (xleft, xright, ybottom, ytop) limits to the view to show. See `SliceViewer::setXYLimits()`
        normalization :: 0=none; 1=volume (default); 2=# of events.

    Returns:
        a (list of) handle(s) to the SliceViewerWindow widgets that were open.
        Use SliceViewerWindow.getSlicer() to get access to the functions of the
        SliceViewer, e.g. setting the view and slice point.
    """
    workspace_names = getWorkspaceNames(source)
    __checkPlotSliceWorkspaces(workspace_names)

    # Make a list of widgets to return
    out = []
    for wsname in workspace_names:
        window = __doSliceViewer(wsname,
                                 label=label,
                                 xydim=xydim,
                                 slicepoint=slicepoint,
                                 colormin=colormin,
                                 colormax=colormax,
                                 colorscalelog=colorscalelog,
                                 limits=limits,
                                 normalization=normalization,
                                 **kwargs)
        pxy = proxies.SliceViewerWindowProxy(window)
        out.append(pxy)

    # Return the widget alone if only 1
    if len(out) == 1:
        return out[0]
    else:
        return out
示例#7
0
def plotSpectrum(source,
                 indices,
                 distribution=mantidqtpython.MantidQt.DistributionDefault,
                 error_bars=False,
                 type=-1,
                 window=None,
                 clearWindow=False,
                 waterfall=False):
    """Open a 1D Plot of a spectrum in a workspace.

    This plots one or more spectra, with X as the bin boundaries,
    and Y as the counts in each bin.

    Args:
        source: workspace or name of a workspace
        indices: workspace index, or tuple or list of workspace indices to plot
        error_bars: bool, set to True to add error bars.
        type: curve style for plot (-1: unspecified; 0: line, default; 1: scatter/dots)
        window: window used for plotting. If None a new one will be created
        clearWindow: if is True, the window specified will be cleared before adding new curve
        waterfall: if True, plot as a waterfall if there is more than 1 curve
    Returns:
        A handle to window if one was specified, otherwise a handle to the created one. None in case of error.
    """
    workspace_names = getWorkspaceNames(source)
    __checkPlotWorkspaces(workspace_names)
    # check spectrum indices
    index_list = __getWorkspaceIndices(indices)
    if len(index_list) == 0:
        raise ValueError("No spectrum indices given")
    for idx in index_list:
        if idx < 0:
            raise ValueError("Wrong spectrum index (<0): %d" % idx)
    for name in workspace_names:
        max_spec = workspace(name).getNumberHistograms() - 1
        for idx in index_list:
            if idx > max_spec:
                raise ValueError(
                    "Wrong spectrum index for workspace '%s': %d, which is bigger than the"
                    " number of spectra in this workspace - 1 (%d)" %
                    (name, idx, max_spec))

    # Unwrap the window object, if any specified
    if window is not None:
        window = window._getHeldObject()

    graph = proxies.Graph(
        threadsafe_call(_qti.app.mantidUI.plot1D, workspace_names, index_list,
                        True, distribution, error_bars, type, window,
                        clearWindow, waterfall))
    if graph._getHeldObject() == None:
        raise RuntimeError("Cannot create graph, see log for details.")
    else:
        return graph
示例#8
0
def plotSubplots(source, indices, distribution = mantidqtpython.MantidQt.DistributionDefault, error_bars=False, window=None):
    """Open a tiled plot.

    This plots one or more spectra, with X as the bin boundaries,
    and Y as the counts in each bin.
    
    If one workspace, each spectrum gets its own tile.
    Otherwise, each workspace gets its own tile.

    Args:
        source: list of workspace names
        indices: workspace index, or tuple or list of workspace indices to plot
        distribution: whether or not to plot as a distribution
        error_bars: bool, set to True to add error bars.
        window: window used for plotting. If None a new one will be created
    Returns:
        A handle to window if one was specified, otherwise a handle to the created one. None in case of error.
    """

    workspace_names = getWorkspaceNames(source)
   
    # Deal with workspace groups that may contain various types:
    # Only want to plot MatrixWorkspaces
    to_plot = []
    for name in workspace_names:
        if isinstance(mantid.api.mtd[name], mantid.api.MatrixWorkspace):
            to_plot.append(name)
            
    __checkPlotWorkspaces(to_plot)
    # check spectrum indices
    index_list = __getWorkspaceIndices(indices)
    if len(index_list) == 0:
        raise ValueError("No spectrum indices given")
    for idx in index_list:
        if idx < 0:
            raise ValueError("Wrong spectrum index (<0): %d" % idx)
    for name in to_plot:
        max_spec = workspace(name).getNumberHistograms() - 1
        for idx in index_list:
            if idx > max_spec:
                raise ValueError("Wrong spectrum index for workspace '%s': %d, which is bigger than the"
                                 " number of spectra in this workspace - 1 (%d)" % (name, idx, max_spec))
    
    # Unwrap the window object, if any specified
    if window != None:
        window = window._getHeldObject()
    
    graph = proxies.Graph(threadsafe_call(_qti.app.mantidUI.plotSubplots,
                                          to_plot, index_list, distribution, error_bars, window))
    if graph._getHeldObject() == None:
        raise RuntimeError("Cannot create graph, see log for details.")
    else:
        return graph
示例#9
0
文件: __init__.py 项目: mducle/mantid
def createDetectorTable(source):
    try:
        import mantidqtpython
    except:
        print("Could not find module mantidqtpython. Cannot open the detector table.")
        return

    workspace_names = getWorkspaceNames(source)

    if len(workspace_names) != 1:
        raise Exception("Please specify only one workspace.")
    else:
        return new_proxy(proxies.MDIWindow, _qti.app.mantidUI.createDetectorTable, workspace_names[0])
示例#10
0
def createDetectorTable(source):
    try:
        import mantidqtpython
    except:
        print "Could not find module mantidqtpython. Cannot open the detector table."
        return

    workspace_names = getWorkspaceNames(source)

    if len(workspace_names) != 1:
        raise Exception("Please specify only one workspace.")
    else:
        return new_proxy(proxies.MDIWindow, _qti.app.mantidUI.createDetectorTable, workspace_names[0])
示例#11
0
def plotMD(source,
           plot_axis=-2,
           normalization=DEFAULT_MD_NORMALIZATION,
           error_bars=False,
           window=None,
           clearWindow=False):
    """Open a 1D plot of a MDWorkspace.

    Args:
        source: Workspace(s) to plot
        plot_axis: Index of the plot axis (defaults to auto-select)
        normalization: Type of normalization required (defaults to volume, options available:
        MDNormalization.NoNormalization, MDNormalization.NumEventsNormalization, and
        MDNormalization.VolumeNormalization).
        error_bars: Flag for error bar plotting.
        window: window used for plotting. If None a new one will be created
        clearWindow: if is True, the window specified will be cleared before adding new curve
    Returns:
        A handle to the matrix containing the image data.
    """
    workspace_names = getWorkspaceNames(source)
    __checkPlotMDWorkspaces(workspace_names)

    for name in workspace_names:
        non_integrated_dims = mantid.api.mtd[name].getNonIntegratedDimensions()
        if not len(non_integrated_dims) == 1:
            raise ValueError(
                "'%s' must have a single non-integrated dimension in order to be rendered via plotMD"
                % name)

    # check axis index
    for name in workspace_names:
        ws = workspace(name)
        if hasattr(ws, "axes"):
            max_axis = workspace(name).axes()
            # see choice in MantidQwtIMDWorkspaceData::setPlotAxisChoice, -2: auto, -1: distance
            if plot_axis < -2 or plot_axis > max_axis:
                raise ValueError(
                    "Incorrect axis index given for workspace '%s': %d, should be < %d"
                    % (name, plot_axis, max_axis))

    # Unwrap the window object, if any specified
    if window is not None:
        window = window._getHeldObject()

    graph = proxies.Graph(
        threadsafe_call(_qti.app.mantidUI.plotMDList, workspace_names,
                        plot_axis, normalization, error_bars, window,
                        clearWindow))

    return graph
示例#12
0
def plotSlice(source, label="", xydim=None, slicepoint=None,
              colormin=None, colormax=None, colorscalelog=False,
              normalization=1,
              limits=None, **kwargs):
    """Opens the SliceViewer with the given MDWorkspace(s).

    Args:
        source :: one workspace, or a list of workspaces

    Optional Keyword Args:
        label :: label for the window title
        xydim :: indexes or names of the dimensions to plot, as an (X,Y) list or tuple. See SliceViewer::setXYDim()
        slicepoint :: list with the slice point in each dimension.  Must be the same length as the number of dimensions of the workspace. See SliceViewer::setSlicePoint()
        colormin :: value of the minimum color in the scale. See SliceViewer::setColorScaleMin()
        colormax :: value of the maximum color in the scale. See SliceViewer::setColorScaleMax()
        colorscalelog :: value of the maximum color in the scale. See SliceViewer::setColorScaleLog()
        limits :: list with the (xleft, xright, ybottom, ytop) limits to the view to show. See SliceViewer::setXYLimits()
        normalization :: 0=none; 1=volume (default); 2=# of events.

    Returns:
        a (list of) handle(s) to the SliceViewerWindow widgets that were open.
        Use SliceViewerWindow.getSlicer() to get access to the functions of the
        SliceViewer, e.g. setting the view and slice point.
    """
    workspace_names = getWorkspaceNames(source)
    __checkPlotSliceWorkspaces(workspace_names)

    try:
        import mantidqtpython
    except:
        print "Could not find module mantidqtpython. Cannot open the SliceViewer."
        return

    # Make a list of widgets to return
    out = []
    for wsname in workspace_names:
        window = __doSliceViewer(wsname, label=label,
                                 xydim=xydim, slicepoint=slicepoint, colormin=colormin,
                                 colormax=colormax, colorscalelog=colorscalelog, limits=limits,
                                 normalization=normalization,
                                 **kwargs)
        pxy = proxies.SliceViewerWindowProxy(window)
        out.append(pxy)

    # Return the widget alone if only 1
    if len(out) == 1:
        return out[0]
    else:
        return out
示例#13
0
文件: __init__.py 项目: mducle/mantid
def plotBin(source, indices, error_bars=False, type=-1, window=None, clearWindow=False,
            waterfall=False):
    """Create a 1D Plot of bin count vs spectrum in a workspace.

    This puts the spectrum number as the X variable, and the
    count in the particular bin # (in 'indices') as the Y value.

    If indices is a tuple or list, then several curves are created, one
    for each bin index.

    Args:
        source: workspace or name of a workspace
        indices: bin number(s) to plot
        error_bars: bool, set to True to add error bars.
        type: Plot style
        window: window used for plotting. If None a new one will be created
        clearWindow: if is True, the window specified will be cleared before adding new curve
        waterfall: if True, plot as a waterfall if there is more than 1 curve
    Returns:
        A handle to window if one was specified, otherwise a handle to the created one. None in case of error.
    """
    workspace_names = getWorkspaceNames(source)
    __checkPlotWorkspaces(workspace_names)
    index_list = __getWorkspaceIndices(indices)
    if len(index_list) == 0:
        raise ValueError("No indices given")

    for idx in index_list:
        if idx < 0:
            raise ValueError("Wrong bin index (<0): %d" % idx)
    for name in workspace_names:
        max_bin = workspace(name).blocksize() - 1
        for idx in index_list:
            if idx > max_bin:
                raise ValueError("Wrong bin index for workspace '%s': %d, which is bigger than the"
                                 " number of bins in this workspace - 1 (%d)" % (name, idx, max_bin))

    # Unwrap the window object, if any specified
    if window != None:
        window = window._getHeldObject()

    graph = proxies.Graph(threadsafe_call(_qti.app.mantidUI.plot1D,
                                          workspace_names, index_list, False, mantidqtpython.MantidQt.DistributionDefault, error_bars,
                                          type, window, clearWindow, waterfall))
    if graph._getHeldObject() == None:
        raise RuntimeError("Cannot create graph, see log for details.")
    else:
        return graph
示例#14
0
文件: __init__.py 项目: mducle/mantid
def plotSpectrum(source, indices, distribution = mantidqtpython.MantidQt.DistributionDefault, error_bars=False, type=-1, window=None,
                 clearWindow=False, waterfall=False):
    """Open a 1D Plot of a spectrum in a workspace.

    This plots one or more spectra, with X as the bin boundaries,
    and Y as the counts in each bin.

    Args:
        source: workspace or name of a workspace
        indices: workspace index, or tuple or list of workspace indices to plot
        error_bars: bool, set to True to add error bars.
        type: curve style for plot (-1: unspecified; 0: line, default; 1: scatter/dots)
        window: window used for plotting. If None a new one will be created
        clearWindow: if is True, the window specified will be cleared before adding new curve
        waterfall: if True, plot as a waterfall if there is more than 1 curve
    Returns:
        A handle to window if one was specified, otherwise a handle to the created one. None in case of error.
    """
    workspace_names = getWorkspaceNames(source)
    __checkPlotWorkspaces(workspace_names)
    # check spectrum indices
    index_list = __getWorkspaceIndices(indices)
    if len(index_list) == 0:
        raise ValueError("No spectrum indices given")
    for idx in index_list:
        if idx < 0:
            raise ValueError("Wrong spectrum index (<0): %d" % idx)
    for name in workspace_names:
        max_spec = workspace(name).getNumberHistograms() - 1
        for idx in index_list:
            if idx > max_spec:
                raise ValueError("Wrong spectrum index for workspace '%s': %d, which is bigger than the"
                                 " number of spectra in this workspace - 1 (%d)" % (name, idx, max_spec))

    # Unwrap the window object, if any specified
    if window != None:
        window = window._getHeldObject()

    graph = proxies.Graph(threadsafe_call(_qti.app.mantidUI.plot1D,
                                          workspace_names, index_list, True, distribution, error_bars,
                                          type, window, clearWindow, waterfall))
    if graph._getHeldObject() == None:
        raise RuntimeError("Cannot create graph, see log for details.")
    else:
        return graph
示例#15
0
文件: __init__.py 项目: mducle/mantid
def plotMD(source, plot_axis=-2, normalization=DEFAULT_MD_NORMALIZATION, error_bars=False, window=None,
           clearWindow=False):
    """Open a 1D plot of a MDWorkspace.

    Args:
        source: Workspace(s) to plot
        plot_axis: Index of the plot axis (defaults to auto-select)
        normalization: Type of normalization required (defaults to volume, options available:
        MDNormalization.NoNormalization, MDNormalization.NumEventsNormalization, and
        MDNormalization.VolumeNormalization).
        error_bars: Flag for error bar plotting.
        window: window used for plotting. If None a new one will be created
        clearWindow: if is True, the window specified will be cleared before adding new curve
    Returns:
        A handle to the matrix containing the image data.
    """
    workspace_names = getWorkspaceNames(source)
    __checkPlotMDWorkspaces(workspace_names)

    for name in workspace_names:
        non_integrated_dims = mantid.api.mtd[name].getNonIntegratedDimensions()
        if not len(non_integrated_dims) == 1:
            raise ValueError(
                "'%s' must have a single non-integrated dimension in order to be rendered via plotMD" % name)

    # check axis index
    for name in workspace_names:
        ws = workspace(name)
        if hasattr(ws, "axes"):
            max_axis = workspace(name).axes()
            # see choice in MantidQwtIMDWorkspaceData::setPlotAxisChoice, -2: auto, -1: distance
            if plot_axis < -2 or plot_axis > max_axis:
                raise ValueError(
                    "Incorrect axis index given for workspace '%s': %d, should be < %d" % (name, plot_axis, max_axis))

    # Unwrap the window object, if any specified
    if window != None:
        window = window._getHeldObject()

    graph = proxies.Graph(threadsafe_call(_qti.app.mantidUI.plotMDList, workspace_names, plot_axis, normalization,
                                          error_bars, window, clearWindow))

    return graph
示例#16
0
def getSliceViewer(source, label=""):
    """Retrieves a handle to a previously-open SliceViewerWindow.
    This allows you to get a handle on, e.g., a SliceViewer that was open
    by the MultiSlice view in VATES Simple Interface.
    Will raise an exception if not found.

    Args:
        source :: name of the workspace that was open
        label :: additional label string that was used to identify the window.

    Returns:
        a handle to the SliceViewerWindow object that was created before.
    """
    import mantidqtpython
    workspace_names = getWorkspaceNames(source)
    if len(workspace_names) != 1:
        raise Exception("Please specify only one workspace.")
    else:
        svw = threadsafe_call(mantidqtpython.MantidQt.Factory.WidgetFactory.Instance().getSliceViewerWindow, workspace_names[0], label)
        if svw is not None:
            return proxies.SliceViewerWindowProxy(svw)
        else:
            return None