Beispiel #1
0
    def generate_indicators(self):
        self.filepaths = {}

        for name, (projconfig, batchname, visname, datasourcename,
                   year) in self.indicators.items():
            op = OpusProject()
            op.open(os.path.join(PROJECTCONFIGBASE, projconfig))

            bp = BatchProcessor(op)
            visualizationsconf = get_batch_configuration(project=op,
                                                         batch_name=batchname,
                                                         vis_name=visname)
            bp.set_data(visualizations=visualizationsconf,
                        source_data_name=datasourcename,
                        years=[year, year])
            bp.run()

            visualizations = bp.get_visualizations()

            # visualizations in batch
            assert len(visualizations) == 1
            vistype, visualizations = visualizations[0]
            # indicators in visualization
            assert len(visualizations) == 1
            self.filepaths[name] = visualizations[0].get_file_path()
Beispiel #2
0
    def on_indicatorBox(self):
        indicator_name = str(self.diagnostic_indicator_name.currentText())
        dataset_name = self.diagnostic_dataset_name.currentText()
        indicator_type = str(self.diagnostic_indicator_type.currentText())
        year = str(self.diagnostic_year.currentText())
        if year == '': return
        year = int(year)

        if dataset_name not in self.spatial_datasets and indicator_type == 'map':
            MessageBox.warning(
                mainwindow=self.mainwindow,
                text="That indicator cannot be visualized as a map.",
                detailed_text=(
                    'The dataset %s is either not spatial or cannot be '
                    'rendered as a grid. If the latter, please try '
                    'exporting to an external GIS tool.' % dataset_name))
            return

        cache_directory = self.model.config['cache_directory']
        params = {'indicators': [indicator_name]}
        if indicator_type == 'table':
            indicator_type = 'tab'
            params['output_type'] = 'tab'
        # JLM > commented this out for when implemented animations
#        else:
#            indicator_type = 'mapnik_map'

        visualizations = [(indicator_type, str(dataset_name), params)]

        self.batch_processor = BatchProcessor(self.project)

        self.batch_processor.guiElement = self

        self.batch_processor.set_data(visualizations=visualizations,
                                      source_data_name=self.model.run_name,
                                      years=[year, year],
                                      cache_directory=cache_directory)

        self.diagnosticThread = OpusGuiThread(
            parentThread=self.mainwindow,
            parentGuiElement=self,
            thread_object=self.batch_processor)

        # Use this signal from the thread if it is capable of producing its own status signal
        QObject.connect(self.diagnosticThread,
                        SIGNAL("runFinished(PyQt_PyObject)"),
                        self.visualizationsCreated)
        QObject.connect(self.diagnosticThread,
                        SIGNAL("runError(PyQt_PyObject)"),
                        self.runErrorFromThread)

        self.diagnosticThread.start()
Beispiel #3
0
    def runIndicatorBatch(self):
        visualizations = get_batch_configuration(project=self.project,
                                                 batch_name=self.batch_name)
        start, end = self.get_years()

        self.batch_processor = BatchProcessor(project=self.project)
        self.batch_processor.errorCallback = self.errorCallback
        self.batch_processor.finishedCallback = self.indicatorBatchFinishedCallback

        self.batch_processor.set_data(visualizations=visualizations,
                                      source_data_name=self.get_run_name(),
                                      years=range(start, end + 1))

        self.batch_processor.run()
Beispiel #4
0
    def __init__(self, mainwindow, resultsManagerBase, batch_name = None,
                 run_name = None):
        QDialog.__init__(self, mainwindow)
        self.setupUi(self)

        #mainwindow is an OpusGui
        self.mainwindow = mainwindow
        self.resultsManagerBase = resultsManagerBase
        self.project = resultsManagerBase.project

        self.available_years_for_simulation_runs = {}

        self.batch_processor = BatchProcessor(project = self.project)

        self.batch_processor.guiElement = self

        self.run_name = run_name
        self.batch_name = batch_name

        self._setup_co__years()
Beispiel #5
0
    def on_pb_generate_results_clicked(self):
        run_name = self.current_run
        indicator_name = self.current_indicator
        indicator_dataset = self.current_indicator_dataset
        start_year = int(self.current_year)
        end_year = start_year

        if run_name is None or indicator_name is None or start_year is None:
            return

        key = (run_name, indicator_name, start_year)

        if key in self.already_browsed:
            if not self.generating_results:
                (tab_widget, map_widget) = self.already_browsed[key]
                #                self.swap_visualizations(map_widget, tab_widget)
                self.pb_generate_results.setText('Results Generated')
            else:
                self.queued_results = ('swap', (map_widget, tab_widget))
            return

        self.pb_generate_results.setEnabled(False)
        self.pb_generate_results.setText('Generating Results...')

        indicator_nodes = get_available_indicator_nodes(self.project)

        dataset = None
        for indicator_node in indicator_nodes:
            ind_dataset, name = get_variable_dataset_and_name(indicator_node)
            if name == indicator_name and ind_dataset == indicator_dataset:
                dataset = ind_dataset
                break

        if dataset is None:
            raise Exception('Could not find dataset for indicator %s' %
                            indicator_name)

        table_params = {
            'name': None,
            'output_type': 'tab',
            'indicators': [indicator_name],
        }

        map_params = {'name': None, 'indicators': [indicator_name]}

        visualizations = [('table_per_year', dataset, table_params),
                          ('mapnik_map', dataset, map_params)]

        batch_processor = BatchProcessor(self.project)
        batch_processor.guiElement = self

        batch_processor.set_data(visualizations=visualizations,
                                 source_data_name=run_name,
                                 years=range(start_year, end_year + 1))

        if not self.generating_results:
            self.generating_results = True
            logger.log_note(
                'Generating results for %s on run %s for year %indicator_node'
                % (run_name, indicator_name, start_year))
            self.running_key = key
            self.batch_processor = batch_processor
            batch_processor_thread = OpusGuiThread(
                parentThread=get_mainwindow_instance(),
                parentGuiElement=self,
                thread_object=self.batch_processor)

            # Use this signal from the thread if it is capable of producing its own status signal
            self.connect(batch_processor_thread,
                         SIGNAL("runFinished(PyQt_PyObject)"),
                         self._run_finished)
            self.connect(batch_processor_thread,
                         SIGNAL("runError(PyQt_PyObject)"), self._run_error)

            batch_processor_thread.start()
        else:
            self.queued_results = (key, batch_processor)
    try: import wingdbstub
    except: pass
    option_group = MakeIndicatorsOptionGroup()
    parser = option_group.parser
    (options, args) = parser.parse_args()
    
    if not (options.xml_configuration and
            options.indicator_batch and
            ( options.cache_directory or 
              options.run_name) and
            options.years
            ):
        parser.print_help()
        sys.exit(0)
    
    from opus_gui.results_manager.run.batch_processor import BatchProcessor
    project = OpusProject()
    project.open(options.xml_configuration)
    bp = BatchProcessor(project)
    visualizations = get_batch_configuration(project = project,
                                             batch_name = options.indicator_batch)
    
    bp.set_data(visualizations=visualizations,
                source_data_name = options.run_name,
                cache_directory = options.cache_directory,
                years = eval(options.years),
                )
    bp.errorCallback = lambda x: x     ## 
    bp.finishedCallback = lambda x: x  ## hack to work around BatchProcessor
    bp.run()