Esempio n. 1
0
def Cut(InputWorkspace, CutAxis=None, IntegrationAxis=None, NormToOne=False):
    """
    Cuts workspace.
    :param InputWorkspace: Workspace to cut. The parameter can be either a python
                      handle to the workspace OR the workspace name as a string.
    :param CutAxis: The x axis of the cut. If not specified will default to |Q| (or Degrees).
    :param IntegrationAxis: The integration axis of the cut. If not specified will default to DeltaE.
    Axis Format:-
            Either a string in format '<name>, <start>, <end>, <step_size>' e.g.
            'DeltaE,0,100,5' (step_size may be omitted for the integration axis)
            or just the name e.g. 'DeltaE'. In that case, the start and end will
            default to the full range of the data.
            Optionally you can also specify the energy unit at the end e.g.
            '<name>, <start>, <end>, <step>, cm-1', or '<name>, <start>, <end>, meV'
            Recognised energy units are 'meV' (default) and 'cm-1'
    :param NormToOne: if True the cut will be normalized to one.
    :return:
    """
    from mslice.app.presenters import get_cut_plotter_presenter

    _check_workspace_name(InputWorkspace)
    workspace = get_workspace_handle(InputWorkspace)
    _check_workspace_type(workspace, PixelWorkspace)
    cut_axis = _process_axis(CutAxis, 0, workspace)
    integration_axis = _process_axis(IntegrationAxis, 1 if workspace.is_PSD else 2,
                                     workspace, string_function=_string_to_integration_axis)
    cut = compute_cut(workspace, cut_axis, integration_axis, NormToOne, store=True)
    get_cut_plotter_presenter().update_main_window()

    return cut
Esempio n. 2
0
def Slice(InputWorkspace, Axis1=None, Axis2=None, NormToOne=False):
    """
    Slices workspace.

    :param InputWorkspace: The workspace to slice. The parameter can be either a python handle to the workspace
       OR the workspace name as a string.
    :param Axis1: The x axis of the slice. If not specified will default to |Q| (or Degrees).
    :param Axis2: The y axis of the slice. If not specified will default to DeltaE
       Axis Format:-
            Either a string in format '<name>, <start>, <end>, <step_size>' e.g.
            'DeltaE,0,100,5'  or just the name e.g. 'DeltaE'. In that case, the
            start and end will default to the range in the data.
    :param NormToOne: if true the slice will be normalized to one.
    :return:
    """

    _check_workspace_name(InputWorkspace)
    workspace = get_workspace_handle(InputWorkspace)
    _check_workspace_type(workspace, PixelWorkspace)
    x_axis = _process_axis(Axis1, 0, workspace)
    y_axis = _process_axis(Axis2, 1 if workspace.is_PSD else 2, workspace)

    return get_slice_plotter_presenter().create_slice(workspace, x_axis,
                                                      y_axis, None, None,
                                                      NormToOne, DEFAULT_CMAP)
Esempio n. 3
0
def Cut(InputWorkspace, CutAxis=None, IntegrationAxis=None, NormToOne=False):
    """
    Cuts workspace.
    :param InputWorkspace: Workspace to cut. The parameter can be either a python
                      handle to the workspace OR the workspace name as a string.
    :param CutAxis: The x axis of the cut. If not specified will default to |Q| (or Degrees).
    :param IntegrationAxis: The integration axis of the cut. If not specified will default to DeltaE.
    Axis Format:-
            Either a string in format '<name>, <start>, <end>, <step_size>' e.g.
            'DeltaE,0,100,5' (step_size may be omitted for the integration axis)
            or just the name e.g. 'DeltaE'. In that case, the start and end will
            default to the full range of the data.
    :param NormToOne: if true the cut will be normalized to one.
    :return:
    """

    _check_workspace_name(InputWorkspace)
    workspace = get_workspace_handle(InputWorkspace)
    _check_workspace_type(workspace, PixelWorkspace)
    cut_axis = _process_axis(CutAxis, 0, workspace)
    integration_axis = _process_axis(
        IntegrationAxis,
        1 if workspace.is_PSD else 2,
        workspace,
        string_function=_string_to_integration_axis)
    cut = compute_cut(workspace,
                      cut_axis,
                      integration_axis,
                      NormToOne,
                      store=True)

    get_cut_plotter_presenter().update_main_window()

    return cut
