Esempio n. 1
0
    def check_variable(self, check='syntax'):
        '''
        validate the variable and display the result in i dialog box
        if check_syntax is True a syntax check is performed, otherwise a data
        check is performed.
        '''
        if check == 'syntax':
            func = batch_check_syntax
        elif check == 'data':
            func = batch_check_data
        else:
            raise ValueError(
                'check_variable() got an unknown value for argument "check"; "%s"'
                % check)

        self._update_variable_from_fields()
        dummy, result, msgs = func([
            self.variable,
        ], self.validator)[0]
        if result is True:
            text = '%s check OK' % check
            MessageBox.information(mainwindow=self, text=text)
        else:
            text = 'Encountered a %s error' % check
            MessageBox.warning(mainwindow=self,
                               text=text,
                               detailed_text='\n '.join(msgs))
Esempio n. 2
0
 def on_syntaxButton_clicked(self):
     node = self._checkImportNodeMsg()
     if node is None:
         return
     
     MessageBox.information(self, 'Check passed!',
                            self.ATTENTION)
Esempio n. 3
0
    def _show_problem_variables(self):
        ''' shows the current list of problem variables '''
        if not self.problem_variables:
            MessageBox.information(self, 'All tested variables passed.')
            return

        msg = '<qt>'
        for dummy, err_msg in self.problem_variables:
            msg += '<br/>'.join(err_msg)
            msg += '<br/><br/>'
        msg += '</qt>'
        txt = 'Found problems with %d of the variables' % len(self.problem_variables)
        MessageBox.warning(self, txt, msg)
Esempio n. 4
0
    def _show_problem_variables(self):
        ''' shows the current list of problem variables '''
        if not self.problem_variables:
            MessageBox.information(self, 'All tested variables passed.')
            return

        msg = '<qt>'
        for dummy, err_msg in self.problem_variables:
            msg += '<br/>'.join(err_msg)
            msg += '<br/><br/>'
        msg += '</qt>'
        txt = 'Found problems with %d of the variables' % len(
            self.problem_variables)
        MessageBox.warning(self, txt, msg)
 def send_to_urbancanvas(self):
     '''
     Sends to UrbanCanvas for visualization.
     '''
     self._update_variable_from_fields()
     func = batch_check_data
     dummy, result, msgs = func([self.variable,], self.validator)[0]
     expression = dummy['definition']
     if dummy['dataset'] == 'parcel':
         from opus_core.storage_factory import StorageFactory
         from opus_core.datasets.dataset_pool import DatasetPool
         import os, sys
         base_year = self.validator.project.xml_config.get_estimation_configuration()['base_year']
         project_name = self.validator.project.name
         opus_data_path = self.validator.project.xml_config.get_opus_data_path()
         logger.log_note(base_year)
         logger.log_note(project_name)
         logger.log_note(opus_data_path)
         cache = os.path.join(opus_data_path,project_name,'base_year_data',str(base_year))
         logger.log_note(cache)
         storage = StorageFactory().get_storage('flt_storage',storage_location=cache)
         dataset_pool = DatasetPool(storage=storage, package_order=[project_name,'urbansim_parcel','urbansim','opus_core'])
         parcels = dataset_pool.get_dataset('parcel')
         parcel_ids = pd.Series(parcels.get_attribute('parcel_id'))
         values = pd.Series(parcels.compute_variables([expression],dataset_pool=dataset_pool).astype('float'))
         parcels = pd.DataFrame({"parcel_id":parcel_ids,"vl_values":values})
         parcels.set_index(keys='parcel_id',inplace=True)
         #parcels["vl_values"][parcels["vl_values"]==0] = np.nan
         parcels = parcels[parcels["vl_values"]>0]
         
         os.chdir(os.path.join(opus_data_path,project_name))
         
         np.savez('variable_library_indicator',parcel_id=parcels.vl_values.index.values.astype('int32'),values=parcels.vl_values.values.astype('int32'))
         
         ##############UNCOMMENT IF WEBSERVICE IS DESIRED
         # parcels.save('variable_library.pkl') ##I believe 'save' was just deprectated in pandas- its now to_pickle or some such thing... change this later
         # web_service_path = os.path.join(os.getenv("OPUS_HOME"),'src',project_name,'scripts','web_service.py')
         # logger.log_note(web_service_path)
         # p = subprocess.Popen([sys.executable,web_service_path])
         # MessageBox.information(mainwindow = self, text = 'Click OK when done viewing in UrbanCanvas')
         # p.kill()
         
         MessageBox.information(mainwindow = self, text = 'Variable exported to the project data directory for viewing in UrbanCanvas')
         
     else:
         MessageBox.information(mainwindow = self, text = 'Not a parcel variable. Only parcel variables can be sent to UrbanCanvas')
