예제 #1
0
 def _Execute(self):
     with _m.logbook_trace(name="{classname} v{version}".format(classname=(self.__class__.__name__), version=self.version),
                                  attributes=self._GetAtts()):
         
         try:
             networkCalculationTool = _m.Modeller().tool("inro.emme.network_calculation.network_calculator")
         except Exception, e:
             networkCalculationTool = _m.Modeller().tool("inro.emme.standard.network_calculation.network_calculator")
         
         with self._lineAttributeMANAGER() as flagAttributeId:
             with _m.logbook_trace("Flagging slected lines"):
                 self.TRACKER.runTool(networkCalculationTool, 
                                      self._GetNetCalcSpec(flagAttributeId), self.Scenario)
             
             network = self.Scenario.get_network()
             
             flaggedLines = [line for line in network.transit_lines() if line[flagAttributeId] == 1]
             self.TRACKER.startProcess(len(flaggedLines))
             for line in flaggedLines:
                 self._ProcessLine(line)
                 self.TRACKER.completeSubtask()
             self.TRACKER.completeTask()
                 
             self.Scenario.publish_network(network)
         
         return len(flaggedLines)
예제 #2
0
 def _Execute(self):
     with _m.logbook_trace(name="{classname} v{version}".format(classname=(self.__class__.__name__), version=self.version),
                                  attributes=self._GetAtts()):
         
         with _m.logbook_trace("Loading shapefile"):
             boundaries = self._LoadCheckGeometry()
         
         network = self.Scenario.get_network()
         self.TRACKER.completeTask()
         
         with _m.logbook_trace("Classifying nodes"):
             self._ClassifyNodes(network, boundaries)
             
         with _m.logbook_trace("Renumbering nodes"):
             fixedNodeIDs = self._OffsetNodeNumbers(network)
             _m.logbook_write("Offset node numbers")
             
             mappings = self._RenumberNodes(network, fixedNodeIDs)
             _m.logbook_write("Re-numbered nodes")
         
         if self.ReportFlag:
             _m.logbook_write("Conversion Report", value=self._WriteMappingsReport(mappings))
         
         self.Scenario.publish_network(network, True)
         self.TRACKER.completeTask()
         
         self.tool_run_msg = _m.PageBuilder.format_info("Done. %s nodes were renumbered." %len(mappings))
 def _Execute(self):
     with _m.logbook_trace(name="{classname} v{version}".format(classname=(self.__class__.__name__), version=self.version),
                                  attributes=self._GetAtts()):
         
         with self._zipFileMANAGER() as zf:
             reader = zf.open('run_order.txt', 'rU')
             try:
                 scripts = [line.strip() for line in reader]
             finally:
                 reader.close()
                             
             self.TRACKER.reset(len(scripts))
             nl = set(zf.namelist())
             
             for script in scripts:
                 if script.endswith(".mac"):
                     if not script in nl:
                         raise IOError("NUP file formatting error: Script %s does not exist" %script)
                     
                     with _m.logbook_trace("Running MACRO %s" %script):
                         self._RunMacro(zf, script)
                 elif script.endswith(".py"):
                     if not script in nl:
                         raise IOError("NUP file formatting error: Script %s does not exist" %script)
                     with _m.logbook_trace("Running PY_SCRIPT %s" %script):
                         self._RunPythonScript(zf, script)
                 else:
                     _m.logbook_write("Script type of '%'s not supported" %script)
                 self.TRACKER.completeTask()
 def _Execute(self):
     with _m.logbook_trace(name="{classname} v{version}".format(classname=(self.__class__.__name__), version=self.version),
                                  attributes=self._GetAtts()):
         
         managers = [_util.tempMatrixMANAGER("Walk-all-way matrix"),
                     _util.tempExtraAttributeMANAGER(self.Scenario, 'TRANSIT_SEGMENT',
                                                     description= "Initial boardings attribute"),
                     _util.tempExtraAttributeMANAGER(self.Scenario, 'TRANSIT_SEGMENT',
                                                     description= "Final alightings attribute"),
                     getTemporaryFolder()]
         
         #Handle creating the transit line attribute in which to flag groups (if required). 
         if self.LineGroupOptionOrAttributeId.isdigit():
             managers.insert(0, _util.tempExtraAttributeMANAGER(self.Scenario, 'TRANSIT_LINE',
                                                                description= "Line group ID",
                                                                returnId= True))
             lineGroupOption = int(self.LineGroupOptionOrAttributeId)
         else:
             managers.insert(0, blankContextManager(self.LineGroupOptionOrAttributeId))
             lineGroupOption = 0
         
         with nested(*managers) as (lineGroupAtributeID, walkAllWayMatrix, 
                                    boardAttribute, alightAttribute,
                                    tempFolder):
             
             #---1. Flag pre-built groupings, if needed
             if lineGroupOption and self.ExportTransferMatrixFlag:
                 with _m.logbook_trace("Applying pre-built groupings"):
                     self._ApplyPreBuiltCodes(lineGroupOption, lineGroupAtributeID)
             self.TRACKER.completeTask()
             
             #---2. Get the traversal matrix
             if self.ExportTransferMatrixFlag:
                 transferMatrix = self._GetTraversalMatrix(lineGroupAtributeID, tempFolder)
                 
                 
                 #---3. Attach initial boarding and final alighting data to matrix
                 self._GetBoardingsAndAlightings(transferMatrix, lineGroupAtributeID, 
                                                 boardAttribute.id, alightAttribute.id)
                 print "Loaded initial boardings and final alightings"
             else: transferMatrix = None 
             
             #---4. Get the walk-all-way matrix
             self._GetWalkAllWayMatrix(walkAllWayMatrix, transferMatrix)
             print "Loaded walk all-way matrix"
             
             #---5. Export the transfer matrix
             if self.ExportTransferMatrixFlag:
                 self._WriteExportFile(transferMatrix)
             
             #---6. Export the aggregated walk-all-way matrix (if desired)
             if self.ExportWalkAllWayMatrixFlag:
                 self._ExportWalkAllWayMatrix(walkAllWayMatrix)
예제 #5
0
    def _Execute(self):
        with _m.logbook_trace(name="{classname} v{version}".format(classname=(self.__class__.__name__), version=self.version),
                                     attributes=self._GetAtts()):
            
            tool = _MODELLER.tool('inro.emme.network_calculation.network_calculator')

            with _m.logbook_trace("Calulating light zone tolls"):
                self.TRACKER.runTool(tool, scenario=self.Scenario,
                                 specification=self._GetZoneSpec(1, self.LightZoneToll))

            with _m.logbook_trace("Calculating regular zone tolls"):
                self.TRACKER.runTool(tool, scenario=self.Scenario,
                                 specification=self._GetZoneSpec(2, self.RegularZoneToll))
 def _Execute(self):
     with _m.logbook_trace(name="{classname} v{version}".format(classname=(self.__class__.__name__), version=self.version),
                                  attributes=self._GetAtts()):
         
         tool = _MODELLER.tool('inro.emme.network_calculation.network_calculator')
         
         self.TRACKER.reset(len(self.Scenarios))
         
         for scenario in self.Scenarios:
             with _m.logbook_trace("Processing scenario %s" %scenario):
                 self._ProcessScenario(scenario)
             self.TRACKER.completeTask()
             
         _MODELLER.desktop.refresh_needed(True)
 def _execute(self):
     
     with _m.logbook_trace(name="Extract transit feasibility matrix v%s" %self.version,
                                  attributes={
                                              "Scenario" : self.scenario.id,
                                              "Walk Time Cutoff" : self.WalkTimeCutoff,
                                              "Wait Time Cutoff": self.WaitTimeCutoff,
                                              "Total Time Cutoff": self.TotalTimeCutoff,
                                              "ModeString": self.ModeString,
                                              "Is running from XTMF?" : str(self.isRunningFromXTMF),
                                              "self": self.__MODELLER_NAMESPACE__}):
         
         self._assignmentCheck()
         
         #---1 Initialize temporary matrices for storing walk, wait, and in-vehicle times
         with nested(_util.tempMatrixMANAGER(description='Temp walk time matrix'),
                     _util.tempMatrixMANAGER(description='Temp wait time matrix'),
                     _util.tempMatrixMANAGER(description='Temp ivtt matrix'))\
                 as (self.walkMatrix, self.waitMatrix, self.ivttMatrix):
         
             #---2 Compute the temporary matrices
             _m.logbook_write("Computing temporary matrices")
             self.matrixResultTool(self._getStrategyAnalysisSpec())
             
             #---3 Compute the final results matrix
             _m.logbook_write("Computing feasibility matrix")
             if EMME_VERSION >= (4,2,1):
                 self.matrixCalcTool(self._getMatrixCalcSpec(), self.scenario,
                                          num_processors=self.NumberOfProcessors)  
             else: 
                 self.matrixCalcTool(self._getMatrixCalcSpec(), self.scenario)         
    def __call__(self, MatrixId, Filename, ScenarioNumber):
        with _m.logbook_trace("Exporting matrix %s to XTMF" % MatrixId):
            scenario = _m.Modeller().emmebank.scenario(ScenarioNumber)
            if (scenario is None):
                raise Exception("Scenario %s was not found!" % ScenarioNumber)

            try:
                tool = None
                try:
                    tool = _m.Modeller().tool(
                        'inro.emme.standard.data.matrix.export_matrices')
                except Exception as e:
                    tool = _m.Modeller().tool(
                        'inro.emme.data.matrix.export_matrices')

                mtx = _m.Modeller().emmebank.matrix("mf%s" % MatrixId)
                if mtx is None:
                    raise Exception("No matrix found with id '%s'" % MatrixId)
                self._tracker.runTool(
                    tool,
                    export_file=Filename,
                    field_separator=' ',
                    matrices=[mtx],
                    full_matrix_line_format="ONE_ENTRY_PER_LINE",
                    export_format="PROMPT_DATA_FORMAT",
                    scenario=scenario,
                    skip_default_values=False)

            except Exception as e:
                raise Exception(_traceback.format_exc(e))
