Exemplo n.º 1
0
    def save_project(self,
                     directory,
                     workspace_to_save=None,
                     plots_to_save=None,
                     interfaces_to_save=None):
        """
        The method that will actually save the project and call relevant savers for workspaces, plots, interfaces etc.
        :param directory: String; The directory of the
        :param workspace_to_save: List; of Strings that will have workspace names in it, if None will save all
        :param plots_to_save: List; of matplotlib.figure objects to save to the project file.
        :param interfaces_to_save: List of Lists of Window and Encoder; the interfaces to save and the encoders to use
        :return: None; If the method cannot be completed.
        """
        # Check if the directory doesn't exist
        if directory is None:
            logger.warning("Can not save to empty directory")
            return

        # Check this isn't saving a blank project file
        if workspace_to_save is None and plots_to_save is None and interfaces_to_save is None:
            logger.warning("Can not save an empty project")
            return

        # Save workspaces to that location
        workspace_saver = WorkspaceSaver(directory=directory)
        workspace_saver.save_workspaces(workspaces_to_save=workspace_to_save)

        # Generate plots
        plots_to_save_list = PlotsSaver().save_plots(plots_to_save)

        # Save interfaces
        if interfaces_to_save is None:
            interfaces_to_save = []
        interfaces = []
        for interface, encoder in interfaces_to_save:
            # Add to the dictionary encoded data with the key as the first tag in the list on the encoder attributes
            try:
                tag = encoder.tags[0]
                encoded_dict = encoder.encode(interface, directory)
                encoded_dict["tag"] = tag
                interfaces.append(encoded_dict)
            except Exception as e:
                # Catch any exception and log it
                if isinstance(e, KeyboardInterrupt):
                    raise
                logger.warning(
                    "Project Saver: An interface could not be saver error: " +
                    str(e))

        # Pass dicts to Project Writer
        writer = ProjectWriter(
            workspace_names=workspace_saver.get_output_list(),
            plots_to_save=plots_to_save_list,
            interfaces_to_save=interfaces,
            save_location=directory,
            project_file_ext=self.project_file_ext)
        writer.write_out()
Exemplo n.º 2
0
    def save_project(self,
                     file_name,
                     workspace_to_save=None,
                     plots_to_save=None,
                     interfaces_to_save=None,
                     project_recovery=True):
        """
        The method that will actually save the project and call relevant savers for workspaces, plots, interfaces etc.
        :param file_name: String; The file_name of the
        :param workspace_to_save: List; of Strings that will have workspace names in it, if None will save all
        :param plots_to_save: List; of matplotlib.figure objects to save to the project file.
        :param interfaces_to_save: List of Lists of Window and Encoder; the interfaces to save and the encoders to use
        :param project_recovery: Bool; If the behaviour of Project Save should be altered to function correctly inside
        of project recovery
        :return: None; If the method cannot be completed.
        """
        # Check if the file_name doesn't exist
        if file_name is None:
            logger.warning("Please select a valid file name")
            return

        # Check this isn't saving a blank project file
        if (workspace_to_save is None and plots_to_save is None
                and interfaces_to_save is None) and project_recovery:
            logger.warning("Can not save an empty project")
            return

        directory = os.path.dirname(file_name)
        # Save workspaces to that location
        if project_recovery:
            workspace_saver = WorkspaceSaver(directory=directory)
            workspace_saver.save_workspaces(
                workspaces_to_save=workspace_to_save)
            saved_workspaces = workspace_saver.get_output_list()
        else:
            # Assume that this is project recovery so pass a list of workspace names
            saved_workspaces = ADS.getObjectNames()

        # Generate plots
        plots_to_save_list = PlotsSaver().save_plots(plots_to_save,
                                                     not project_recovery)

        # Save interfaces
        if interfaces_to_save is None:
            interfaces_to_save = []

        interfaces = self._return_interfaces_dicts(
            directory=directory, interfaces_to_save=interfaces_to_save)

        # Pass dicts to Project Writer
        writer = ProjectWriter(workspace_names=saved_workspaces,
                               plots_to_save=plots_to_save_list,
                               interfaces_to_save=interfaces,
                               save_location=file_name,
                               project_file_ext=self.project_file_ext)
        writer.write_out()