Esempio n. 4
0
def PlotCut(InputWorkspace, IntensityStart=0, IntensityEnd=0, PlotOver=False):
    """
    Create mslice standard matplotlib plot of a cut workspace.

    :param InputWorkspace: Workspace to cut. The parameter can be either a python handle to the workspace
    OR the workspace name as a string.
    :param IntensityStart: Lower bound of the y axis
    :param IntensityEnd: Upper bound of the y axis
    :param PlotOver: if true the cut will be plotted on an existing figure.
    :return:
    """
    _check_workspace_name(InputWorkspace)
    workspace = get_workspace_handle(InputWorkspace)
    if not isinstance(workspace, HistogramWorkspace):
        raise RuntimeError("Incorrect workspace type.")

    if IntensityStart == 0 and IntensityEnd == 0:
        intensity_range = None
    else:
        intensity_range = (IntensityStart, IntensityEnd)
    from mslice.app.presenters import cli_cut_plotter_presenter
    cli_cut_plotter_presenter.plot_cut_from_workspace(workspace, intensity_range=intensity_range,
                                                      plot_over=PlotOver)

    return GlobalFigureManager._active_figure
Esempio n. 5
0
def Slice(InputWorkspace, Axis1=None, Axis2=None, NormToOne=False):
    """
    Slices workspace.

    :param InputWorkspace: The workspace to slice. The parameter can be either a python handle to the workspace
       OR the workspace name as a string.
    :param Axis1: The x axis of the slice. If not specified will default to |Q| (or Degrees).
    :param Axis2: The y axis of the slice. If not specified will default to DeltaE
       Axis Format:-
            Either a string in format '<name>, <start>, <end>, <step_size>' e.g.
            'DeltaE,0,100,5'  or just the name e.g. 'DeltaE'. In that case, the
            start and end will default to the range in the data.
            Optionally you can also specify the energy unit at the end e.g.
            '<name>, <start>, <end>, <step>, cm-1'. Recognised energy units are 'meV' (default) and 'cm-1'
    :param NormToOne: if True the slice will be normalized to one.
    :return:
    """
    from mslice.app.presenters import get_slice_plotter_presenter
    _check_workspace_name(InputWorkspace)
    workspace = get_workspace_handle(InputWorkspace)
    _check_workspace_type(workspace, PixelWorkspace)
    x_axis = _process_axis(Axis1, 0, workspace)
    y_axis = _process_axis(Axis2, 1 if workspace.is_PSD else 2, workspace)

    return get_slice_plotter_presenter().create_slice(workspace, x_axis, y_axis, None, None, NormToOne, DEFAULT_CMAP)
Esempio n. 6
0
def errorbar(axes, workspace, *args, **kwargs):
    """
    Same as the cli PlotCut but returns the relevant axes object.
    """
    from mslice.app.presenters import get_cut_plotter_presenter
    cur_fig = plt.gcf()
    cur_canvas = cur_fig.canvas

    _check_workspace_name(workspace)
    workspace = get_workspace_handle(workspace)
    if not isinstance(workspace, HistogramWorkspace):
        raise RuntimeError("Incorrect workspace type.")

    presenter = get_cut_plotter_presenter()

    plot_over = kwargs.pop('plot_over', True)
    intensity_range = kwargs.pop('intensity_range', (None, None))
    label = kwargs.pop('label', None)
    label = workspace.name if label is None else label
    en_conversion_allowed = kwargs.pop('en_conversion', True)

    cut_axis, int_axis = tuple(workspace.axes)
    # Checks that current cut has consistent units with previous
    if plot_over:
        cached_cuts = presenter.get_cache(axes)
        if cached_cuts:
            if (cut_axis.units != cached_cuts[0].cut_axis.units):
                raise RuntimeError('Cut axes not consistent with current plot. '
                                   'Expected {}, got {}'.format(cached_cuts[0].cut_axis.units, cut_axis.units))
            # Checks whether we should do an energy unit conversion
            if 'DeltaE' in cut_axis.units and cut_axis.e_unit != cached_cuts[0].cut_axis.e_unit:
                if en_conversion_allowed:
                    _rescale_energy_cut_plot(presenter, cached_cuts, cut_axis.e_unit)
                else:
                    raise RuntimeError('Wrong energy unit for cut. '
                                       'Expected {}, got {}'.format(cached_cuts[0].cut_axis.e_unit, cut_axis.e_unit))

    plotfunctions.errorbar(axes, workspace.raw_ws, label=label, *args, **kwargs)

    axes.set_ylim(*intensity_range) if intensity_range is not None else axes.autoscale()
    intensity_min, intensity_max = axes.get_ylim()
    if cur_canvas.manager.window.action_toggle_legends.isChecked():
        leg = axes.legend(fontsize='medium')
        leg.draggable()
    axes.set_xlabel(get_display_name(cut_axis), picker=CUT_PICKER_TOL_PTS)
    axes.set_ylabel(CUT_INTENSITY_LABEL, picker=CUT_PICKER_TOL_PTS)
    if not plot_over:
        cur_canvas.set_window_title(workspace.name)
        cur_canvas.manager.update_grid()
    if not cur_canvas.manager.has_plot_handler():
        cur_canvas.manager.add_cut_plot(presenter, workspace.name)
    cur_fig.canvas.draw()
    axes.pchanged()  # This call is to let the waterfall callback know to update

    cut = Cut(cut_axis, int_axis, intensity_min, intensity_max, workspace.norm_to_one, width='')
    cut.workspace_name = workspace.parent
    presenter.save_cache(axes, cut, plot_over)

    return axes.lines