예제 #9
0
 def _Execute(self):
     with _m.logbook_trace(name="{classname} v{version}".format(classname=(self.__class__.__name__), version=self.version),
                                  attributes=self._GetAtts()):
         self.TRACKER.reset()
         if self.TrafficClassAttributeId != None:
             linkResults = _util.fastLoadLinkAttributes(self.Scenario, [self.CountpostAttributeId,
                                                                        self.TrafficClassAttributeId,
                                                                    'auto_volume',
                                                                    'additional_volume',
                                                                    'auto_time'])
         else:
             linkResults = _util.fastLoadLinkAttributes(self.Scenario, [self.CountpostAttributeId,
                                                                    'auto_volume',
                                                                    'additional_volume',
                                                                    'auto_time'])
         
         alternateLinkResults = {}
         if self.AlternateCountpostAttributeId and self.AlternateCountpostAttributeId != "":
             alternateLinkResults = _util.fastLoadLinkAttributes(self.Scenario, 
                                                                 [self.AlternateCountpostAttributeId])
         
         #Remove entries not flagged with a countpost
         self._CleanResults(linkResults, alternateLinkResults)
         
         #Get the countpost data, sorted
         lines = self._ProcessResults(linkResults, alternateLinkResults)
         
         #Write countpost data to file
         self._WriteReport(lines)
예제 #10
0
    def _Execute(self):
        with _m.logbook_trace(name="{classname} v{version}".format(
                classname=(self.__class__.__name__), version=self.version),
                              attributes=self._GetAtts()):

            groupings = self.__options[self.CodeOption]

            tool = _MODELLER.tool(
                'inro.emme.network_calculation.network_calculator')

            def flagGroup(value, selector, descr):
                spec = {
                    "result": self.AttributeId,
                    "expression": str(value),
                    "aggregation": None,
                    "selections": {
                        "transit_line": selector
                    },
                    "type": "NETWORK_CALCULATION"
                }
                with _m.logbook_trace("Flagging %s lines as %s" %
                                      (descr, value)):
                    tool(spec, scenario=self.Scenario)

            self.TRACKER.startProcess(len(groupings))
            for value, selector, description in groupings:
                flagGroup(value, selector, description)
                self.TRACKER.completeSubtask()

            self._WriteTableReport(groupings)
    def __call__(self):
        report = ""

        with _m.logbook_trace(name="Check connector speeds",
                              attributes={
                                  "Scenario": self.Scenario.id,
                                  "self": self.__MODELLER_NAMESPACE__
                              }):
            _m.logbook_write(name="Checking connector speeds for scenario %s" %
                             self.Scenario.id,
                             attributes={"version": "1.00.00"})

            linksChecked = 0
            problemLinks = 0
            for link in self.Scenario.get_network().links():

                if link.i_node.is_centroid or link.j_node.is_centroid:
                    #link is a centroid connector
                    if link.data2 != 40:
                        report += "<br>Centroid connector link <b>" + link.id + "</b> speed should be 40, instead is " + str(
                            link.data2)
                        problemLinks += 1

                linksChecked += 1
            _m.logbook_write(name="Report", value=report)

        self.tool_run_msg = "Tool complete. " + str(
            linksChecked) + " links were checked, " + str(
                problemLinks
            ) + " were flagged as problems. See logbook for details."
예제 #12
0
    def _Execute(self):
        with _m.logbook_trace(name="{classname} v{version}".format(
                classname=(self.__class__.__name__), version=self.version),
                              attributes=self._GetAtts()):

            self.TRACKER.completeTask()

            self.BaseNetwork = self.BaseScenario.get_network()
            self.TRACKER.completeTask()

            self._RemoveLinks(self.BaseNetwork)
            self.TRACKER.completeTask()

            self._RemoveStrandedNodes(self.BaseNetwork)

            self.TRACKER.startProcess(2)

            bank = _MODELLER.emmebank

            if self.NewScenarioFlag:
                newScenario = bank.copy_scenario(self.BaseScenario.id,
                                                 self.NewScenarioId,
                                                 copy_strat_files=False,
                                                 copy_path_files=False)
                newScenario.title = self.NewScenarioTitle
                newScenario.publish_network(self.BaseNetwork, True)
            else:
                self.BaseScenario.publish_network(self.BaseNetwork, True)

            self.TRACKER.completeSubtask()

            _MODELLER.desktop.refresh_needed(True)
            self.TRACKER.completeTask()
예제 #13
0
 def _demandMatrixMANAGER(self):
     #Code here is executed upon entry
     
     with _m.logbook_trace("Initializing temporary demand matrix"):
         id=None
         if self.demandMatrix == None:
             
             self.demandMatrix = _util.initializeMatrix(id,
                                                   matrix_type='SCALAR',
                                                   name='trscal',
                                                   description='Scalar matrix to get transit times')
             
             self._tracker.completeTask()
             
         else:
             cachedMatrix = self.demandMatrix
             self.demandMatrix = _util.initializeMatrix(matrix_type='FULL', description="Constrained full matrix for station-to-station assignment")
             _m.logbook_write("Created temporary constrained full demand matrix '%s'" %id)
             
             try:
                 matrixCalcTool = _m.Modeller().tool("inro.emme.standard.matrix_calculation.matrix_calculator")
             except Exception, e:
                 matrixCalcTool = _m.Modeller().tool("inro.emme.matrix_calculation.matrix_calculator")
             
             self._tracker.runTool(matrixCalcTool,
                                   self._getConstraintSpec(cachedMatrix, self.demandMatrix), 
                                   scenario=self.scenario) #TASK 1
예제 #14
0
    def _Execute(self):
        with _m.logbook_trace(name="{classname} v{version}".format(classname=(self.__class__.__name__), version=self.version),
                                     attributes=self._GetAtts()):
            
            network = self.BaseScenario.get_network()
            print "Loaded network"

            lineIds, lineList = self._ReadSetFile()
            print "Loaded lines"

            unchangedSched, changedSched = self._LoadServiceTable(lineList)
            print "Loaded service table"

            #newLineIds = self._ConcatenateLines(network, lineIds)
            #print "Lines concatenated"    
                                
            moddedSched, removedSched, leftoverSched = self._ModifySched(network, lineIds, changedSched)
            self._WriteNewServiceTable(unchangedSched, moddedSched, removedSched, leftoverSched)
            print "Created modified service table"
            
            #self._WriteUnusedTrips()
            #print "Created unused trip table"

            print "Publishing network"
            self.BaseScenario.publish_network(network)
            self.TRACKER.completeTask()
    def _execute(self):
        with _m.logbook_trace(name="Extract select line matrix v%s" %
                              self.version,
                              attributes={
                                  "Scenario": self.Scenario.id,
                                  "Result Matrix": self.MatrixResultId,
                                  "self": self.__MODELLER_NAMESPACE__
                              }):

            resultMatrix = _util.initializeMatrix(
                self.MatrixResultId,
                name='slctOD',
                description="Transit select line analysis result")

            try:
                strategyAnalysisTool = _m.Modeller().tool(
                    'inro.emme.standard.transit_assignment.extended.strategy_based_analysis'
                )
            except Exception, e:
                strategyAnalysisTool = _m.Modeller().tool(
                    'inro.emme.transit_assignment.extended.strategy_based_analysis'
                )

            self.TRACKER.runTool(strategyAnalysisTool, self._getAnalysisSpec(),
                                 self.Scenario)
    def _Execute(self):
        with _m.logbook_trace(name="{classname} v{version}".format(
                classname=(self.__class__.__name__), version=self.version),
                              attributes=self._GetAtts()):

            if not self.Scenario.has_transit_results:
                raise Exception("Scenario %s has no transit results" %
                                self.Scenario)

            network = self.Scenario.get_network()
            stations, badNodes = self._LoadStationNodeFile(network)

            if len(badNodes) > 0:
                print "%s node IDs were not found in the network and were skipped." % len(
                    badNodes)
                pb = _m.PageBuilder("NodeIDs not in network")

                pb.add_text_element(
                    "<b>The following node IDs were not found in the network:</b>"
                )

                for id in badNodes:
                    pb.add_text_element(id)

                _m.logbook_write(
                    "Some IDs were not found in the network. Click for details.",
                    value=pb.render())

            nodeValues = self._CalcBoardingAlighting(network, stations)
            self._OutputResults(nodeValues)
    def _execute(self):
        with _m.logbook_trace(name="Adding Toolbox (%s v%s)" %
                              (self.__class__.__name__, self.version),
                              attributes=self._getAtts()):

            self._tracker.reset()
            _m.Modeller().desktop.add_modeller_toolbox(self.ModellerLocation)
 def _Execute(self):
     with _m.logbook_trace(name="{classname} v{version}".format(classname=(self.__class__.__name__), version=self.version),
                                  attributes=self._GetAtts()):
         
         routes = self._LoadCheckGtfsRoutesFile()
         self.TRACKER.completeTask()
         
         network = self.Scenario.get_network()
         print "Loaded network"
         self.TRACKER.completeTask()
         
         stops2nodes = self._LoadStopNodeMapFile(network)
         
         trips = self._LoadTrips(routes)
         
         self._LoadPrintStopTimes(trips, stops2nodes)
         
         with open(self.LineServiceTableFile, 'w') as writer:
             self._GenerateLines(routes, stops2nodes, network, writer)
         
         if self.PublishFlag:
             copy = _MODELLER.emmebank.copy_scenario(self.Scenario.id, self.NewScenarioId)
             copy.title = self.NewScenarioTitle
             copy.publish_network(network, True)
         self.TRACKER.completeTask()
 def _Execute(self):
     with _m.logbook_trace(name="{classname} v{version}".format(classname=(self.__class__.__name__), version=self.version),
                                  attributes=self._GetAtts()):
         
         
         adjacencyMatrix = _util.initializeMatrix(id=self.ResultMatrixId, name="zadj", description="Zone adjacency matrix")
         
         network = self.Scenario.get_network()
         _m.logbook_write("Loaded network data")
         with _m.logbook_trace("Loading zone boundaries"):
             self._LoadShapefileGeometry(network)
             self.TRACKER.completeTask()
             
         with _m.logbook_trace("Processing zone adjacencies"):
             self._ProcessAdjacencies(network, adjacencyMatrix)
             self.TRACKER.completeTask()
