File: show_interface.py

package info (click to toggle)
python-mcstasscript 0.0.46%2Bgit20250402111921.bfa5a26-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 11,440 kB
  • sloc: python: 13,421; makefile: 14
file content (55 lines) | stat: -rw-r--r-- 1,603 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from .simulation_interface import SimInterface
from .plot_interface import PlotInterface

from mcstasscript.interface.instr import McCode_instr
from mcstasscript.data.data import McStasData


def show(function_input):
    """
    Shortcut to showing an interface appropriate for given object

    Can show widget interface for instrument object or list of McStasData
    objects. Needs "%matplotlib widget" in notebook to work correctly.

    Parameters
    ----------

    function_input : McCode_instr, list of McStasData

    """

    if isinstance(function_input, McCode_instr):
        return show_instrunent(function_input)

    elif isinstance(function_input, (list, McStasData)):
        return show_plot(function_input)

    else:
        raise RuntimeError("Show did not recoignize object of type"
                           + str(type(function_input)) + ".")


def show_instrunent(instrument):
    """
    Shows simulation interface for instrument
    """
    simulation_interface = SimInterface(instrument)
    return simulation_interface.show_interface()


def show_plot(data):
    """
    Shows plot interface for given data
    """
    if isinstance(data, list):
        for element in data:
            if not isinstance(element, McStasData):
                raise RuntimeError("Given list contains elements that "
                                   + "are not McStasData objects.")
    else:
        if not isinstance(data, McStasData):
            raise RuntimeError("Given data is not McStasData.")

    plot_interface = PlotInterface(data)
    return plot_interface.show_interface()