Exemple #1
0
class ProjectReaderMantidPlot(ProjectReaderInterface):
    def __init__(self, project_file_ext, filename):
        super().__init__(project_file_ext, filename)
        self.parser = None

    def read_project(self):
        try:
            self.parser = MantidPlotProjectParser(self.filename)
            self.read_workspaces()
            self.read_interfaces()
            self.read_plots()
        except Exception as err:
            logger.warning("Mantidplot project file unable to be loaded/read",
                           err)

    def read_workspaces(self):
        logger.notice("Loading workspaces from Mantidplot project file " +
                      self.filename)
        self.workspace_names = self.parser.get_workspaces()

    def read_interfaces(self):
        logger.notice(
            "Loading interfaces from mantid plot project file not supported")

    def read_plots(self):
        logger.notice("Loading plots from MantidPlot project file")
        self.plot_list = self.parser.get_plots()
Exemple #2
0
    def test_parsing_simple_1d_plot(self):
        parser = MantidPlotProjectParser(self.project_with_simple_1d_plot)
        expected_creation_args = {
            'linestyle': 'solid',
            'linewidth': 1.5,
            'drawstyle': 'default',
            'marker': None,
            'markersize': 6,
            'function': 'plot',
            'wkspIndex': 1,
            'workspaces': 'MUSR00062261'
        }

        plot_list = parser.get_plots()
        plot_dict = plot_list[0]
        axes_dict = plot_dict["axes"]
        axes_properties = axes_dict[0]["properties"]
        creation_args = plot_dict["creationArguments"][0][0]

        self.assertEqual(len(plot_list), 1)
        self.assertEqual(len(axes_dict), 1)
        self.assertEqual(plot_dict["label"], "MUSR00062261-1")
        self.assertEqual(axes_dict[0]["title"], "MUSR00062261")
        self.assertEqual(axes_dict[0]["xAxisTitle"], "Time (μs)")
        self.assertEqual(axes_dict[0]["yAxisTitle"], "Counts (μs)⁻¹")
        self.assertEqual(axes_dict[0]["title"], "MUSR00062261")
        self.assertEqual(axes_properties["xLim"], [-5, 35])
        self.assertEqual(axes_properties["yLim"], [0, 300000.0])
        self.assertEqual(creation_args, expected_creation_args)
Exemple #3
0
    def test_error_bars_correctly_loaded_from_project_file(self):
        parser = MantidPlotProjectParser(self.project_with_errorbars)

        plot_list = parser.get_plots()
        plot_dict = plot_list[0]
        creation_args = plot_dict["creationArguments"][0][0]

        self.assertEqual(creation_args["function"], "errorbar")
Exemple #4
0
    def test_parsing_workspace_group(self):
        expected_workspaces = [
            'MUSR00015189_1', 'MUSR00015189_2', 'MUSR00062260', 'MUSR00062261'
        ]
        parser = MantidPlotProjectParser(self.project_with_workspace_group)

        workspace_list = parser.get_workspaces()

        self.assertCountEqual(workspace_list, expected_workspaces)
Exemple #5
0
 def read_project(self):
     try:
         self.parser = MantidPlotProjectParser(self.filename)
         self.read_workspaces()
         self.read_interfaces()
         self.read_plots()
     except Exception as err:
         logger.warning("Mantidplot project file unable to be loaded/read",
                        err)
Exemple #6
0
    def test_parsing_workspaces(self):
        expected_workspaces = [
            'BASIS_79827_divided_sqw', 'irs26176_graphite002_red',
            'MUSR00062261'
        ]
        parser = MantidPlotProjectParser(self.project_with_multiple_workspaces)

        workspace_list = parser.get_workspaces()

        self.assertCountEqual(workspace_list, expected_workspaces)
Exemple #7
0
    def test_axes_scale_read_read_correctly_from_project_file(self):
        parser = MantidPlotProjectParser(self.project_with_logscale)

        plot_list = parser.get_plots()
        plot_dict = plot_list[0]
        axes_dict = plot_dict["axes"]
        axes_properties = axes_dict[0]["properties"]

        self.assertEqual(axes_properties["yAxisScale"], 'linear')
        self.assertEqual(axes_properties["xAxisScale"], 'log')
Exemple #8
0
    def test_parsing_tiled_plot(self):
        number_of_tiles = 4
        parser = MantidPlotProjectParser(self.project_with_tiled_lots)

        plot_list = parser.get_plots()
        plot_dict = plot_list[0]
        creation_args = plot_dict["creationArguments"]
        axes_args = plot_dict["axes"]
        index_list = [
            creation_args[i][0]["wkspIndex"] for i in range(len(creation_args))
        ]

        self.assertEqual(len(plot_list), 1)
        self.assertEqual(len(axes_args), number_of_tiles)
        self.assertEqual(len(creation_args), number_of_tiles)
        self.assertEqual(index_list, [0, 4, 18, 26])
Exemple #9
0
    def test_parsing_plot_with_multiple_lines(self):
        number_of_lines = 4
        parser = MantidPlotProjectParser(self.project_plot_with_multiple_lines)

        plot_list = parser.get_plots()
        plot_dict = plot_list[0]
        creation_args = plot_dict["creationArguments"][0]
        workspace_list = [
            creation_args[i]["workspaces"] for i in range(len(creation_args))
        ]
        index_list = [
            creation_args[i]["wkspIndex"] for i in range(len(creation_args))
        ]

        self.assertEqual(len(plot_list), 1)
        self.assertEqual(len(creation_args), number_of_lines)
        self.assertEqual(workspace_list, ["MUSR00062261"] * number_of_lines)
        self.assertEqual(index_list, [0, 1, 2, 3])
Exemple #10
0
    def test_parsing_multiple_1d_plots(self):
        parser = MantidPlotProjectParser(self.project_with_multiple_1d_plots)
        expected_creation_args = {
            'linestyle': 'solid',
            'linewidth': 1.5,
            'drawstyle': 'default',
            'marker': None,
            'markersize': 6,
            'function': 'plot',
            'wkspIndex': 1,
            'workspaces': 'MUSR00062261'
        }

        plot_list = parser.get_plots()
        creation_args_1 = plot_list[0]["creationArguments"][0][0]
        creation_args_2 = plot_list[1]["creationArguments"][0][0]
        creation_args_3 = plot_list[2]["creationArguments"][0][0]

        self.assertEqual(len(plot_list), 3)
        self.assertEqual(creation_args_1, expected_creation_args)
        expected_creation_args["wkspIndex"] = 8
        self.assertEqual(creation_args_2, expected_creation_args)
        expected_creation_args["wkspIndex"] = 32
        self.assertEqual(creation_args_3, expected_creation_args)