예제 #20
0
 def _exectue(self):
     with _m.logbook_trace("Renumber nodes from DMG2001 to NCS11"):
         
         report = ""
         
         for Scenario in self.Scenarios:
             network = Scenario.get_network()
             count = 0
             
             for i in range(30000, 80000):
                 # All of the regional nodes from 30,000 to 79,999 
                 # must be shifted down by 10,000.
                 # Cycling through them from bottom-up, to ensure no id conflicts occur.
                 n = network.node(i)
                 if n == None:
                     continue
                 newNumber = n.number - 10000
                 nn = network.node(newNumber)
                 if nn != None:
                     raise Exception("Renumbering of node " + str(n.number) + " failed! New number " + str(newNumber) +" already exists!")
                 
                 n.number -= 10000
                 count += 1
             
             for i in range(0,1000):
                 n = network.node(91999 - i) 
                 # GO Rail nodes need to be shifted up by 7,000
                 # Cycling through them top to bottom to prevent id conflicts.
                 if n == None:
                     continue
                 
                 newNumber = n.number + 7000
                 nn = network.node(newNumber)
                 if nn != None:
                     raise Exception("Renumbering of node " + str(n.number) + " failed! New number " + str(newNumber) +" already exists!")
                 
                 n.number += 7000
                 count += 1
             
             for i in range(0,1000):
                 n = network.node(90999 - i) 
                 # Subway nodes need to be shifted up by 7,000
                 # Cycling through them top to bottom to prevent id conflicts.
                 if n == None:
                     continue
                 
                 newNumber = n.number + 7000
                 nn = network.node(newNumber)
                 if nn != None:
                     raise Exception("Renumbering of node " + str(n.number) + " failed! New number " + str(newNumber) +" already exists!")
                 
                 n.number += 7000
                 count += 1
                 
             Scenario.publish_network(network)
             s = "{0} nodes were changed in scenario {1}".format(count, Scenario.id)
             _m.logbook_write(s)
             report += "<br>%s" %s
             
         self.tool_run_msg = _m.PageBuilder.format_info(report)
예제 #21
0
    def _execute(self):
        with _m.logbook_trace("Load Boarding Penalties From File"):
            _m.logbook_write("Opening file:'%s'" % self.BoardingsFile)
            file = open(self.BoardingsFile, "r")
            line = file.readline()
            cells = line.split(";")
            if cells.count("boarding_penalty") < 1:
                raise Exception("Boardings file does not have a boarding_penalty header!")
            if cells.count("filter_expression") < 1:
                raise Exception("Boardings file does not have a filter_expression header!")
            headers = {"penalty": cells.index("boarding_penalty"), "expression": cells.index("filter_expression")}

            for line in file.readlines():
                try:
                    cells = line.split(";")
                    val = float(cells[headers["penalty"]])
                    expr = cells[headers["expression"]]

                    specification = {
                        "result": "ut3",
                        "expression": "%s" % val,
                        "aggregation": None,
                        "selections": {"transit_line": expr},
                        "type": "NETWORK_CALCULATION",
                    }
                    self.netCalcTool(specification)

                except ValueError:
                    continue
예제 #22
0
 def _Execute(self):
     with _m.logbook_trace(name="{classname} v{version}".format(classname=(self.__class__.__name__), version=self.version),
                                  attributes=self._GetAtts()):
         
         groupings = self.__options[self.CodeOption]
         
         tool = _MODELLER.tool('inro.emme.network_calculation.network_calculator')
     
         def flagGroup(value, selector, descr):
             spec= {
                     "result": self.AttributeId,
                     "expression": str(value),
                     "aggregation": None,
                     "selections": {
                         "transit_line": selector
                     },
                     "type": "NETWORK_CALCULATION"
                 }
             with _m.logbook_trace("Flagging %s lines as %s" %(descr, value)):
                 tool(spec, scenario=self.Scenario)
         
         self.TRACKER.startProcess(len(groupings))
         for value, selector, description in groupings:
             flagGroup(value, selector, description)
             self.TRACKER.completeSubtask()
             
         self._WriteTableReport(groupings)
 def __call__(self, MatrixId, Filename, ScenarioNumber):        
     with _m.logbook_trace("Exporting matrix %s to XTMF" %MatrixId): 
         scenario = _m.Modeller().emmebank.scenario(ScenarioNumber)
         if (scenario == None):
             raise Exception("Scenario %s was not found!" %ScenarioNumber)
         
         try:
             tool = None
             try:
                 tool = _m.Modeller().tool('inro.emme.standard.data.matrix.export_matrices')
             except Exception, e:
                 tool = _m.Modeller().tool('inro.emme.data.matrix.export_matrices')
             
             mtx = _m.Modeller().emmebank.matrix("mf%s" %MatrixId)
             if mtx == None:
                 raise Exception("No matrix found with id '%s'" %MatrixId)
             self._tracker.runTool(tool,
                                   export_file=Filename,
                                   field_separator='TAB',
                                   matrices=[mtx],
                                   full_matrix_line_format="ONE_ENTRY_PER_LINE",
                                   export_format="PROMPT_DATA_FORMAT",
                                   scenario=scenario,
                                   skip_default_values=False)
             
         except Exception, e:
             raise Exception(_traceback.format_exc(e))
 def _Execute(self):
     with _m.logbook_trace(name="{classname} v{version}".format(classname=(self.__class__.__name__), version=self.version),
                                  attributes=self._GetAtts()):
         
         with _util.tempMatrixMANAGER(matrix_type= 'SCALAR', description= "Zero demand matrix") \
                 as demandMatrix:
             with self._tempScenarioMANAGER():
                 dataTuples = []
                 
                 if self.AutoModeIds:
                     self._CheckAutoConnectivity(demandMatrix.id, dataTuples)
                 
                 if self.TransitModeIds:
                     self._CheckTransitConnectivity(demandMatrix.id, dataTuples)
                 
                 
                 
                 totalFountains = set()
                 totalSinks = set()
                 totalOrphans = set()
                 for type, modes, fountains, sinks, orphans in dataTuples:
                     for node in fountains: totalFountains.add(node)
                     for node in sinks: totalSinks.add(node)
                     for node in orphans: totalOrphans.add(node)
                 
                 nFountains = len(totalFountains)
                 nSinks = len(totalSinks)
                 nOrphans = len(totalOrphans)
                 
                 if (nFountains + nSinks + nOrphans) > 0:
                     self._WriteReport(dataTuples)
                     return nFountains, nSinks, nOrphans
                 else: return 0,0,0
예제 #25
0
 def run(self):
     self.tool_run_msg = ""
     try:
         with _m.logbook_trace(name="Move Networks",
                                  attributes=self._getAtts()):
             
             calculator = None
             try:
                 calculator = _m.Modeller().tool("inro.emme.network_calculation.network_calculator")
             except Exception, e:
                 calculator = _m.Modeller().tool("inro.emme.standard.network_calculation.network_calculator")
             
             spec = {
                     "result": "yi",
                     "expression": "yi + 4000000",
                     "aggregation": None,
                     "selections": {
                                    "node": "all"
                                    },
                     "type": "NETWORK_CALCULATION"
                     }
             
             for scenario in self.Scenarios:
                 _m.logbook_write("Changing scenario %s" %scenario.id)
                 calculator(spec, scenario=scenario)
             
             self.tool_run_msg = _m.PageBuilder.format_info("Tool complete.")
        
     except Exception, e:
         self.tool_run_msg = _m.PageBuilder.format_exception(
             e, _traceback.format_exc(e))
         raise
