Uses Google's Directions API to calculate commute times to/from potential homes
All functions will require
If you don't want to set your timezone by hand (see below), you'll also need
The grid search will additionally require
numpy. If you want to bound the search
to be within a state's boundaries (e.g. if you want to exclude the ocean from your
search), then you'll also need
bokeh is required to plot the results of the grid search overtop a Google
There are two main ways to use these tools. In either case, you must first setup your configuration file and create an API key.
Second, create your configuration file. It should look like:
timezone: <timezone, e.g. America/San_Francisco, or don't include to use local timezone> api_key: <Google API key> commutes: <person 1 name>: address: <person 1 work address> arrival_hour: <hour person 1 arrives at work (24-hour; e.g. 9) arrival_minute: <minute person 1 arrives at work> departure_hour: <hour person 1 departs work (24-hour; e.g. 17) departure_minute: <minute person 1 departs work> <person 2 name>: ... ...
You can either save this in the same directory as the scripts as
private_info.txt, or you can give it any name you want and pass it to
each of the scripts as
python commute_times.py with the address you want to calculate
commute times relative to (i.e. the address of a house/apartment for sale/rent).
python commute_times.py --help to see the available options, which include
the period of time over which the commute will be calculated, which model to
print the final summary for, and the path to the configuration filename.
The script will use the Directions API to query for the right time to leave
in the morning and the amount of time it'll take to get home in the afternoon
for each person given in the configuration file. It'll do this for all three
models, then print out a table for each person of best and worst case scenarios
for each traffic model, then finally print a summary of the average guess from
There are also tools to create a grid of commute times to and from work for each person within some lat/lng boundaries. Note that this will take a good bit of time, especially for the commute to work where the departure time is uncertain (in particular, this is the function that will end up costing you money, if anything does), so don't go too crazy with the number of points right away.
First, you're going to use
build_commute_grid.py to query commute times from
a grid of latitute and longitute points, the results of which will be saved to a
pickle file given by the sole required argument. However, the limits of the
rectangle (given by
northern/southern/eastern/western_limit) and the number
of points (
npts) are both important optional arguments. You should also set
the name of the state that you want to bound the points within (usually to
separate land from water), or you can set to
None (as a string) to skip this
step (e.g. for a completely land area). Once you've set all your args (perferably
with a low
npts to start, something like 3 - 5), fire off the script and wait
for it to finish.
Next you'll want to plot the result. Call
plot_commute_grid.py to get a sense
of the arguments. There are two required args, the name of the pickle file that
you created with
build_commute_grid.py, and the name of the output file you want
to create (will be an html webpage). Most of the optional arguments are
self-explanatory, except perhaps
center_lng -- these set the
initial center of the map. If either of these are not (independently) set as valid
floats, then the code will default to the center of the grid.
Run the code, and it should open up a file in your browser that contains a map of the number of minutes each person's commute to and from work is expected to take. The code will also create a map that shows the "happy place," defined as the region where all of the commutes are less than some specified length (which defaults to 45 minutes). The red area will have at least 2 "unhappy" commutes (and are thus ruled out) while the orange areas have exactly one unhappy commute.
Your first go with only a few grid points probably won't be very useful -- it'll
be too coarse-grained to really show you anything. Once you're satisfied with the
boundaries of the grid, go ahead and rerun
build_commute_grid.py with a larger
npts (probably something like 25 - 50), then rerun
and find your happy place!