Ejemplo n.º 1
0
 def run(self):
     # Prepare
     scenarioInput = self.input
     scenarioFolder = self.getFolder()
     expandPath = lambda x: os.path.join(scenarioFolder, x)
     # Register demographics
     print 'Registering demographics'
     nodesPath = expandPath('nodes')
     targetPath = self.getDatasetPath()
     sourcePath = expandPath(scenarioInput['demographic file name'])
     datasetStore = dataset_store.create(targetPath, sourcePath)
     datasetStore.saveNodesSHP(nodesPath)
     datasetStore.saveNodesCSV(nodesPath)
     # Apply metric
     print 'Applying metric'
     metricModel = metric.getModel(scenarioInput['metric model name'])
     metricConfiguration = scenarioInput['metric configuration']
     metricValueByOptionBySection = datasetStore.applyMetric(metricModel, metricConfiguration)
     # Build network
     print 'Building network'
     networkModel = network.getModel(scenarioInput['network model name'])
     networkConfiguration = scenarioInput['network configuration']
     networkValueByOptionBySection = datasetStore.buildNetwork(networkModel, networkConfiguration)
     # Update metric
     print 'Updating metric'
     metricValueByOptionBySection = datasetStore.updateMetric(metricModel, metricValueByOptionBySection)
     # Save output
     print 'Saving output'
     metric.saveMetricsCSV(expandPath('metrics-global'), metricModel, metricValueByOptionBySection)
     datasetStore.saveMetricsCSV(expandPath('metrics-local'), metricModel)
     datasetStore.saveSegmentsSHP(expandPath('networks-existing'), is_existing=True)
     datasetStore.saveSegmentsSHP(expandPath('networks-proposed'), is_existing=False)
     # Bundle
     store.zipFolder(scenarioFolder + '.zip', scenarioFolder)
     # Validate
     self.validateParameters()
     # Save output
     self.output = {
         'variables': { 
             'node': dict((str(x.id), dict(input=x.input, output=x.output)) for x in datasetStore.cycleNodes()),
             'metric': metricValueByOptionBySection,
             'network': networkValueByOptionBySection,
         }, 
         'statistics': { 
             'node': datasetStore.getNodeStatistics(), 
             'metric': datasetStore.getMetricStatistics(), 
             'network': datasetStore.getNetworkStatistics(), 
         }, 
         'warnings': store.popWarnings(self.id),
     }
     # Commit
     Session.commit()
Ejemplo n.º 2
0
    def test_scenarioRun(self):
        'for now, just make sure it runs'
        sourcePath = os.path.join(inputDataPath, "sample_demand_nodes.csv")
        # make output dir if not exists
        if not os.path.exists(outputDataPath):
            os.makedirs(outputDataPath)

        targetPath = os.path.join(outputDataPath, "dataset.db")
        datasetStore = dataset_store.create(targetPath, sourcePath)
        
        """
        // Sample Model Parameter JSON
        metricValueByOptionBySection = {
            'demand (household)': 
                {'household unit demand per household per year': 50}
        }
        """
        metricConfigPath = os.path.join(baseDirPath, "sample_metric_params.json")
        metricConfiguration = json.load(open(metricConfigPath, 'r'))

        """
        // Sample Model Parameter JSON
        networkValueByOptionBySection = {
            'algorithm': 
                {'minimum node count per subnetwork': 2}
        }
        """
        networkConfigPath = os.path.join(baseDirPath, "network_params.json")
        networkConfiguration = json.load(open(networkConfigPath, 'r'))

        # Run metric model
        metricModel = metric.getModel("mvMax5")
        metricValueByOptionBySection = datasetStore.applyMetric(metricModel, metricConfiguration)

        # Now that metrics (mvMax in particular) have been calculated
        # we can build the network
        networkModel = network.getModel("modKruskal")
        networkValueByOptionBySection = datasetStore.buildNetwork(networkModel, networkConfiguration)

        # Now that the network's been built (and the electrification option 
        # is chosen) run the aggregate calculations
        metricValueByOptionBySection = datasetStore.updateMetric(metricModel, metricValueByOptionBySection)

        metric.saveMetricsConfigurationCSV(os.path.join(outputDataPath, 'metrics-job-input'), metricConfiguration)
        metric.saveMetricsCSV(os.path.join(outputDataPath, 'metrics-global'), metricModel, metricValueByOptionBySection)
        datasetStore.saveMetricsCSV(os.path.join(outputDataPath, 'metrics-local'), metricModel)
        datasetStore.saveSegmentsSHP(os.path.join(outputDataPath, 'networks-proposed'), is_existing=False)
Ejemplo n.º 3
0
    def _save_output(self, metric_value_by_option_by_section, metric_config,
                    metric_model):

        output_directory = self.output_directory
        metric.saveMetricsConfigurationCSV(os.path.join(output_directory,
            'metrics-job-input'), metric_config)
        metric.saveMetricsCSV(os.path.join(output_directory,
            'metrics-global'),
            metric_model,
            metric_value_by_option_by_section)
        self.store.saveMetricsCSV(os.path.join(output_directory,
            'metrics-local'),
            metric_model,
            VS.HEADER_TYPE_ALIAS)
        # underlying library can't handle unicode strings so cast via str
        self.store.saveSegmentsSHP(os.path.join(str(output_directory),
            'networks-proposed'), is_existing=False)