Exemplo n.º 3
0
    def setUp(self):
        CreateSampleWorkspace(OutputWorkspace="ws1")
        self.plots_loader = PlotsLoader()

        # Make a figure with a given input with all these values already set
        self.loader_plot_dict = {
            u'axes': [{
                u'colorbar': {
                    u'exists': False
                },
                u'legend': {
                    u'exists': True,
                    u'visible': True,
                    u'title': "Legend",
                    u'background_color': u'#ffffff',
                    u'edge_color': u'#000000',
                    u'transparency': 0.5,
                    u'entries_font': u'DejaVu Sans',
                    u'entries_size': 10.0,
                    u'entries_color': u'#000000',
                    u'title_font': u'DejaVu Sans',
                    u'title_size': 12.0,
                    u'title_color': u'#000000',
                    u'marker_size': 2.0,
                    u'box_visible': True,
                    u'shadow': False,
                    u'round_edges': True,
                    u'columns': 1,
                    u'column_spacing': 0.5,
                    u'label_spacing': 0.5,
                    u'marker_position': u'Left of Entries',
                    u'markers': 1,
                    u'border_padding': 0.5,
                    u'marker_label_padding': 1.0
                },
                u'lines': [{
                    u'alpha': 1,
                    u'color': u'#1f77b4',
                    u'label': u'ws1: spec 2',
                    u'lineIndex': 0,
                    u'lineStyle': u'-',
                    u'lineWidth': 1.5,
                    u'markerStyle': {
                        u'edgeColor': u'#1f77b4',
                        u'edgeWidth': 1.0,
                        u'faceColor': u'#1f77b4',
                        u'markerSize': 6.0,
                        u'markerType': u'None',
                        u'zOrder': 2
                    },
                    u'errorbars': {
                        u'exists': False
                    }
                }],
                u'properties': {
                    u'axisOn': True,
                    u'bounds': (0.0, 0.0, 0.0, 0.0),
                    u'dynamic': True,
                    u'frameOn': True,
                    u'visible': True,
                    u'xAxisProperties': {
                        u'fontSize': 10.0,
                        u'gridStyle': {
                            u'gridOn': False
                        },
                        u'majorTickFormat': None,
                        u'majorTickFormatter': u'ScalarFormatter',
                        u'majorTickLocator': u'AutoLocator',
                        u'majorTickLocatorValues': None,
                        u'minorTickFormat': None,
                        u'minorTickFormatter': u'NullFormatter',
                        u'minorTickLocator': u'NullLocator',
                        u'minorTickLocatorValues': None,
                        u'visible': True
                    },
                    u'xAxisScale': u'linear',
                    u'xLim': (0.0, 1.0),
                    u"xAutoScale": False,
                    u'yAxisProperties': {
                        u'fontSize': 10.0,
                        u'gridStyle': {
                            u'gridOn': False
                        },
                        u'majorTickFormat': None,
                        u'majorTickFormatter': u'ScalarFormatter',
                        u'majorTickLocator': u'AutoLocator',
                        u'majorTickLocatorValues': None,
                        u'minorTickFormat': None,
                        u'minorTickFormatter': u'NullFormatter',
                        u'minorTickLocator': u'NullLocator',
                        u'minorTickLocatorValues': None,
                        u'visible': True
                    },
                    u'yAxisScale': u'linear',
                    u'yLim': (0.0, 1.0),
                    u"yAutoScale": False,
                    u"facecolor": (0.0, 0.0, 0.0, 0.0),
                    u'showMinorGrid': False,
                    u'tickParams': {
                        'xaxis': {
                            'major': {
                                'bottom': True,
                                'top': True,
                                'labelbottom': True,
                                'labeltop': True,
                                'direction': 'inout',
                                'width': 1,
                                'size': 6
                            },
                            'minor': {
                                'bottom': True,
                                'top': True,
                                'labelbottom': True,
                                'labeltop': True,
                                'direction': 'inout',
                                'width': 1,
                                'size': 3
                            }
                        },
                        'yaxis': {
                            'major': {
                                'left': True,
                                'right': True,
                                'labelleft': True,
                                'labelright': True,
                                'direction': 'inout',
                                'width': 1,
                                'size': 6
                            },
                            'minor': {
                                'left': True,
                                'right': True,
                                'labelleft': True,
                                'labelright': True,
                                'direction': 'inout',
                                'width': 1,
                                'size': 3
                            }
                        }
                    },
                    u'spineWidths': {
                        'left': 0.4,
                        'right': 0.4,
                        'bottom': 0.4,
                        'top': 0.4
                    }
                },
                u'textFromArtists': {},
                u'texts': [{
                    u'position': (0, 0),
                    u'style': {
                        u'alpha': 1,
                        u'color': u'#000000',
                        u'hAlign': u'left',
                        u'rotation': 0.0,
                        u'textSize': 10.0,
                        u'vAlign': u'baseline',
                        u'zOrder': 3
                    },
                    u'text': u'text',
                    u'useTeX': False
                }],
                u'title':
                u'',
                u'xAxisTitle':
                u'',
                u'yAxisTitle':
                u''
            }],
            u'creationArguments': [[{
                u"workspaces": u"ws1",
                u"specNum": 2,
                u"function": u"plot"
            }]],
            u'label':
            u'',
            u'properties': {
                u'dpi': 100.0,
                u'figHeight': 4.8,
                u'figWidth': 6.4
            }
        }

        self.fig = self.plots_loader.make_fig(self.loader_plot_dict,
                                              create_plot=False)

        self.plot_saver = PlotsSaver()