예제 #26
0
 def _Execute(self):
     
     with _m.logbook_trace(name="{classname} v{version}".format(classname=(self.__class__.__name__), version=self.version),
                                  attributes=self._GetAtts()):
                                
         #Creating a link extra attribute to hold TTS Cordon Counts
         if self.Scenario.extra_attribute('@cord') is not None:                       
                     _m.logbook_write("Deleting Previous Extra Attributes.")
                     self.Scenario.delete_extra_attribute('@cord')
                     print "Cleared previously created Cordon attribute"                    
         
         _m.logbook_write("Created extra attribute for cordon counts.")
         self.Scenario.create_extra_attribute('LINK', '@cord', default_value=0)
         print "Created extra attribute for cordon counts"
         
         net = self.Scenario.get_network()
                     
         with open(self.CordonTruthTable) as input:
             next(input, None)
             for row in input:
         #process individual row
                 column = row.split(',')
                 countpostlinkid = column[1].split("-")
                 value = column[2].strip()
         #apply the values
                 ourLink = net.link(countpostlinkid[0],countpostlinkid[1])
                 if ourLink != None:
                     print value
                     ourLink["@cord"] = int(value)
                 else:                    
                     print "%d - %d" %countpostlinki %value                        
         
         self.Scenario.publish_network(net)
예제 #27
0
    def _Execute(self):
        with _m.logbook_trace(name="{classname} v{version}".format(classname=(self.__class__.__name__), version=self.version),
                                     attributes=self._GetAtts()):

            linkLists = self._ParseLinkString(self.LinkSetString)
            results = []

            if self.DemandMatrix is None:
                demandMatrixId = _util.DetermineAnalyzedTransitDemandId(EMME_VERSION, self.BaseScenario)
            else:
                demandMatrixId = self.DemandMatrix.id            
            
            for linkPair in linkLists:
                fullLinkSet = linkPair
                link1List = [linkPair[1]] # maintain a list of links at and above link 1 for volume summing later (sums at/above link 1 and 2 will be identical)
                if self.HypernetworkFlag: # search for links 'above' the initial link pair in the hypernetwork
                    print "Looking for links in the hypernetwork"
                    network = self.BaseScenario.get_network()                    
                    initialLink1 = self._ParseIndividualLink(linkPair[1])
                    initialLink2 = self._ParseIndividualLink(linkPair[2])
                    inode1 = initialLink1[0]
                    inode2 = initialLink2[0]
                    jnode1 = initialLink1[1]
                    jnode2 = initialLink2[1]
                    for link in network.links():
                        if link.shape == network.link(inode1, jnode1).shape:
                            linkString = self._LinkToString(link)
                            if linkString not in fullLinkSet:
                                fullLinkSet.append(linkString)
                                link1List.append(linkString)
                        if link.shape == network.link(inode2, jnode2).shape:
                            linkString = self._LinkToString(link)
                            if linkString not in fullLinkSet:
                                fullLinkSet.append(linkString)

                with nested(_util.tempExtraAttributeMANAGER(self.BaseScenario, 'LINK', description= 'Line Flag'),
                            _util.tempExtraAttributeMANAGER(self.BaseScenario, 'TRANSIT_SEGMENT', description= 'Transit Volumes')) \
                            as (linkMarkerAtt, segVol):

                    
                    networkCalcTool(self._MarkLinks(fullLinkSet, linkMarkerAtt.id), scenario=self.BaseScenario)
                    print ('Finished marking links for %s' %fullLinkSet[0])
                    pathAnalysis(self._PathVolume(linkMarkerAtt.id, segVol.id, demandMatrixId), scenario=self.BaseScenario)  
                    print ('Finished running path analysis for %s' %fullLinkSet[0])
                                            
                    network = self.BaseScenario.get_network()
                    print 'Network loaded'
                    linkSum = 0
                    for link in link1List: #evaluate all links at/above link 1
                        singleLinkList = self._ParseIndividualLink(link)
                        for s in network.link(singleLinkList[0], singleLinkList[1]).segments(): #iterate through segments on the link
                            linkSum += s[segVol.id]
                    linkSum /= self.PeakHourFactor
                    results.append([fullLinkSet[0],linkSum]) #add label and sum
                    print ('Results calculated for %s' %fullLinkSet[0])


            self._WriteResultsToFile(results)

            self.TRACKER.completeTask()
예제 #28
0
 def _Execute(self):
     with _m.logbook_trace(name="{classname} v{version}".format(classname=(self.__class__.__name__), version=self.version),
                                  attributes=self._GetAtts()):
         
         self._ParseSegmentAggregators()
         self.TRACKER.completeTask()
         
         network = self.BaseScenario.get_network()
         self.TRACKER.completeTask()
         
         nodesToDelete = self._GetCandidateNodes(network)
         
         if len(nodesToDelete) == 0:
             raise Exception("Found zero nodes to delete.") 
         
         if self.ConnectorFilterAttributeId:
             self._RemoveCandidateCentroidConnectors(nodesToDelete)
         
         log = self._RemoveNodes(network, nodesToDelete)
         
         self._WriteReport(log)
         
         self.TRACKER.startProcess(2)
         if self.PublishFlag:
             bank = _MODELLER.emmebank
             newScenario = bank.copy_scenario(self.BaseScenario.id, self.NewScenarioId, copy_strat_files= False, copy_path_files= False)
             newScenario.title= self.NewScenarioTitle
             self.TRACKER.completeSubtask()
             newScenario.publish_network(network, True)
             self.TRACKER.completeSubtask()
             
             _MODELLER.desktop.refresh_needed(True)
         self.TRACKER.completeTask()
예제 #29
0
 def __call__(self):
     report = ""
     
     with _m.logbook_trace(name="Check connector speeds",
                                  attributes={
                                      "Scenario" : self.Scenario.id,
                                      "self" : self.__MODELLER_NAMESPACE__}):
         _m.logbook_write(
             name="Checking connector speeds for scenario %s" %self.Scenario.id,
             attributes={
                 "version":"1.00.00"})
         
         linksChecked = 0
         problemLinks = 0
         for link in self.Scenario.get_network().links():
             
             if link.i_node.is_centroid or link.j_node.is_centroid:
                 #link is a centroid connector
                 if link.data2 != 40:
                     report += "<br>Centroid connector link <b>" + link.id + "</b> speed should be 40, instead is " + str(link.data2)
                     problemLinks += 1
             
             linksChecked += 1
         _m.logbook_write(name="Report",
                          value=report)
             
     self.tool_run_msg = "Tool complete. " + str(linksChecked) + " links were checked, " + str(problemLinks) + " were flagged as problems. See logbook for details."
 def _Execute(self):
     
     networkCalculationTool = _MODELLER.tool("inro.emme.network_calculation.network_calculator") 
     
     if self.BaseScenario.extra_attribute('@cvolt') is not None:
         _m.logbook_write("Deleting Previous Extra Attributes.")
         self.BaseScenario.delete_extra_attribute('@cvolt')
     _m.logbook_write("Creating Attribute for ca_Voltr_l Value Transfer")
     self.BaseScenario.create_extra_attribute('TRANSIT_SEGMENT', '@cvolt', default_value=0)
     
     if self.BaseScenario.extra_attribute('@volut') is not None:
         _m.logbook_write("Deleting Previous Extra Attributes.")
         self.BaseScenario.delete_extra_attribute('@volut')
     _m.logbook_write("Creating Attribute for ca_Voltr_l Value Transfer")
     self.BaseScenario.create_extra_attribute('LINK', '@volut', default_value=0)
                 
     
     #Transfer ca_Voltr_l into a transit segment attribute.
     spec_transfer_1 = {
         "result": "@cvolt",
         "expression": "voltr",
         "aggregation": None,
         "selections": {
             "link": "all",
             "transit_line": "all"
         },
         "type": "NETWORK_CALCULATION"
     }
     
     with _m.logbook_trace("Transferring Voltr into an Extra Attribute"): #Do Once
         networkCalculationTool(spec_transfer_1, scenario=self.BaseScenario)
         
         
     #Transfer the transit segment attribute into a link attribute
     spec_transfer_2 = {
         "result": "@volut",
         "expression": "@cvolt",
         "aggregation": "+",
         "selections": {
             "link": "all",
             "transit_line": "all"
         },
         "type": "NETWORK_CALCULATION"
     }
     
     with _m.logbook_trace("Transferring  into an  Link Attribute"): #Do Once
         networkCalculationTool(spec_transfer_2, scenario=self.BaseScenario)