Esempio n. 6
0
 def send_to_urbancanvas(self):
     '''
     Sends to UrbanCanvas for visualization.
     '''
     self._update_variable_from_fields()
     func = batch_check_data
     dummy, result, msgs = func([self.variable,], self.validator)[0]
     expression = dummy['definition']
     if dummy['dataset'] == 'parcel':
         from opus_core.storage_factory import StorageFactory
         from opus_core.datasets.dataset_pool import DatasetPool
         import os, sys
         base_year = self.validator.project.xml_config.get_estimation_configuration()['base_year']
         project_name = self.validator.project.name
         opus_data_path = self.validator.project.xml_config.get_opus_data_path()
         logger.log_note(base_year)
         logger.log_note(project_name)
         logger.log_note(opus_data_path)
         cache = os.path.join(opus_data_path,project_name,'base_year_data',str(base_year))
         logger.log_note(cache)
         storage = StorageFactory().get_storage('flt_storage',storage_location=cache)
         dataset_pool = DatasetPool(storage=storage, package_order=[project_name,'urbansim_parcel','urbansim','opus_core'])
         parcels = dataset_pool.get_dataset('parcel')
         parcel_ids = pd.Series(parcels.get_attribute('parcel_id'))
         values = pd.Series(parcels.compute_variables([expression],dataset_pool=dataset_pool).astype('float'))
         parcels = pd.DataFrame({"parcel_id":parcel_ids,"vl_values":values})
         #parcels.set_index(keys='parcel_id',inplace=True)
         #parcels["vl_values"][parcels["vl_values"]==0] = np.nan
         parcels = parcels[parcels["vl_values"]>0]
         
         os.chdir(os.path.join(opus_data_path,project_name))
         parcels.to_csv('variable_library_indicator.csv',index=False)
         #np.savez('variable_library_indicator',parcel_id=parcels.vl_values.index.values.astype('int32'),values=parcels.vl_values.values.astype('int32'))
         
         ##############UNCOMMENT IF WEBSERVICE IS DESIRED
         # parcels.save('variable_library.pkl') ##I believe 'save' was just deprectated in pandas- its now to_pickle or some such thing... change this later
         # web_service_path = os.path.join(os.getenv("OPUS_HOME"),'src',project_name,'scripts','web_service.py')
         # logger.log_note(web_service_path)
         # p = subprocess.Popen([sys.executable,web_service_path])
         # MessageBox.information(mainwindow = self, text = 'Click OK when done viewing in UrbanCanvas')
         # p.kill()
         
         MessageBox.information(mainwindow = self, text = 'Variable exported to the project data directory for viewing in UrbanCanvas')
         
     else:
         MessageBox.information(mainwindow = self, text = 'Not a parcel variable. Only parcel variables can be sent to UrbanCanvas')
    def check_variable(self, check = 'syntax'):
        '''
        validate the variable and display the result in i dialog box
        if check_syntax is True a syntax check is performed, otherwise a data
        check is performed.
        '''
        if check == 'syntax':
            func = batch_check_syntax
        elif check == 'data':
            func = batch_check_data
        else:
            raise ValueError('check_variable() got an unknown value for argument "check"; "%s"' % check)

        self._update_variable_from_fields()
        dummy, result, msgs = func([self.variable,], self.validator)[0]
        if result is True:
            text = '%s check OK' % check
            MessageBox.information(mainwindow = self, text = text)
        else:
            text = 'Encountered a %s error' % check
            MessageBox.warning(mainwindow = self, text = text, detailed_text = '\n '.join(msgs))
    def _scanForRuns(self):
        run_manager = get_run_manager()
        run_manager.clean_runs()
        run_manager.close()

        added_runs, removed_runs = update_available_runs(self.project)
        added_msg = removed_msg = None
        if len(added_runs) > 0:
            added_msg = ('The following simulation runs have been '
                         'automatically added to the results manager:\n\n%s'
                         % '\n'.join(added_runs))
        if len(removed_runs) > 0:
            removed_msg = ('The following simulation runs have been '
                         'automatically removed from the results manager:\n\n%s'
                         % '\n'.join(removed_runs))
        if added_msg or removed_msg:
            self.project.dirty = True
            text = 'The list of simulation runs has been automatically updated.'
            detailed_text = '%s\n\n%s' % (added_msg or '', removed_msg or '')
            MessageBox.information(mainwindow = self.base_widget,
                                   text = text,
                                   detailed_text = detailed_text)