Exemplo n.º 4
0
    def setUp(self):
        CreateSampleWorkspace(OutputWorkspace="ws1")
        self.plots_loader = PlotsLoader()

        # Make a figure with a given input with all these values already set
        self.loader_plot_dict = {
            u'axes': [{
                u'colorbar': {
                    u'exists': False
                },
                u'legend': {
                    u'exists': False
                },
                u'lines': [{
                    u'alpha': 1,
                    u'color': u'#1f77b4',
                    u'label': u'ws1: spec 2',
                    u'lineIndex': 0,
                    u'lineStyle': u'-',
                    u'lineWidth': 1.5,
                    u'markerStyle': {
                        u'edgeColor': u'#1f77b4',
                        u'edgeWidth': 1.0,
                        u'faceColor': u'#1f77b4',
                        u'markerSize': 6.0,
                        u'markerType': u'None',
                        u'zOrder': 2
                    },
                    u'errorbars': {
                        u'exists': False
                    }
                }],
                u'properties': {
                    u'axisOn': True,
                    u'bounds': (0.0, 0.0, 0.0, 0.0),
                    u'dynamic': True,
                    u'frameOn': True,
                    u'visible': True,
                    u'xAxisProperties': {
                        u'fontSize': 10.0,
                        u'gridStyle': {
                            u'gridOn': False
                        },
                        u'majorTickFormat': None,
                        u'majorTickFormatter': u'ScalarFormatter',
                        u'majorTickLocator': u'AutoLocator',
                        u'majorTickLocatorValues': None,
                        u'minorTickFormat': None,
                        u'minorTickFormatter': u'NullFormatter',
                        u'minorTickLocator': u'NullLocator',
                        u'minorTickLocatorValues': None,
                        u'position': u'Bottom',
                        u'visible': True
                    },
                    u'xAxisScale': u'linear',
                    u'xLim': (0.0, 1.0),
                    u'yAxisProperties': {
                        u'fontSize': 10.0,
                        u'gridStyle': {
                            u'gridOn': False
                        },
                        u'majorTickFormat': None,
                        u'majorTickFormatter': u'ScalarFormatter',
                        u'majorTickLocator': u'AutoLocator',
                        u'majorTickLocatorValues': None,
                        u'minorTickFormat': None,
                        u'minorTickFormatter': u'NullFormatter',
                        u'minorTickLocator': u'NullLocator',
                        u'minorTickLocatorValues': None,
                        u'position': u'Left',
                        u'visible': True
                    },
                    u'yAxisScale': u'linear',
                    u'yLim': (0.0, 1.0)
                },
                u'textFromArtists': {},
                u'texts': [{
                    u'position': (0, 0),
                    u'style': {
                        u'alpha': 1,
                        u'color': u'#000000',
                        u'hAlign': u'left',
                        u'rotation': 0.0,
                        u'textSize': 10.0,
                        u'vAlign': u'baseline',
                        u'zOrder': 3
                    },
                    u'text': u'text',
                    u'useTeX': False
                }],
                u'title':
                u'',
                u'xAxisTitle':
                u'',
                u'yAxisTitle':
                u''
            }],
            u'creationArguments': [[{
                u"workspaces": u"ws1",
                u"specNum": 2,
                u"function": u"plot"
            }]],
            u'label':
            u'',
            u'properties': {
                u'dpi': 100.0,
                u'figHeight': 4.8,
                u'figWidth': 6.4
            }
        }
        self.fig = self.plots_loader.make_fig(self.loader_plot_dict,
                                              create_plot=False)

        self.plot_saver = PlotsSaver()