Esempio n. 1
0
File: Demand.py Progetto: rcads/dta
    def readDynameqTable(cls, net, fileName):
        """
        Read the dynameq demand stored in the *fileName* that pertains to *net*, a :py:class:`Network` instance.
        This method reads only rectangular demand tables. 
        """
        DYNAMEQ_FORMAT_FULL = "FORMAT:full"

        input = open(fileName, "rb")

        input.next()  # <DYNAMEQ>
        input.next()  # <VERSION>
        input.next()  # <MATRIX_FILE>
        input.next()  # * comment
        line = input.next().strip()
        if line != DYNAMEQ_FORMAT_FULL:
            raise DtaError("I cannot read a demand format other than %s" %
                           Demand.FORMAT_FULL)
        input.next()  # VEH_CLASS
        line = input.next().strip()

        vehClassName = line
        input.next()  #DATA
        line = input.next().strip()

        startTime = Time.readFromString(line)
        line = input.next().strip()
        endTime = Time.readFromString(line)

        line = input.next().strip()  #SLICE
        assert line == "SLICE"
        line = input.next().strip()  # first time slice

        timeSlice1 = Time.readFromString(line)

        timeStep = timeSlice1 - startTime
        if timeStep.getMinutes() == 0:
            raise DtaError(
                "The time step defined by the first slice cannot be zero")

        demand = Demand(net, vehClassName, startTime, endTime, timeStep)
        _npyArray = demand._demandTable.getNumpyArray()

        timeStepInMin = timeStep.getMinutes()

        for i, timePeriod in enumerate(demand.iterTimePeriods()):
            if timePeriod != demand.startTime + demand.timeStep:
                line = input.next().strip()
                assert line == "SLICE"
                line = input.next().strip()
            destinations = map(int, input.next().strip().split())
            for j, origin in enumerate(range(net.getNumCentroids())):
                fields = map(float, input.next().strip().split())
                #_npyArray[i,j,:] = np.array(fields[1:]) / ( 60.0 / timeStepInMin)
                _npyArray[i, j, :] = np.array(fields[1:])

        return demand
Esempio n. 2
0
    #magic numbers here. This information may (or may not) be somewhere in the .dqt files 
    simStartTime = 14 * 60 + 30
    simEndTime = 21 * 60 + 30
    simTimeStep = 5
    net.readSimResults(simStartTime, simEndTime, 5)

    DtaLogger.info("Reading 15-minute link counts")
    net.readObsLinkCounts(COUNT_DIR + "/" + LINK_COUNT_FILE_15MIN)
    DtaLogger.info("Reading 15-minute movement counts")
    net.readObsMovementCounts(COUNT_DIR + "/" + MOVEMENT_COUNT_FILE_15MIN)
    DtaLogger.info("Reading 5-minute movement counts")
    net.readObsMovementCounts(COUNT_DIR + "/" + MOVEMENT_COUNT_FILE_5MIN)
    

    reportStartTime = Time.readFromString(REPORTING_START_TIME).getMinutes()
    reportEndTime = Time.readFromString(REPORTING_END_TIME).getMinutes()

    routeTTOuput = open(REPORTS_ROUTE_TRAVEL_TIME_FILE, "w") 

    routeTTOuput.write("%s,%s,%s,%s,%s\n" % ("RouteName", "SimTravelTimeInMin", "ObsTravelTimeInMin", "SimRouteLengthInMiles", "ObsRouteLengthInMiles"))

    allRoutes = []
    for record in csv.DictReader(open(ROUTE_DEFINITION_FILE, "r")):
        streetNames = []

        name = record["RouteName"].strip()
        regex = re.compile(r",| AND|\&|\@|\ AT|\/")
        streetNames = regex.split(name)
        #streetNames_cleaned = [net.cleanStreetName(nm) for nm in streetNames]
Esempio n. 3
0
    # write the shape file
    DtaLogger.info("Writing shape files")

    net.writeLinksToShp("sf_links")
    net.writeNodesToShp("sf_nodes")

    # write out the total volume on all links
    DtaLogger.info("Writing total volumes")

    # start with the header
    outputStream = open(LINK_VOLUME_FILE_TOTAL, "w")
    outputStream.write(
        "ANode,BNode,LinkID,LengthInMiles,Label,FacilityType,FreeflowSpeed,NumLanes,StartTime,EndTime,ModelVolume,TravelTime,ModelVolume4to6,ModelVolume5to6\n"
    )

    reportStartTime = Time.readFromString(START_TIME).getMinutes()
    reportEndTime = Time.readFromString(END_TIME).getMinutes()

    # now loop through all links
    for link in net.iterRoadLinks():
        outputStream.write("%d," % link.getStartNode().getId())
        outputStream.write("%d," % link.getEndNode().getId())
        outputStream.write("%d," % link.getId())
        outputStream.write("%f," % link.getLength())
        outputStream.write("%s," % link.getLabel())
        outputStream.write("%d," % link.getFacilityType())
        outputStream.write("%d," % link.getFreeFlowSpeedInMPH())
        outputStream.write("%d," % link.getNumLanes())
        outputStream.write("%s," % Time.fromMinutes(reportStartTime))
        outputStream.write("%s," % Time.fromMinutes(reportEndTime))
        outputStream.write(