Esempio n. 9
0
    def _scanForRuns(self):
        run_manager = get_run_manager()
        run_manager.clean_runs()
        run_manager.close()

        added_runs, removed_runs = update_available_runs(self.project)
        added_msg = removed_msg = None
        if len(added_runs) > 0:
            added_msg = ('The following simulation runs have been '
                         'automatically added to the results manager:\n\n%s' %
                         '\n'.join(added_runs))
        if len(removed_runs) > 0:
            removed_msg = (
                'The following simulation runs have been '
                'automatically removed from the results manager:\n\n%s' %
                '\n'.join(removed_runs))
        if added_msg or removed_msg:
            self.project.dirty = True
            text = 'The list of simulation runs has been automatically updated.'
            detailed_text = '%s\n\n%s' % (added_msg or '', removed_msg or '')
            MessageBox.information(mainwindow=self.base_widget,
                                   text=text,
                                   detailed_text=detailed_text)
Esempio n. 10
0
    def on_pb_urbancanvas_clicked(self):
        
        run_name = self.current_run
        indicator_name = self.current_indicator
        indicator_dataset = self.current_indicator_dataset
        if indicator_dataset != 'parcel':
            MessageBox.information(mainwindow = self, text = 'Not a parcel variable. Only parcel variables can be sent to UrbanCanvas')
        else:
            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)

            self.pb_urbancanvas.setText('Sending to UrbanCanvas...')

            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],
            }
            expression_library = self.project.xml_config.get_expression_library()
            expression = expression_library[(dataset,name)]
            logger.log_note(expression)
            
            base_year = end_year
            project_name = self.project.name
            opus_data_path = self.project.xml_config.get_opus_data_path()
            logger.log_note(base_year)
            logger.log_note(project_name)
            logger.log_note(opus_data_path)
            interface = IndicatorFrameworkInterface(self.project)
            source_data = interface.get_source_data(
                                 source_data_name = run_name,
                                 years = [end_year,]
            )
            cache = os.path.join(source_data.cache_directory,str(end_year))
            logger.log_note(cache)
            storage = StorageFactory().get_storage('flt_storage',storage_location=cache)
            dataset_pool = DatasetPool(storage=storage, package_order=[project_name,'urbansim_parcel','urbansim','opus_core'])
            parcels = dataset_pool.get_dataset('parcel')
            parcel_ids = pd.Series(parcels.get_attribute('parcel_id'))
            values = pd.Series(parcels.compute_variables([expression],dataset_pool=dataset_pool).astype('float'))
            parcels = pd.DataFrame({"parcel_id":parcel_ids,"vl_values":values})
            #parcels.set_index(keys='parcel_id',inplace=True)
            #parcels["vl_values"][parcels["vl_values"]==0] = np.nan
            parcels = parcels[parcels["vl_values"]>0]
            
            os.chdir(os.path.join(opus_data_path,project_name))
            parcels.to_csv('results_browser_indicator.csv',index=False)
            #np.savez('results_browser_indicator',parcel_id=parcels.vl_values.index.values.astype('int32'),values=parcels.vl_values.values.astype('int32'))
            
            ##############UNCOMMENT IF WEBSERVICE IS DESIRED
            # parcels.save('variable_library.pkl') ##I believe 'save' was just deprectated in pandas- its now to_pickle or some such thing... change this later
            # web_service_path = os.path.join(os.getenv("OPUS_HOME"),'src',project_name,'scripts','web_service.py')
            # logger.log_note(web_service_path)
            # p = subprocess.Popen([sys.executable,web_service_path])
            # MessageBox.information(mainwindow = self, text = 'Click OK when done viewing in UrbanCanvas')
            # p.kill()
            # self.pb_urbancanvas.setText('View in UrbanCanvas')
            
            MessageBox.information(mainwindow = self, text = 'Variable exported to the project data directory for viewing in UrbanCanvas')
            self.pb_urbancanvas.setText('View in UrbanCanvas')