예제 #31
0
 def _execute(self):
     self._tracker.reset()
     with _m.logbook_trace(name="{classname} v{version}".format(classname=(self.__class__.__name__), version=self.version),
                                  attributes=self._getAtts()):
         
         try:
             transitAssignmentTool = _m.Modeller().tool("inro.emme.standard.transit_assignment.extended_transit_assignment")
             matrixResultsTool = _m.Modeller().tool('inro.emme.standard.transit_assignment.extended.matrix_results')
             matrixCalcTool = _m.Modeller().tool("inro.emme.standard.matrix_calculation.matrix_calculator")
         except Exception as e:
             transitAssignmentTool = _m.Modeller().tool("inro.emme.transit_assignment.extended_transit_assignment")
             matrixResultsTool = _m.Modeller().tool('inro.emme.transit_assignment.extended.matrix_results')
             matrixCalcTool = _m.Modeller().tool("inro.emme.matrix_calculation.matrix_calculator")
         
         with self._demandMatrixMANAGER(): # TASK 1
             
             with _m.logbook_trace("Initializing output matrices"):
                 ivttMatrix = _util.initializeMatrix(id=self.InVehicleTimeMatrixNumber,
                                                matrix_type='FULL',
                                                description="Station-station IVTT matrix")
                 
                 waitMatrix = _util.initializeMatrix(id=self.WaitTimeMatrixNumber,
                                                matrix_type='FULL',
                                                description="Station-station wait time matrix")
                 
                 self._tracker.completeTask() # TASK 2
             
             with _m.logbook_trace("Running transit assignment"):
                 self._tracker.runTool(transitAssignmentTool, self._getAssignmentSpec(),
                                   scenario=self.scenario,
                                   add_volumes=self.UseAdditiveDemand) #TASK 3
                 
                 # some error with progress reporting is occurring here.
             
             with _m.logbook_trace("Extracting output matrices"):
                 self._tracker.runTool(matrixResultsTool,
                                       self._getMatrixResultSpec(ivttMatrix, waitMatrix),
                                       scenario=self.scenario) # TASK 4
                 
             with _m.logbook_trace("Constraining output matrices"):
                 self._tracker.runTool(matrixCalcTool,
                                       self._getConstraintSpec(ivttMatrix, ivttMatrix),
                                       scenario=self.scenario) # TASK 5
                 
                 self._tracker.runTool(matrixCalcTool,
                                       self._getConstraintSpec(waitMatrix, waitMatrix),
                                       scenario=self.scenario) # TASK 6
예제 #32
0
 def _execute(self):
     self._tracker.reset()
     with _m.logbook_trace(name="{classname} v{version}".format(classname=(self.__class__.__name__), version=self.version),
                                  attributes=self._getAtts()):
         
         try:
             transitAssignmentTool = _m.Modeller().tool("inro.emme.standard.transit_assignment.extended_transit_assignment")
             matrixResultsTool = _m.Modeller().tool('inro.emme.standard.transit_assignment.extended.matrix_results')
             matrixCalcTool = _m.Modeller().tool("inro.emme.standard.matrix_calculation.matrix_calculator")
         except Exception, e:
             transitAssignmentTool = _m.Modeller().tool("inro.emme.transit_assignment.extended_transit_assignment")
             matrixResultsTool = _m.Modeller().tool('inro.emme.transit_assignment.extended.matrix_results')
             matrixCalcTool = _m.Modeller().tool("inro.emme.matrix_calculation.matrix_calculator")
         
         with self._demandMatrixMANAGER(): # TASK 1
             
             with _m.logbook_trace("Initializing output matrices"):
                 ivttMatrix = _util.initializeMatrix(id=self.InVehicleTimeMatrixNumber,
                                                matrix_type='FULL',
                                                description="Station-station IVTT matrix")
                 
                 waitMatrix = _util.initializeMatrix(id=self.WaitTimeMatrixNumber,
                                                matrix_type='FULL',
                                                description="Station-station wait time matrix")
                 
                 self._tracker.completeTask() # TASK 2
             
             with _m.logbook_trace("Running transit assignment"):
                 self._tracker.runTool(transitAssignmentTool, self._getAssignmentSpec(),
                                   scenario=self.scenario,
                                   add_volumes=self.UseAdditiveDemand) #TASK 3
                 
                 # some error with progress reporting is occurring here.
             
             with _m.logbook_trace("Extracting output matrices"):
                 self._tracker.runTool(matrixResultsTool,
                                       self._getMatrixResultSpec(ivttMatrix, waitMatrix),
                                       scenario=self.scenario) # TASK 4
                 
             with _m.logbook_trace("Constraining output matrices"):
                 self._tracker.runTool(matrixCalcTool,
                                       self._getConstraintSpec(ivttMatrix, ivttMatrix),
                                       scenario=self.scenario) # TASK 5
                 
                 self._tracker.runTool(matrixCalcTool,
                                       self._getConstraintSpec(waitMatrix, waitMatrix),
                                       scenario=self.scenario) # TASK 6
예제 #33
0
 def _Execute(self):
     with _m.logbook_trace(name="{classname} v{version}".format(classname=(self.__class__.__name__), version=self.version),
                                  attributes=self._GetAtts()):
         
         network = self.Scenario.get_network()
         self.TRACKER.completeTask()
         
         anchorVecotr = ((self.CorrespondingX0, self.CorrespondingY0),
                          (self.CorrespondingX1, self.CorrespondingY1))
         
         refLink = self._GetRefLink(network)
         referenceVector = self._GetLinkVector(refLink)
         _m.logbook_write("Found reference link '%s-%s'" %(self.ReferenceLinkINode, self.ReferenceLinkJNode))
         
         angle = self._GetRotationAngle(anchorVecotr, referenceVector)# + math.pi / 2
         _m.logbook_write("Rotation: %s degrees" %math.degrees(angle))
         cosTheta = math.cos(angle)
         sinTheta = math.sin(angle)
         
         self.TRACKER.startProcess(network.element_totals['centroids'] + network.element_totals['regular_nodes'])
         for node in network.nodes():
             self._RotateNode(node, cosTheta, sinTheta)
             self.TRACKER.completeSubtask()
         self.TRACKER.completeTask()
         _m.logbook_write("Finished rotating nodes.")
         
         self.TRACKER.startProcess(network.element_totals['links'])
         count = 0
         for link in network.links():
             if len(link.vertices) > 0:
                 self._RotateLinkVertices(link, cosTheta, sinTheta)
                 count += 1
             self.TRACKER.completeSubtask()
         self.TRACKER.completeTask()
         _m.logbook_write("Rotated %s links with vertices." %count)
         
         referenceVector = self._GetLinkVector(refLink) # Reset the reference vector
         delta = self._GetTranslation(referenceVector, anchorVecotr)
         _m.logbook_write("Translation: %s" %str(delta))
         
         self.TRACKER.startProcess(network.element_totals['centroids'] + network.element_totals['regular_nodes'])
         for node in network.nodes():
             self._TranslateNode(node, delta)
             self.TRACKER.completeSubtask()
         self.TRACKER.completeTask()
         _m.logbook_write("Finished translating nodes.")
         
         self.TRACKER.startProcess(network.element_totals['links'])
         count = 0
         for link in network.links():
             if len(link.vertices) > 0:
                 self._TranslateLink(link, delta)
                 count += 1
             self.TRACKER.completeSubtask()
         self.TRACKER.completeTask()
         _m.logbook_write("Translated %s links with vertices." %count)
         
         self.Scenario.publish_network(network, resolve_attributes=True)
         self.TRACKER.completeTask()
 def _Execute(self, scenario, filename):
     with _m.logbook_trace(name="{classname} v{version}".format(classname=(self.__class__.__name__), version=self.version),
                                  attributes={"Scenario": str(scenario),
                                              "Version": self.version,
                                              "self": self.__MODELLER_NAMESPACE__}):
         
         tool = _MODELLER.tool('inro.emme.data.network.base.export_base_network')
         self.TRACKER.runTool(tool, export_file= filename, scenario= scenario)
예제 #35
0
 def _execute(self):
     with _m.logbook_trace(name="{classname} v{version}".format(classname=(self.__class__.__name__), version=self.version),
                                  attributes=self._getAtts()):
         
         _m.logbook_write("Executing Python script from file '%s'" %self.filename)
         
         with self._printRedirectMANAGER():
             execfile(self.filename, locals())
예제 #36
0
    def __call__(self):
        report = "<h3>Check Link Lanes</h3>\
                    <table><tr>\
                    <th>I Node</th><th>J Node</th><th>Link Class</th><th>Req'd Lanes</th><th>Actual Lanes</th>\
                    </tr>"

        with _m.logbook_trace(name="Check Link lanes",
                              attributes={
                                  "Scenario": self.Scenario.id,
                                  "self": self.__MODELLER_NAMESPACE__
                              }):
            _m.logbook_write(name="Checking link lanes for scenario %s" %
                             self.Scenario.id,
                             attributes={"version": "1.0.1"})

            problemLinks = 0
            for link in self.Scenario.get_network().links():

                if link.i_node.is_centroid or link.j_node.is_centroid:
                    #link is a centroid connector
                    if link.num_lanes != 2.0:
                        report += "<tr><td>{inode}</td><td>{jnode}</td><td>Centroid connector\
                            </td><td>2.0</td><td>{lanes}</td></tr>".format(
                            inode=link.i_node.id,
                            jnode=link.j_node.id,
                            lanes=str(link.num_lanes))
                        #report += "<br>Centroid connector link <b>" + link.id + "</b> should have 2.0 lanes, instead has " + str(link.num_lanes)
                        problemLinks += 1
                elif self.linkIsTransitOnly(link):
                    #link is exclusive ROW
                    if link.num_lanes != 0.0:
                        report += "<tr><td>{inode}</td><td>{jnode}</td><td>Exclusive transit link\
                            </td><td>0.0</td><td>{lanes}</td></tr>".format(
                            inode=link.i_node.id,
                            jnode=link.j_node.id,
                            lanes=str(link.num_lanes))

                        #report += "<br>Exclusive transit link <b>" + link.id + "</b> should have 0.0 lanes, instead has " + str(link.num_lanes)
                        problemLinks += 1
                elif self.linkHasMode(link, "t") or self.linkHasMode(
                        link, "u"):
                    #transfer link
                    if link.num_lanes != 0.0:
                        report += "<tr><td>{inode}</td><td>{jnode}</td><td>Transfer link\
                            </td><td>0.0</td><td>{lanes}</td></tr>".format(
                            inode=link.i_node.id,
                            jnode=link.j_node.id,
                            lanes=str(link.num_lanes))
                        report += "<br>Transfer link <b>" + link.id + "</b> should have 0.0 lanes, instead has " + str(
                            link.num_lanes)
                        problemLinks += 1

            report += "</table>"
            _m.logbook_write(name="Report", value=report)

        self.tool_run_msg = _m.PageBuilder.format_info(
            "%s links were flagged as problems. See logbook for details." %
            problemLinks)
    def _Execute(self):
        with _m.logbook_trace(name="{classname} v{version}".format(
                classname=(self.__class__.__name__), version=self.version),
                              attributes=self._GetAtts()):

            tool = _MODELLER.tool(
                'inro.emme.network_calculation.network_calculator')

            self.TRACKER.reset(len(self.Scenarios))

            filterList = self._ParseFilterString(self.PenaltyFilterString)

            for scenario in self.Scenarios:
                with _m.logbook_trace("Processing scenario %s" % scenario):
                    self._ProcessScenario(scenario, filterList)
                self.TRACKER.completeTask()

            _MODELLER.desktop.refresh_needed(True)