Esempio n. 7
0
def pcolormesh(axes, workspace, *args, **kwargs):
    """
    Same as the CLI PlotSlice but returns the relevant axes object.
    """
    from mslice.app.presenters import get_slice_plotter_presenter, cli_slice_plotter_presenter
    _check_workspace_name(workspace)
    workspace = get_workspace_handle(workspace)
    _check_workspace_type(workspace, HistogramWorkspace)

    # slice cache needed from main slice plotter presenter
    if is_gui() and GlobalFigureManager.get_active_figure().plot_handler is not None:
        cli_slice_plotter_presenter._slice_cache = app.MAIN_WINDOW.slice_plotter_presenter._slice_cache
    else:
        # Needed so the figure manager knows about the slice plot handler
        create_slice_figure(workspace.name[2:], get_slice_plotter_presenter())

    slice_cache = get_slice_plotter_presenter().get_slice_cache(workspace)

    intensity = kwargs.pop('intensity', None)
    temperature = kwargs.pop('temperature', None)

    if temperature is not None:
        get_slice_plotter_presenter().set_sample_temperature(workspace.name[2:], temperature)

    if intensity is not None and intensity != 's(q,e)':
        workspace = getattr(slice_cache, _intensity_to_workspace[intensity])
        plot_window = GlobalFigureManager.get_active_figure().window
        plot_handler = GlobalFigureManager.get_active_figure().plot_handler
        intensity_action = getattr(plot_window, _intensity_to_action[intensity])
        plot_handler.set_intensity(intensity_action)
        intensity_action.setChecked(True)

        # Set intensity properties for generated script to use
        if not is_gui():
            for key, value in _function_to_intensity.items():
                if value == intensity:
                    intensity_method = key
                    break
            plot_handler.intensity = True
            plot_handler.intensity_method = intensity_method
            plot_handler.temp = temperature
            plot_handler.temp_dependent = True if temperature is not None else False
            plot_handler._slice_plotter_presenter._slice_cache[plot_handler.ws_name].colourmap = kwargs.get('cmap')

    if not workspace.is_PSD and not slice_cache.rotated:
        workspace = Transpose(OutputWorkspace=workspace.name, InputWorkspace=workspace, store=False)
    plotfunctions.pcolormesh(axes, workspace.raw_ws, *args, **kwargs)
    axes.set_title(workspace.name[2:], picker=SLICE_PICKER_TOL_PTS)
    x_axis = slice_cache.energy_axis if slice_cache.rotated else slice_cache.momentum_axis
    y_axis = slice_cache.momentum_axis if slice_cache.rotated else slice_cache.energy_axis
    axes.get_xaxis().set_units(x_axis.units)
    axes.get_yaxis().set_units(y_axis.units)
    # labels
    axes.set_xlabel(get_display_name(x_axis), picker=SLICE_PICKER_TOL_PTS)
    axes.set_ylabel(get_display_name(y_axis), picker=SLICE_PICKER_TOL_PTS)
    axes.set_xlim(x_axis.start, x_axis.end)
    axes.set_ylim(y_axis.start, y_axis.end)
    return axes.collections[0]  # Quadmesh object
Esempio n. 8
0
    def bragg(self, workspace, element=None, cif=None):
        from mslice.app.presenters import get_slice_plotter_presenter
        _check_workspace_name(workspace)
        workspace = get_workspace_handle(workspace)
        _check_workspace_type(workspace, HistogramWorkspace)

        key = _get_overplot_key(element, rmm=None)

        get_slice_plotter_presenter().add_overplot_line(workspace.name, key, recoil=False, cif=cif)
        _update_overplot_checklist(key)
        _update_legend()
Esempio n. 9
0
def MakeProjection(InputWorkspace, Axis1, Axis2, Units='meV'):
    """
    Calculate projections of workspace

    :param InputWorkspace: Workspace to project, can be either python handle
    to the workspace or a string containing the workspace name.
    :param Axis1: The first axis of projection (string)
    :param Axis2: The second axis of the projection (string)
    :param Units: The energy units (string) [default: 'meV']
    :return:
    """

    _check_workspace_name(InputWorkspace)
    return get_powder_presenter().calc_projection(InputWorkspace, Axis1, Axis2,
                                                  Units)