Esempio n. 11
0
    def on_pb_urbancanvas_clicked(self):

        run_name = self.current_run
        indicator_name = self.current_indicator
        indicator_dataset = self.current_indicator_dataset
        if indicator_dataset != 'parcel':
            MessageBox.information(
                mainwindow=self,
                text=
                'Not a parcel variable. Only parcel variables can be sent to UrbanCanvas'
            )
        else:
            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)

            self.pb_urbancanvas.setText('Sending to UrbanCanvas...')

            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],
            }
            expression_library = self.project.xml_config.get_expression_library(
            )
            expression = expression_library[(dataset, name)]
            logger.log_note(expression)

            base_year = end_year
            project_name = self.project.name
            opus_data_path = self.project.xml_config.get_opus_data_path()
            logger.log_note(base_year)
            logger.log_note(project_name)
            logger.log_note(opus_data_path)
            interface = IndicatorFrameworkInterface(self.project)
            source_data = interface.get_source_data(source_data_name=run_name,
                                                    years=[
                                                        end_year,
                                                    ])
            cache = os.path.join(source_data.cache_directory, str(end_year))
            logger.log_note(cache)
            storage = StorageFactory().get_storage('flt_storage',
                                                   storage_location=cache)
            dataset_pool = DatasetPool(storage=storage,
                                       package_order=[
                                           project_name, 'urbansim_parcel',
                                           'urbansim', 'opus_core'
                                       ])
            parcels = dataset_pool.get_dataset('parcel')
            parcel_ids = pd.Series(parcels.get_attribute('parcel_id'))
            values = pd.Series(
                parcels.compute_variables(
                    [expression], dataset_pool=dataset_pool).astype('float'))
            parcels = pd.DataFrame({
                "parcel_id": parcel_ids,
                "vl_values": values
            })
            #parcels.set_index(keys='parcel_id',inplace=True)
            #parcels["vl_values"][parcels["vl_values"]==0] = np.nan
            parcels = parcels[parcels["vl_values"] > 0]

            os.chdir(os.path.join(opus_data_path, project_name))
            parcels.to_csv('results_browser_indicator.csv', index=False)
            #np.savez('results_browser_indicator',parcel_id=parcels.vl_values.index.values.astype('int32'),values=parcels.vl_values.values.astype('int32'))

            ##############UNCOMMENT IF WEBSERVICE IS DESIRED
            # parcels.save('variable_library.pkl') ##I believe 'save' was just deprectated in pandas- its now to_pickle or some such thing... change this later
            # web_service_path = os.path.join(os.getenv("OPUS_HOME"),'src',project_name,'scripts','web_service.py')
            # logger.log_note(web_service_path)
            # p = subprocess.Popen([sys.executable,web_service_path])
            # MessageBox.information(mainwindow = self, text = 'Click OK when done viewing in UrbanCanvas')
            # p.kill()
            # self.pb_urbancanvas.setText('View in UrbanCanvas')

            MessageBox.information(
                mainwindow=self,
                text=
                'Variable exported to the project data directory for viewing in UrbanCanvas'
            )
            self.pb_urbancanvas.setText('View in UrbanCanvas')
Esempio n. 12
0
    def on_syntaxButton_clicked(self):
        node = self._checkImportNodeMsg()
        if node is None:
            return

        MessageBox.information(self, 'Check passed!', self.ATTENTION)