예제 #38
0
 def _DetermineAttributesToCopy(self, sourceNetwork, targetNetwork):
     sourceAttributes = set(sourceNetwork.attributes('LINK'))
     targetAttributes = set(targetNetwork.attributes('LINK'))
     
     attsNotInTarget = sourceAttributes - targetAttributes
     attsNotInSource = targetAttributes - sourceAttributes
     
     if len(attsNotInSource) > 0:
         with _m.logbook_trace("Attributes in target but not in source scenario"):
             for att in attsNotInSource: _m.logbook_write(att)
             _m.logbook_write("The attributes will not be copied")
     
     if len(attsNotInTarget) > 0:
         with _m.logbook_trace("Attributes in source but not in target scenario"):
             for att in attsNotInTarget: _m.logbook_write(att)
             _m.logbook_write("The attributes will not be copied")
     
     return sourceAttributes & targetAttributes
예제 #39
0
 def _Execute(self):
     with _m.logbook_trace(name="{classname} v{version}".format(classname=(self.__class__.__name__), version=self.version),
                                  attributes=self._GetAtts()):
         
         screenlines = self._LoadScreenlinesFile()
         
         counts = self._LoadResults()
         
         self._ExportResults(screenlines, counts)
예제 #40
0
 def _DetermineAttributesToCopy(self, sourceNetwork, targetNetwork):
     sourceAttributes = set(sourceNetwork.attributes('LINK'))
     targetAttributes = set(targetNetwork.attributes('LINK'))
     
     attsNotInTarget = sourceAttributes - targetAttributes
     attsNotInSource = targetAttributes - sourceAttributes
     
     if len(attsNotInSource) > 0:
         with _m.logbook_trace("Attributes in target but not in source scenario"):
             for att in attsNotInSource: _m.logbook_write(att)
             _m.logbook_write("The attributes will not be copied")
     
     if len(attsNotInTarget) > 0:
         with _m.logbook_trace("Attributes in source but not in target scenario"):
             for att in attsNotInTarget: _m.logbook_write(att)
             _m.logbook_write("The attributes will not be copied")
     
     return sourceAttributes & targetAttributes
예제 #41
0
    def _execute(self):
        with _m.logbook_trace(name="{classname} v{version}".format(
                classname=self.__class__.__name__, version=self.version),
                              attributes=self._get_logbook_attributes()):

            if _bank.scenario(
                    self.scenario_Id
            ) is not None and not self.overwrite_scenario_flag:
                raise IOError(
                    "Scenario %s exists and overwrite flag is set to false." %
                    self.scenario_Id)

            self._components.reset(
            )  # Clear any held-over contents from previous run

            with _zipfile.ZipFile(self.network_package_file
                                  ) as zf, self._temp_file() as temp_folder:

                self._check_network_package(zf)  # Check the file format.

                if _bank.scenario(self.scenario_Id) is not None:
                    if not self.overwrite_scenario_flag:
                        raise IOError("Scenario %s already exists." %
                                      self.scenario_Id)
                    sc = _bank.scenario(self.scenario_Id)
                    if sc.modify_protected or sc.delete_protected:
                        raise IOError(
                            "Scenario %s is protected against modifications" %
                            self.scenario_Id)
                    _bank.delete_scenario(self.scenario_Id)
                scenario = _bank.create_scenario(self.scenario_Id)
                scenario.title = self.scenario_description

                _m.logbook_write("Created new scenario %s" % self.scenario_Id)
                self.TRACKER.completeTask()

                self._batchin_modes(scenario, temp_folder, zf)
                self._batchin_vehicles(scenario, temp_folder, zf)
                self._batchin_base(scenario, temp_folder, zf)
                self._batchin_link_shapes(scenario, temp_folder, zf)
                self._batchin_lines(scenario, temp_folder, zf)
                self._batchin_turns(scenario, temp_folder, zf)

                if self._components.traffic_results_files is not None:
                    self._batchin_traffic_results(scenario, temp_folder, zf)

                if self._components.transit_results_files is not None:
                    self._batchin_transit_results(scenario, temp_folder, zf)

                if self._components.attribute_header_file is not None:
                    self._batchin_extra_attributes(scenario, temp_folder, zf)
                self.TRACKER.completeTask()

                if self._components.functions_file is not None:
                    self._batchin_functions(temp_folder, zf)
                self.TRACKER.completeTask()
예제 #42
0
    def _Execute(self):

        with _m.logbook_trace(
                name="{classname}".format(classname=(self.__class__.__name__)),
                attributes=self._GetAtts()):

            logbookLocation = os.path.abspath(
                os.path.join(os.path.dirname(emmebankLocation), os.pardir,
                             'Logbook'))
            initialDir = os.listdir(logbookLocation)
            #we need to do this in since the active scenario is executed in the call method.
            _MODELLER.desktop.data_explorer().replace_primary_scenario(
                self.Scenario)
            LogTable(worksheet_items_or_folders=self.WorksheetPaths,
                     field_separator=",")
            finalDir = os.listdir(logbookLocation)
            newItems = []
            count = 0
            if self.FileName:
                fileNameSplit = self.FileName.split(".")
                fileNameHead = fileNameSplit[0]
                fileNameExt = fileNameSplit[1]
                for item in finalDir:
                    if item not in initialDir:
                        oldOutputFiles = os.listdir(
                            os.path.join(logbookLocation, item))

                        for file in oldOutputFiles:
                            if count == 0:
                                fileNameInsert = ""
                            else:
                                fileNameInsert = str(count)
                            os.renames(
                                os.path.join(logbookLocation, item, file),
                                os.path.join(
                                    logbookLocation, item, fileNameHead +
                                    fileNameInsert + "." + fileNameExt))
                            count += 1
                        newItems.append(item)

            else:
                for item in finalDir:
                    if item not in initialDir:
                        newItems.append(item)
            for item in newItems:
                try:
                    copy_tree(
                        os.path.abspath(os.path.join(logbookLocation, item)),
                        self.FilePath)  # copy folder to chosen path
                    # note: copy_tree will overwrite any file with the same name
                    shutil.rmtree(
                        os.path.abspath(os.path.join(logbookLocation,
                                                     item)))  # clean up
                except Exception as e:
                    msg = str(e) + "\n" + _traceback.format_exc()
                    raise Exception(msg)
예제 #43
0
    def _execute(self):
        with _m.logbook_trace(name="{classname} v{version}".format(
                classname=(self.__class__.__name__), version=self.version),
                              attributes=self._getAtts()):

            _m.logbook_write("Executing Python script from file '%s'" %
                             self.filename)

            with self._printRedirectMANAGER():
                execfile(self.filename, locals())
예제 #44
0
    def _Execute(self):
        with _m.logbook_trace(name="{classname} v{version}".format(
                classname=(self.__class__.__name__), version=self.version),
                              attributes=self._GetAtts()):

            tool = _MODELLER.tool(
                'inro.emme.network_calculation.network_calculator')

            with _m.logbook_trace("Calulating light zone tolls"):
                self.TRACKER.runTool(tool,
                                     scenario=self.Scenario,
                                     specification=self._GetZoneSpec(
                                         1, self.LightZoneToll))

            with _m.logbook_trace("Calculating regular zone tolls"):
                self.TRACKER.runTool(tool,
                                     scenario=self.Scenario,
                                     specification=self._GetZoneSpec(
                                         2, self.RegularZoneToll))
