當前位置: 首頁>>代碼示例>>Python>>正文


Python GTFSDatabase.stop方法代碼示例

本文整理匯總了Python中graphserver.ext.gtfs.gtfsdb.GTFSDatabase.stop方法的典型用法代碼示例。如果您正苦於以下問題:Python GTFSDatabase.stop方法的具體用法?Python GTFSDatabase.stop怎麽用?Python GTFSDatabase.stop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在graphserver.ext.gtfs.gtfsdb.GTFSDatabase的用法示例。


在下文中一共展示了GTFSDatabase.stop方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: dict

# 需要導入模塊: from graphserver.ext.gtfs.gtfsdb import GTFSDatabase [as 別名]
# 或者: from graphserver.ext.gtfs.gtfsdb.GTFSDatabase import stop [as 別名]
station_labels = npz['station_labels']
matrix         = npz['matrix'].astype(np.int32)

station_idx = dict( zip(station_labels, range(len(station_labels))) )

origins = list(station_labels)
destinations = origins[:] # copy 1 level

random.shuffle(origins)
random.shuffle(destinations)

pairs = zip(origins, destinations)
errors = []

for o, d in pairs : 
    og = gtfsdb.stop(o[4:])
    dg = gtfsdb.stop(d[4:])
    #print 'Origin (mds, gtfs)'
    #print o, og
    #print 'Destination (mds, gtfs)'
    #print d, dg
    print 'from %s to %s (%f, %f) -> (%f, %f)' % (og[1], dg[1], og[2], og[3], dg[2], dg[3])

    tm = matrix[station_idx[o], station_idx[d]] / 60.
    
    from_str = '%f,%f' % (og[2], og[3])
    to_str   = '%f,%f' % (dg[2], dg[3])
    conn = httplib.HTTPConnection('developer.trimet.org')
    conn.request("GET", URL_FORMAT % (from_str, to_str, TRIP_DATE, TRIP_TIME) )
    r1 = conn.getresponse()
    #print r1.status, r1.reason
開發者ID:abyrd,項目名稱:metric-embedding,代碼行數:33,代碼來源:tritest-od.py

示例2: MakeMatrixThread

# 需要導入模塊: from graphserver.ext.gtfs.gtfsdb import GTFSDatabase [as 別名]
# 或者: from graphserver.ext.gtfs.gtfsdb.GTFSDatabase import stop [as 別名]
class MakeMatrixThread(QtCore.QThread):
    def __init__(self, parent=None):
        QtCore.QThread.__init__(self, parent)
        self.exiting = False

    def makeMatrix(self, gtfsdb, gdb):
        self.gtfsdb = str(gtfsdb)
        self.gdb = str(gdb)
        self.start()

    def run(self):
        self.gtfsdb = GTFSDatabase(self.gtfsdb)
        self.gdb = GraphDatabase(self.gdb)
        # Calculate an origin-destination matrix for the graph's stations
        print "Loading Graphserver DB..."
        self.emit(QtCore.SIGNAL("say(QString)"), QtCore.QString("Loading SQLite Graphserver graph..."))
        g = self.gdb.incarnate()

        # Set up distance-preserving projection system
        # Make a grid over the study area and save its geographic coordinates
        MARGIN = 8000  # meters beyond all stations, diagonally
        min_lon, min_lat, max_lon, max_lat = self.gtfsdb.extent()
        geod = pyproj.Geod(ellps="WGS84")
        min_lon, min_lat, arc_dist = geod.fwd(min_lon, min_lat, 180 + 45, MARGIN)
        max_lon, max_lat, arc_dist = geod.fwd(max_lon, max_lat, 45, MARGIN)
        proj = pyproj.Proj(proj="sinu", ellps="WGS84")
        min_x, min_y = proj(min_lon, min_lat)
        proj = pyproj.Proj(
            proj="sinu", ellps="WGS84", lon_0=min_lon, y_0=-min_y
        )  # why doesn't m parameter work for scaling by 100?
        grid_dim = array(proj(max_lon, max_lat), dtype=int32) / 100
        max_x, max_y = grid_dim
        print "\nMaking grid with dimesions: ", max_x, max_y
        self.emit(QtCore.SIGNAL("say(QString)"), QtCore.QString("Making %i by %i grid..." % (max_x, max_y)))
        # later, use reshape/flat to switch between 1d and 2d array representation
        grid_latlon = empty((max_x, max_y, 2), dtype=float32)
        for y in range(0, max_y):
            self.emit(QtCore.SIGNAL("progress(int, int)"), y, max_y)
            for x in range(0, max_x):
                # inverse project meters to lat/lon
                grid_latlon[x, y] = proj(x * 100, y * 100, inverse=True)

        station_vertices = [v for v in g.vertices if v.label[0:4] == "sta-"]
        station_labels = [v.label for v in station_vertices]
        n_stations = len(station_vertices)
        print "Finding station coordinates..."
        self.emit(QtCore.SIGNAL("say(QString)"), QtCore.QString("Projecting station coordinates..."))
        station_coords = empty((n_stations, 2), dtype=float32)
        for i, label in enumerate(station_labels):
            stop_id, stop_name, lat, lon = self.gtfsdb.stop(label[4:])
            station_coords[i] = proj(lon, lat)
            if i % 20 == 0:
                self.emit(QtCore.SIGNAL("progress(int, int)"), i, n_stations)
        station_coords /= 100

        # ELIMINATE STATIONS WITH SAME INTEGRAL COORDINATES
        # self.emit( QtCore.SIGNAL( 'say(QString)' ), QtCore.QString( 'Eliminating equivalent stations...'  ) )
        # while len(station_coords) > 0 :
        #    coord =
        #    mask = station_coords != station_coords[i]
        #    station_coords = station_coords[mask]
        # newer version follows
        # self.emit( QtCore.SIGNAL( 'say(QString)' ), QtCore.QString( 'Eliminating equivalent stations...' ) )
        # station_labels = np.array(station_labels)
        # station_coords_new = []
        # station_labels_new = []
        # while len(station_coords) > 0 :
        #    coord = np.round(station_coords[0])
        #    minIdx = np.argmin(np.sum(np.abs(station_coords - coord), axis=1))
        #    station_labels_new.append(station_labels[minIdx])
        #    station_coords_new.append(station_coords[minIdx])
        #    mask = np.any(np.round(station_coords) != coord, axis=1)
        #    #print mask
        #    #print len(station_coords)
        #    #print coord
        #    #print station_coords[np.logical_not(mask)]
        #    station_coords = station_coords[mask][:]
        #    station_labels = station_labels[mask][:]
        #    self.emit( QtCore.SIGNAL( 'progress(int, int)' ), n_stations - len(station_coords_new), n_stations )
        #
        # station_labels = station_labels_new
        # station_coords = station_coords_new
        # station_vertices = [g.get_vertex(slabel) for slabel in station_labels_new]
        # n_stations = len(station_labels)
        # print len(station_labels), len(station_coords), len(station_vertices)

        print "Making OD matrix..."
        os.environ["TZ"] = "US/Pacific"
        time.tzset()
        t0s = "Tue Mar 09 08:00:00 2010"
        t0t = time.strptime(t0s)
        d0s = time.strftime("%a %b %d %Y", t0t)
        t0 = int(time.mktime(t0t))
        print "search date: ", d0s
        print "search time: ", time.ctime(t0), t0

        wo = WalkOptions()
        wo.max_walk = 20000
        wo.walking_overage = 0.1
        wo.walking_speed = 1  # trimet uses 0.03 miles / 1 minute
