| |
- BusTrack.BusTrack(__builtin__.object)
-
- GPSBusTrack
- __builtin__.object
-
- GPSBusSchedule
- GPSSchedule
class GPSBusSchedule(__builtin__.object) |
|
A GPSBusSchedule object represents the actual arrival times of a
GPS-tracked bus at its stops as described in the matching GTFS schedule.
This class also serves as a central source for GTFSBusSchedule,
GPSBusTrack, and GTFSBusTrack objects. |
|
Methods defined here:
- __init__(self, segment_id, trip_id=None, offset=None)
- Creates a schedule matchup based on the specified tracked segment.
If trip_id is specified, uses the GTFS schedule for that trip ID,
otherwise uses the trip ID specified in the database.
If offset is specified, then that offset is applied against GTFS
data, otherwise the offset specified in the database is used.
- getGPSBusTrack(self)
- getGPSSchedule(self)
- getGTFSBusTrack(self, use_shape=False)
- getGTFSSchedule(self)
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class GPSBusTrack(BusTrack.BusTrack) |
|
A BusTrack which interpolates the bus route between recorded
lat/lon points from a GPS log. |
|
- Method resolution order:
- GPSBusTrack
- BusTrack.BusTrack
- __builtin__.object
Methods defined here:
- __init__(self, vehicle_segment)
- Given a VehicleSegment, builds the interpolation.
- findLaunchTime(self, tol=50)
- Finds the time that the bus moved tol meters from start point.
If there is no shape data, then the start point is the first
point in the dataset. Otherwise, the start point is defined by
the first point in the shape. In this case, we first find the
time that the bus arrived at the start point, then search for
the launch from there.
- getMatchingGTFSTripID(self, search_size=20, oob_threshold=0.5)
- Returns (tid,offset,error), or None if no matches are found
Where tid is the GTFS trip_id for the trip which best matches
the trip represented by this interpolation, offset is the offset
in seconds to apply to the GTFS schedule to normalize according
to 24 hour times, and error is the distance as measured from the
GTFS trip.
search_size indicates how many guesses to look at from
gtfs schedule data, from which the best match is chosen.
oob_threshold indicates the maximum fraction of the gtfs time
window for which this gps route is allowed to not exist in order
for that gtfs trip to be a candidate for a match.
- measureDistanceFromGTFSTrip(self, trip_id, offset_seconds=0, penalize_gps_oob=True, penalize_gtfs_oob=True)
- Given a GTFS Trip ID and an offset in seconds, returns
(distance, oob_frac)
where dist measures the distance of this trip from that one
as described below, and oob_frac is the fraction of scheduled
stops (out of total number of stops) whose times are outside
the time window of this GPS segment.
The penalize_xxx_oob parameters are used to indicate whether
to penalize for special out-of-bounds cases. See below for details.
Let n = # of timepoints for the GTFS trip
For each timepoint T_i in the GTFS trip, let
G(T_i) = location of GTFS scheduled stop at T_i
B(T_i) = location of GPS signal at T_i+offset_seconds
Then this function will return as the distance
Sqrt( 1/n * Sum over i=1:n of Distance[G(T_i),B(T_i)]**2 )
Note that the normalization factor of 1/n is necessary
to prevent favoring of shorter routes.
Typically the offset will be set to 86400 (24 hours) in cases
where the GTFS trip is a "late night" (after midnight) schedule
which means its times will be greater than 86400 (in seconds).
The 'penalize_xxx_oob' parameters are used to determine what special
treatment will be given to cases where bounding time window of
the GPS trip is not well-matched to that of the GTFS trip.
(That is, whether or not to penalize periods of time where the gtfs
or gps data is "out of bounds" of the other).
This breaks down into two basic cases:
1. Periods of time where GPS data exists but the GTFS schedule does not.
That is, the GPS data is out of bounds of the GTFS time window.
2. Periods of time where the GTFS trip has schedule data but the GPS
trip does not. That is, the GPS trip starts after the GTFS schedule,
and/or it ends before the GTFS schedule, and so the GTFS data is
out of bounds of the GPS time window.
If penalize_gtfs_oob is False, then for periods where the GTFS trip
exists but the GPS trip does not, the GTFS is truncated to match the
GPS time window. Otherwise, it is not truncated.
If penalize_gps_oob is False, then for periods where the GPS trip exists
but the GTFS trip does not, the GPS trip is truncated to match the GTFS
time window. Otherwise, it is not truncated.
The costs for non-truncated out-of-bound segments are handled as follows:
- For timepoints T_i where GTFS exists and GPS does not, the distance
between them is measured as though the GPS was found at the location
of its first (or last) point. That is, if there is a GTFS timepoint
before the beginning of the GPS trip, we use the first point in the
GPS trip; if there is a GTFS timepoint after the end of the GPS trip,
we use the last point in the GPS trip.
- For cases where GPS exists and GTFS does not, we fabricate evenly
spaced time points T_k for k = 1 to n, where
n = (GTFS_stops / GTFS_time) * GPS_OOB_time
GTFS_time = time span of GTFS trip
GTFS_stops = number of stops in GTFS trip
GPS_OOB_time = amount of time GPS trip exists before/after GTFS trip
For each of this times T_k the GTFS location is calculated as for
the GPS trip in the case above.
This is used, for example, in a case where the GPS signal was
turned on several minutes late into the trip, the trip can match
very well with the GTFS schedule during that time the signal
is alive, but during the beginning of the GTFS schedule
there is no data.
In other cases, the GPS signal has been turned on several minutes
early, before it has even arrived at the beginning of its route.
You may wish to penalize this kind of behavior, or ignore it.
WARNING: if penalize_gtfs_oob=False and penalize_gps_oob=False,
then the distance returned from this route with a GTFS trip
with no overlap in time will be 0!
Methods inherited from BusTrack.BusTrack:
- getArrivalTimeAtLocation(self, stoploc, tol=10.0, starttime=None)
- Given a stop location (lat,lon), a tolerance in meters, and a starting
time, does the following:
Finds the first time interval (t1,t2) within which the line segments
of this track are all within tol meters of stoploc, and t1>starttime.
Returns the time t such that t1<=t<=t2 at which this track was closest
to stoploc.
If this track was never within tol meters of the location, then
returns None.
- getBoundingBox(self)
- Returns (lonmin,lonmax,latmin,latmax) the lat/lon bounds
of this route's traversal.
- getLocationAtTime(self, time)
- Given a time, returns a (lat,lon) location of the (estimated)
location of the bus at that time. If the time is before or after
the bounding time of the route, then None is returned.
- getRouteTimeInterval(self)
- Returns the (begin,end) times for which this BusTrack exists.
- getTimesAtLocation(self, latlon, tol=10.0)
- Given a (lat,lon), returns the (begin,end) interval of the
(estimated) times that the bus was within tol meters of that
location.
- set_attributes(self, dictlike)
- Sets attributes as, for each key in dictlike,
self.key = dictlike[key]
Data descriptors inherited from BusTrack.BusTrack:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class GPSSchedule(__builtin__.object) |
|
A lighter version of the GPSBusSchedule below, this class just
loads arrival time data as cached in the database (the results
from a GPSBusSchedule matchup). |
|
Methods defined here:
- __init__(self, segment_id)
- Loads segment_id's gps schedule from database
- getEarlyAndLateMeans(self, arrival_schedule=None)
- Returns (mu_e,mu_l)
where mu_e = mean of all early arrival times
and mu_l = mean of all late arrival times.
Can optionall specify a static arrival schedule to calculate.
- getNumTimePoints(self, arrival_schedule=None)
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
| |