예제 #45
0
 def _walkLinksMANAGER(self):
     #Code here is executed upon entry
     
     with _m.logbook_trace("Changing speed of modes tuv."):
         net = self.scenario.get_network()
         tMode = net.mode('t')
         uMode = net.mode('u')
         vMode = net.mode('v')
         
         tSpeed = tMode.speed
         uSpeed = uMode.speed
         vSpeed = vMode.speed
         
         tMode.speed = 'ul1*1.0'
         _m.logbook_write("Changed speed of mode 't' to 'ul1*1.0'.")
         uMode.speed = 'ul1*1.0'
         _m.logbook_write("Changed speed of mode 'u' to 'ul1*1.0'.")
         vMode.speed = 'ul1*1.0'
         _m.logbook_write("Changed speed of mode 'u' to 'ul1*1.0'.")
         
         self.scenario.publish_network(net)
         _m.logbook_write("Changes saved to databank.")
     
     try:
         yield
         # Code here is executed upon clean exit
     finally:
         # Code here is executed in all cases.
         with _m.logbook_trace("Resetting modes tuv."):
             net = self.scenario.get_network()
             tMode = net.mode('t')
             uMode = net.mode('u')
             vMode = net.mode('v')
             
             tMode.speed = str(tSpeed)
             _m.logbook_write("Reset speed of mode 't' to '%s'." %tSpeed)
             uMode.speed = str(uSpeed)
             _m.logbook_write("Reset speed of mode 'u' to '%s'." %uSpeed)
             vMode.speed = str(vSpeed)
             _m.logbook_write("Reset speed of mode 'v' to '%s'." %vSpeed)
             
             self.scenario.publish_network(net)
             _m.logbook_write("Changes saved to databank.")
예제 #46
0
    def _Execute(self):
        with _m.logbook_trace(name="{classname} v{version}".format(
                classname=(self.__class__.__name__), version=self.version),
                              attributes=self._GetAtts()):

            screenlines = self._LoadScreenlinesFile()

            counts = self._LoadResults()

            self._ExportResults(screenlines, counts)
예제 #47
0
 def _Execute(self):
     with _m.logbook_trace(name="%s v%s" %(self.__class__.__name__, self.version), \
                           attributes= self._GetAtts()):
         matrix = _util.initializeMatrix(self.MatrixId)
         if self.MatrixDescription:
             matrix.description = self.MatrixDescription
         
         data = _MatrixData.load(self.ImportFile)
         
         origins, destinations = data.indices
         origins = set(origins)
         destinations = set(destinations)
         if origins ^ destinations:
             raise Exception("Asymmetrical matrix detected. Matrix must be square.")
         
         if _util.databankHasDifferentZones(_bank):
             
             zones = set(self.Scenario.zone_numbers)
             if zones ^ origins:
                 
                 with _m.logbook_trace("Zones in matrix file but not in scenario"):
                     for index in origins - zones: _m.logbook_write(index)
                 with _m.logbook_trace("Zones in scenario but not in file"):
                     for index in zones - origins: _m.logbook_write(index)
                 
                 raise Exception("Matrix zones not compatible with scenario %s. Check logbook for details." %self.Scenario)
             
             matrix.set_data(data, scenario_id= self.Scenario.id)
         else:
             sc = _bank.scenarios()[0]
             zones = set(sc.zone_numbers)
             if zones ^ origins:
                 
                 with _m.logbook_trace("Zones in matrix file but not in scenario"):
                     for index in origins - zones: _m.logbook_write(index)
                 with _m.logbook_trace("Zones in scenario but not in file"):
                     for index in zones - origins: _m.logbook_write(index)
                 
                 raise Exception("Matrix zones not compatible with emmebank zone system. Check Logbook for details.")
             
             matrix.set_data(data)
         
         self.TRACKER.completeTask()
예제 #48
0
 def _walkLinksMANAGER(self):
     #Code here is executed upon entry
     
     with _m.logbook_trace("Changing speed of modes tuv."):
         net = self.scenario.get_network()
         tMode = net.mode('t')
         uMode = net.mode('u')
         vMode = net.mode('v')
         
         tSpeed = tMode.speed
         uSpeed = uMode.speed
         vSpeed = vMode.speed
         
         tMode.speed = 'ul1*1.0'
         _m.logbook_write("Changed speed of mode 't' to 'ul1*1.0'.")
         uMode.speed = 'ul1*1.0'
         _m.logbook_write("Changed speed of mode 'u' to 'ul1*1.0'.")
         vMode.speed = 'ul1*1.0'
         _m.logbook_write("Changed speed of mode 'u' to 'ul1*1.0'.")
         
         self.scenario.publish_network(net)
         _m.logbook_write("Changes saved to databank.")
     
     try:
         yield
         # Code here is executed upon clean exit
     finally:
         # Code here is executed in all cases.
         with _m.logbook_trace("Resetting modes tuv."):
             net = self.scenario.get_network()
             tMode = net.mode('t')
             uMode = net.mode('u')
             vMode = net.mode('v')
             
             tMode.speed = str(tSpeed)
             _m.logbook_write("Reset speed of mode 't' to '%s'." %tSpeed)
             uMode.speed = str(uSpeed)
             _m.logbook_write("Reset speed of mode 'u' to '%s'." %uSpeed)
             vMode.speed = str(vSpeed)
             _m.logbook_write("Reset speed of mode 'v' to '%s'." %vSpeed)
             
             self.scenario.publish_network(net)
             _m.logbook_write("Changes saved to databank.")
    def _Execute(self):
        with _m.logbook_trace(name="{classname} v{version}".format(
                classname=(self.__class__.__name__), version=self.version),
                              attributes=self._GetAtts()):

            adjacencyMatrix = _util.initializeMatrix(
                id=self.ResultMatrixId,
                name="zadj",
                description="Zone adjacency matrix")

            network = self.Scenario.get_network()
            _m.logbook_write("Loaded network data")
            with _m.logbook_trace("Loading zone boundaries"):
                self._LoadShapefileGeometry(network)
                self.TRACKER.completeTask()

            with _m.logbook_trace("Processing zone adjacencies"):
                self._ProcessAdjacencies(network, adjacencyMatrix)
                self.TRACKER.completeTask()