#.........這裏部分代碼省略.........
開發者ID:abyrd,項目名稱:metric-embedding,代碼行數:103,代碼來源:qt_prep.py

示例3: dict

# 需要導入模塊: from graphserver.ext.gtfs.gtfsdb import GTFSDatabase [as 別名]
# 或者: from graphserver.ext.gtfs.gtfsdb.GTFSDatabase import stop [as 別名]
r = np.load('results/pdx-5d-1000i/result.npy')

station_idx = dict( zip(station_labels, range(len(station_labels))) )

origins = list(zip(station_labels, np.round(station_coords).astype(np.int32)))
destinations = origins[:] # copy 1 level

random.shuffle(origins)
random.shuffle(destinations)

pairs = zip(origins, destinations)
errors = []

for o, d in pairs : 
    og = gtfsdb.stop(o[0][4:])
    dg = gtfsdb.stop(d[0][4:])
    #print 'Origin (mds, gtfs)'
    #print o, og
    #print 'Destination (mds, gtfs)'
    #print d, dg
    print 'from %s to %s (%f, %f) -> (%f, %f)' % (og[1], dg[1], og[2], og[3], dg[2], dg[3])

    p1 = r[ o[1][0], o[1][1] ]
    p2 = r[ d[1][0], d[1][1] ]
    vec = p1 - p2
    tmds = np.sqrt(np.sum(vec ** 2)) / 60
    
    tmat = matrix[ station_idx[ o[0] ], station_idx[ d[0] ] ] / 60.

    llo = (og[2], og[3])
開發者ID:abyrd,項目名稱:metric-embedding,代碼行數:32,代碼來源:tritest.py

示例4: zip

# 需要導入模塊: from graphserver.ext.gtfs.gtfsdb import GTFSDatabase [as 別名]
# 或者: from graphserver.ext.gtfs.gtfsdb.GTFSDatabase import stop [as 別名]
pairs = zip(origins, destinations)[:SAMPLE_SIZE]

wo = WalkOptions() 
wo.max_walk = 2000 
wo.walking_overage = 0.0
wo.walking_speed = 1.0 # trimet uses 0.03 miles / 1 minute - but it uses straight line distance as well
wo.transfer_penalty = 60 * 10
wo.walking_reluctance = 1.5
wo.max_transfers = 5
wo.transfer_slack = 60 * 4

residuals  = []
magnitudes = []
normalize = 0
for o, d in pairs : 
    og = gtfsdb.stop(o)
    dg = gtfsdb.stop(d)
    #print 'Origin (mds, gtfs)'
    #print o, og
    #print 'Destination (mds, gtfs)'
    #print d, dg
    print 'from %s to %s (%f, %f) -> (%f, %f)' % (og[0], dg[0], og[2], og[3], dg[2], dg[3])

    #replace
    spt = g.shortest_path_tree( 'sta-' + o, 'sta-' + d, State(1, t0), wo )
    try:
        vp = spt.get_vertex( 'sta-' + d ).best_state
    except:
        print 'Graphserver search failed.'
        continue
            
開發者ID:abyrd,項目名稱:metric-embedding,代碼行數:32,代碼來源:trimet_web_test.py


注:本文中的graphserver.ext.gtfs.gtfsdb.GTFSDatabase.stop方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。