Esempio n. 10
0
def MakeProjection(InputWorkspace, Axis1, Axis2, Units='meV'):
    """
    Calculate projections of workspace

    :param InputWorkspace: Workspace to project, can be either python handle
    to the workspace or a string containing the workspace name.
    :param Axis1: The first axis of projection (string)
    :param Axis2: The second axis of the projection (string)
    :param Units: The energy units (string) [default: 'meV']
    :return:
    """
    from mslice.app.presenters import get_powder_presenter

    _check_workspace_name(InputWorkspace)
    return get_powder_presenter().calc_projection(InputWorkspace, Axis1, Axis2, Units)
Esempio n. 11
0
    def recoil(self, workspace, element=None, rmm=None):
        from mslice.app.presenters import get_slice_plotter_presenter
        _check_workspace_name(workspace)
        workspace = get_workspace_handle(workspace)
        _check_workspace_type(workspace, HistogramWorkspace)

        key = _get_overplot_key(element, rmm)

        if rmm is not None:
            plot_handler = GlobalFigureManager.get_active_figure().plot_handler
            plot_handler._arb_nuclei_rmm = rmm

        get_slice_plotter_presenter().add_overplot_line(workspace.name, key, recoil=True, cif=None)

        _update_overplot_checklist(key)
        _update_legend()
Esempio n. 12
0
def PlotSliceMsliceProjection(InputWorkspace, IntensityStart="", IntensityEnd="", Colormap=DEFAULT_CMAP):
    """
    Same as the CLI PlotSlice but returns the relevant axes object.
    """

    _check_workspace_name(InputWorkspace)
    workspace = get_workspace_handle(InputWorkspace)
    _check_workspace_type(workspace, HistogramWorkspace)

    # slice cache needed from main slice plotter presenter
    if is_gui():
        cli_slice_plotter_presenter._slice_cache = app.MAIN_WINDOW.slice_plotter_presenter._slice_cache
    cli_slice_plotter_presenter.change_intensity(workspace.name, IntensityStart, IntensityEnd)
    cli_slice_plotter_presenter.change_colourmap(workspace.name, Colormap)
    quadmesh = cli_slice_plotter_presenter.plot_from_cache(workspace)

    return quadmesh
Esempio n. 13
0
def PlotCutMsliceProjection(InputWorkspace, IntensityStart=0, IntensityEnd=0, PlotOver=False):
    """
    Same as the cli PlotCut but returns the relevant axes object.
    """

    _check_workspace_name(InputWorkspace)
    workspace = get_workspace_handle(InputWorkspace)
    if not isinstance(workspace, HistogramWorkspace):
        raise RuntimeError("Incorrect workspace type.")
    if IntensityStart == 0 and IntensityEnd == 0:
        intensity_range = None
    else:
        intensity_range = (IntensityStart, IntensityEnd)
    lines = cli_cut_plotter_presenter.plot_cut_from_workspace(workspace, intensity_range=intensity_range,
                                                              plot_over=PlotOver)

    return lines
Esempio n. 14
0
def PlotSlice(InputWorkspace, IntensityStart="", IntensityEnd="", Colormap=DEFAULT_CMAP):
    """
    Creates mslice standard matplotlib plot of a slice workspace.

    :param InputWorkspace: Workspace to plot. The parameter can be either a python
    handle to the workspace OR the workspace name as a string.
    :param IntensityStart: Lower bound of the intensity axis (colorbar)
    :param IntensityEnd: Upper bound of the intensity axis (colorbar)
    :param Colormap: Colormap name as a string. Default is 'viridis'.
    :return:
    """
    _check_workspace_name(InputWorkspace)
    workspace = get_workspace_handle(InputWorkspace)
    _check_workspace_type(workspace, HistogramWorkspace)

    # slice cache needed from main slice plotter presenter
    from mslice.app.presenters import cli_slice_plotter_presenter
    if is_gui():
        cli_slice_plotter_presenter._slice_cache = app.MAIN_WINDOW.slice_plotter_presenter._slice_cache
    cli_slice_plotter_presenter.change_intensity(workspace.name, IntensityStart, IntensityEnd)
    cli_slice_plotter_presenter.change_colourmap(workspace.name, Colormap)
    cli_slice_plotter_presenter.plot_from_cache(workspace)

    return GlobalFigureManager._active_figure
Esempio n. 15
0
def GenerateScript(InputWorkspace, filename):
    from mslice.scripting import generate_script
    _check_workspace_name(InputWorkspace)
    workspace_name = get_workspace_handle(InputWorkspace).name[2:]
    plot_handler = GlobalFigureManager.get_active_figure().plot_handler
    generate_script(ws_name=workspace_name, filename=filename, plot_handler=plot_handler)