예제 #50
0
    def _Execute(self):
        with _m.logbook_trace(name="{classname} v{version}".format(
                classname=(self.__class__.__name__), version=self.version),
                              attributes=self._GetAtts()):

            if self.FileName[-3:].lower == "txt":
                gtfsEmmeMap(self.FileName, self.MappingFileName)
            if self.FileName[-3:].lower == "shp":
                shpEmmeMap(self.FileName, self.MappingFileName)
            '''#load stops
예제 #51
0
 def _Execute(self):
     with _m.logbook_trace(name="%s v%s" %(self.__class__.__name__, self.version), \
                           attributes= self._GetAtts()):
         matrix = _util.initializeMatrix(self.MatrixId)
         if self.MatrixDescription:
             matrix.description = self.MatrixDescription
         
         data = _MatrixData.load(self.ImportFile)
         
         origins, destinations = data.indices
         origins = set(origins)
         destinations = set(destinations)
         if origins ^ destinations:
             raise Exception("Asymmetrical matrix detected. Matrix must be square.")
         
         if _util.databankHasDifferentZones(_bank):
             
             zones = set(self.Scenario.zone_numbers)
             if zones ^ origins:
                 
                 with _m.logbook_trace("Zones in matrix file but not in scenario"):
                     for index in origins - zones: _m.logbook_write(index)
                 with _m.logbook_trace("Zones in scenario but not in file"):
                     for index in zones - origins: _m.logbook_write(index)
                 
                 raise Exception("Matrix zones not compatible with scenario %s. Check logbook for details." %self.Scenario)
             
             matrix.set_data(data, scenario_id= self.Scenario.id)
         else:
             sc = _bank.scenarios()[0]
             zones = set(sc.zone_numbers)
             if zones ^ origins:
                 
                 with _m.logbook_trace("Zones in matrix file but not in scenario"):
                     for index in origins - zones: _m.logbook_write(index)
                 with _m.logbook_trace("Zones in scenario but not in file"):
                     for index in zones - origins: _m.logbook_write(index)
                 
                 raise Exception("Matrix zones not compatible with emmebank zone system. Check Logbook for details.")
             
             matrix.set_data(data)
         
         self.TRACKER.completeTask()
예제 #52
0
    def _Execute(self):
        with _m.logbook_trace(name="{classname} v{version}".format(classname=(self.__class__.__name__), version=self.version),
                                     attributes=self._GetAtts()):
                        
            network = self.BaseScenario.get_network()
            
            if not self.CustomScenarioSetFlag:
                firstScenario = [self.Scen1UnNumber, self.Scen1Number, self.Scen1UnDescription, self.Scen1Description,
                                 self.Scen1Start, self.Scen1End, self.Scen1NetworkUpdateFile]
                secondScenario = [self.Scen2UnNumber, self.Scen2Number, self.Scen2UnDescription, self.Scen2Description,
                                 self.Scen2Start, self.Scen2End, self.Scen2NetworkUpdateFile]
                thirdScenario = [self.Scen3UnNumber, self.Scen3Number, self.Scen3UnDescription, self.Scen3Description,
                                 self.Scen3Start, self.Scen3End, self.Scen3NetworkUpdateFile]
                fourthScenario = [self.Scen4UnNumber, self.Scen4Number, self.Scen4UnDescription, self.Scen4Description,
                                 self.Scen4Start, self.Scen4End, self.Scen4NetworkUpdateFile]
                fifthScenario = [self.Scen5UnNumber, self.Scen5Number, self.Scen5UnDescription, self.Scen5Description,
                                 self.Scen5Start, self.Scen5End, self.Scen5NetworkUpdateFile]
                scenarioSet = [firstScenario, secondScenario, thirdScenario, fourthScenario, fifthScenario]

            else:
                scenarioSet = self._ParseCustomScenarioSet()
            
            if self.OverwriteScenarioFlag:
                self._DeleteOldScenarios(scenarioSet)
            
            # Create time period networks in all the unclean scenario spots
            # Calls create_transit_time_period
            for scenarios in scenarioSet:
                createTimePeriod(self.BaseScenario, scenarios[0], scenarios[2], self.TransitServiceTableFile,
                                 self.AggTypeSelectionFile, self.AlternativeDataFile,
                                 self.DefaultAgg, scenarios[4], scenarios[5], self.AdditionalAlternativeDataFiles)
                if not (scenarios[6] == None or scenarios[6].lower() == "none"):
                    applyNetUpdate(str(scenarios[0]),scenarios[6])                

            print "Created uncleaned time period networks and applied network updates"

            if self.BatchEditFile:
                for scenarios in scenarioSet:
                    lineEdit(scenarios[0], self.BatchEditFile) #note that batch edit file should use uncleaned scenario numbers
                print "Edited transit line data"

            # Prorate the transit speeds in all uncleaned networks
            for scenarios in scenarioSet:
                prorateTransitSpeed(scenarios[0], self.LineFilterExpression)

            print "Prorated transit speeds"

            for scenarios in scenarioSet:
                removeExtraLinks(scenarios[0], self.TransferModesString, True, scenarios[1], scenarios[3])
                
                removeExtraNodes(scenarios[1], self.NodeFilterAttributeId, self.StopFilterAttributeId, self.ConnectorFilterAttributeId, self.AttributeAggregatorString)
            print "Cleaned networks"
                
            self.BaseScenario.publish_network(network)
            self.TRACKER.completeTask()
예제 #53
0
    def _execute(self, scenario, worksheet, export_path, config):
        with _m.logbook_trace(name="{classname} v{version}".format(
                classname=(self.__class__.__name__), version=self.version),
                              attributes=self._get_atts()):
            desktop = _MODELLER.desktop

            #---1. Set the primary scenario
            data_explorer = desktop.data_explorer()
            db = data_explorer.active_database()
            sc = db.scenario_by_number(scenario.number)
            data_explorer.replace_primary_scenario(sc)

            #---2. Load the view
            view_config = config['view']
            view_box = self._set_view(worksheet, view_config)

            #---3. Set any parameters This is performed AFTER setting the view, in case any parameters sync with the view
            for param_config in config['parameters']:
                par_name = param_config['par_name']

                layer_name = ''
                layer_type = ''
                if 'layer_name' in param_config:
                    layer_name = param_config['layer_name']
                if 'layer_type' in param_config:
                    layer_type = param_config['layer_type']

                val = param_config['value']
                index = int(param_config['index'])

                self._set_parameter(worksheet, layer_type, layer_name,
                                    par_name, val, index)

            #---4. Finally, export the worksheet
            export_config = config['export_type']
            export_type = export_config['type']

            image_types = {
                'JPEGType': '.jpg',
                'PNGType': '.png',
                'BMPType': '.bmp'
            }
            if export_type in image_types:
                export_path = _path.splitext(
                    export_path)[0] + image_types[export_type]
                self._export_image(worksheet, export_config, export_path)
            elif export_type == 'PDFExportType':
                export_path = _path.splitext(export_path)[0] + '.pdf'
                self._export_pdf(worksheet, export_config, export_path)
            elif export_type == 'SVGExportType':
                export_path = _path.splitext(export_path)[0] + '.svg'
                self._export_svg(worksheet, export_config, export_path)
            else:
                raise NameError("Worksheet export type '%s' not recognized" %
                                export_type)
예제 #54
0
    def _execute(self):

        with _m.logbook_trace(name="Flag premium buses v%s" % self.version,
                              attributes={
                                  "Scenario":
                                  str(self.scenario.id),
                                  "Flag GO Buses":
                                  self.FlagGO,
                                  "Flag TTC Premium Buses":
                                  self.FlagPremTTC,
                                  "Flag VIVA Buses":
                                  self.FlagVIVA,
                                  "Flag ZUM":
                                  self.FlagZum,
                                  "Is running from XTMF?":
                                  str(self.isRunningFromXTMF),
                                  "self":
                                  self.__MODELLER_NAMESPACE__
                              }):
            #---0. Set up all Emme tools and data structures
            try:
                self.netWorkCalculationTool = _m.Modeller().tool(
                    "inro.emme.standard.network_calculation.network_calculator"
                )
                _m.logbook_write(name="Emme 3.4.2 Tool Names used")
            except Exception as e:
                self.netWorkCalculationTool = _m.Modeller().tool(
                    "inro.emme.network_calculation.network_calculator")
                _m.logbook_write(name="Emme 4.0.3 Tool Names used")

            #---Initialize the flag attribute
            self._initFlagAttribute()
            self.counter = 0

            #---Get network
            network = self.scenario.get_network()

            #---Set up the list of functions
            functions = []
            if self.FlagGO:
                functions.append(self._flagGoBuses)
            if self.FlagPremTTC:
                functions.append(self._flagTTCPremiumBuses)
            if self.FlagVIVA:
                functions.append(self._flagVIVABuses)
            if self.FlagZum:
                functions.append(self._flagZumBuses)

            #---Execute
            for line in network.transit_lines():
                for f in functions:
                    f(line)

            #---Publish
            self.scenario.publish_network(network)
예제 #55
0
 def __call__(self):
     report = ""
     
     with _m.logbook_trace(name="Check Link Lengths",
                                  attributes={
                                      "Scenario" : self.Scenario.id,
                                      "Tolerance" : self.Error,
                                      "self" : self.__MODELLER_NAMESPACE__}):
         _m.logbook_write(
             name="Checking link lengths for scenario %s" %self.Scenario.id,
             attributes={
                 "version":"1.00.00"})
         
         linksChecked = 0
         problemLinks = 0
         for link in self.Scenario.get_network().links():
             i = link.i_node
             j = link.j_node    
             
             type = "link"
             
             distance = 0
             if self.linkHasMode(link, "t"):
                 distance = 0.10
                 type = "t-link"
             elif self.linkHasMode(link, "u"):
                 distance = 0.10
                 type = "u-link"
             elif (i.number > 900000 and j.number < 900000) or (j.number > 900000 and i < 900000):
                 # HOV ramp
                 distance = 0.0
                 type = "HOV ramp link"
             else:
                 d = math.sqrt((i.x - j.x)**2 + (i.y - j.y)**2) 
                 distance = (int(d /10) / 100.0) # Gives distance in km, truncated to 2 decimal places
             
             length = (int(link.length * 100) / 100.0) #Eliminates rounding error in the link length; length is in km, truncated to 2 decimal places
             
             diff = math.fabs(distance - length)
             
             if diff > self.Error:
                 problemLinks += 1
                 
                 # TODO: Have a better report, maybe in a table, which better organizes the results. 
                 report += "<p><b>Distance error:</b><ul><li><em>link id</em>: " + link.id +"</li><li><em>type</em>: " \
                     + type + "</li><li><em>distance</em>: " + str(distance) + "</li><li><em>length</em>: " + str(length) + "</li></ul></p>"
             
             linksChecked += 1
         _m.logbook_write(name="Report",
                          value=report)
         
         #test = """<select><option value="option1">1</option><option value="option2">2</option><option value="option3">3</option></select>"""
         #_m.logbook_write(name="Test Report", value=test)
             
     self.tool_run_msg = "Tool complete. " + str(linksChecked) + " links were checked, " + str(problemLinks) + " were flagged as problems. See logbook for details."
예제 #56
0
 def _initOutputMatrices(self):
     with _m.logbook_trace("Initializing output matrices:"):
         _util.initializeMatrix(self.CostMatrixId,
                                name='acost',
                                description='AUTO COST: %s' % self.RunTitle)
         _util.initializeMatrix(self.TimesMatrixId,
                                name='aivtt',
                                description='AUTO TIME: %s' % self.RunTitle)
         _util.initializeMatrix(self.TollsMatrixId,
                                name='atoll',
                                description='AUTO TOLL: %s' % self.RunTitle)
예제 #57
0
    def __call__(self):

        current_scen = self.current_scenario

        #export extra attributes
        with _modeller.logbook_trace(name = "Path Based Assignment on Multiple Scenarios", value = ""):
            NAMESPACE = 'inro.emme.traffic_assignment.path_based_traffic_assignment'
            path_assign = _modeller.Modeller().tool(NAMESPACE)
            specs = _json.loads(self.path_specs_box)
            for scen in self.scenarios_list:
                _modeller.Modeller().desktop.data_explorer().replace_primary_scenario(scen)
                path_assign(specs)
예제 #58
0
    def __call__(self):

        current_scen = self.current_scenario
        specs = _json.loads(self.sola_specs_box)
        with _modeller.logbook_trace(
                name="SOLA Assignment on Multiple Scenarios", value=""):
            NAMESPACE = 'inro.emme.traffic_assignment.sola_traffic_assignment'
            sola_assign = _modeller.Modeller().tool(NAMESPACE)
            for scen in self.scenarios_list:
                _modeller.Modeller().desktop.data_explorer(
                ).replace_primary_scenario(scen)
                sola_assign(specs)
예제 #59
0
 def flagGroup(value, selector, descr):
     spec = {
         "result": attributeId,
         "expression": str(value),
         "aggregation": None,
         "selections": {
             "transit_line": selector
         },
         "type": "NETWORK_CALCULATION"
     }
     with _m.logbook_trace("Flagging %s lines as %s" % (descr, value)):
         networkCalculator(spec, scenario=self.Scenario)