Ejemplo n.º 4
0
    def _save_output(self,
                     metric_value_by_option_by_section,
                     metric_config,
                     metric_model,
                     header_type=VS.HEADER_TYPE_SECTION_OPTION):

        output_directory = self.output_directory
        metric.saveMetricsConfigurationCSV(
            os.path.join(output_directory, 'metrics-job-input'), metric_config)
        metric.saveMetricsCSV(os.path.join(output_directory, 'metrics-global'),
                              metric_model, metric_value_by_option_by_section)
        self.store.saveMetricsCSV(
            os.path.join(output_directory, 'metrics-local'), metric_model,
            header_type)
        # underlying library can't handle unicode strings so cast via str
        self.store.saveSegmentsSHP(os.path.join(str(output_directory),
                                                'networks-proposed'),
                                   is_existing=False)
Ejemplo n.º 5
0
 def run(self):
     # Prepare
     scenarioInput = self.input
     scenarioFolder = self.getFolder()
     expandPath = lambda x: os.path.join(scenarioFolder, x)
     # Setup status reporting
     from time import localtime, strftime
     time_format = "%Y-%m-%d %H:%M:%S"
     
     # Register demographics
     Job.log("Registering demographics")
     print "%s Registering demographics" % strftime(time_format, localtime())
     nodesPath = expandPath('nodes')
     targetPath = self.getDatasetPath()
     sourcePath = expandPath(scenarioInput['demographic file name'])
     datasetStore = dataset_store.create(targetPath, sourcePath)
     datasetStore.saveNodesSHP(nodesPath)
     datasetStore.saveNodesCSV(nodesPath)
     # Apply metric
     Job.log("Applying metric")
     print "%s Applying metric" % strftime(time_format, localtime())
     metricModel = metric.getModel(scenarioInput['metric model name'])
     metricConfiguration = scenarioInput['metric configuration']
     metricValueByOptionBySection = datasetStore.applyMetric(metricModel, metricConfiguration)
     # Build network
     Job.log("Building network")
     print "%s Building network" % strftime(time_format, localtime())
     networkModel = network.getModel(scenarioInput['network model name'])
     networkConfiguration = scenarioInput['network configuration']
     networkValueByOptionBySection = datasetStore.buildNetwork(networkModel, networkConfiguration, jobLogger=Job)
     # Update metric
     Job.log("Updating metric")
     print "%s Updating metric" % strftime(time_format, localtime())
     metricValueByOptionBySection = datasetStore.updateMetric(metricModel, metricValueByOptionBySection)
     # Save output
     Job.log("Saving output")
     print "%s Saving output" % strftime(time_format, localtime())
     metric.saveMetricsConfigurationCSV(expandPath('metrics-job-input'), metricConfiguration)
     metric.saveMetricsCSV(expandPath('metrics-global'), metricModel, metricValueByOptionBySection)
     datasetStore.saveMetricsCSV(expandPath('metrics-local'), metricModel)
     datasetStore.saveSegmentsSHP(expandPath('networks-existing'), is_existing=True)
     datasetStore.saveSegmentsSHP(expandPath('networks-proposed'), is_existing=False)
     # Bundle
     store.zipFolder(scenarioFolder + '.zip', scenarioFolder)
     # Validate
     self.validateParameters()
     # Save output
     self.output = {
         'variables': { 
             'node': dict((str(x.id), dict(input=x.input, output=x.output)) for x in datasetStore.cycleNodes()),
             'metric': metricValueByOptionBySection,
             'network': networkValueByOptionBySection,
         }, 
         'statistics': { 
             'node': datasetStore.getNodeStatistics(), 
             'metric': datasetStore.getMetricStatistics(), 
             'network': datasetStore.getNetworkStatistics(), 
         }, 
         'warnings': store.popWarnings(self.id),
     }
     # Commit
     Session.commit()
Ejemplo n.º 6
0
    outputDataPath = args.output_path
    if not os.path.exists(outputDataPath):
        os.makedirs(outputDataPath)

    targetPath = os.path.join(outputDataPath, "dataset.db")
    datasetStore = dataset_store.create(targetPath, args.input_nodes_file)

    # setup models
    metricModel = metric.getModel(args.metric_model_name)
    metricConfiguration = json.load(args.metric_model_params)
    networkModel = network.getModel(args.network_model_name)
    networkConfiguration = json.load(args.network_model_params)

    # Run metric model
    metricValueByOptionBySection = datasetStore.applyMetric(metricModel, metricConfiguration)

    # Now that metrics (mvMax in particular) have been calculated
    # we can build the network
    networkValueByOptionBySection = datasetStore.buildNetwork(networkModel, networkConfiguration)

    # Now that the network's been built (and the electrification option 
    # is chosen) run the aggregate calculations
    metricValueByOptionBySection = datasetStore.updateMetric(metricModel, metricValueByOptionBySection)

    metric.saveMetricsConfigurationCSV(os.path.join(outputDataPath, 'metrics-job-input'), metricConfiguration)
    metric.saveMetricsCSV(os.path.join(outputDataPath, 'metrics-global'), metricModel, metricValueByOptionBySection)
    datasetStore.saveMetricsCSV(os.path.join(outputDataPath, 'metrics-local'), metricModel, args.header_type)
    datasetStore.saveSegmentsSHP(os.path.join(outputDataPath, 'networks-proposed'), is_existing=False)