Skip to content

Commit

Permalink
Merge branch 'master' into quick_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bpben authored Mar 18, 2019
2 parents 4fca637 + 1dc2bee commit 9be385c
Show file tree
Hide file tree
Showing 38 changed files with 2,057 additions and 293 deletions.
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ channels:
dependencies:
- codecov
# Conda packacking issue, will want to revisit later
- fiona=1.8.3
- fiona
- folium
- geopandas
- geocoder
Expand Down
977 changes: 977 additions & 0 deletions notebooks/clustering_segment_level.ipynb

Large diffs are not rendered by default.

209 changes: 209 additions & 0 deletions notebooks/intervention_effect.ipynb

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/config/config_cambridge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,8 @@ waze_features:
jam: Existence of a jam
continuous:
jam_percent: Percent of time there was a jam

avg_jam_level: Jam level
# alert_WEATHERHAZARD: Waze weather hazard alert
# alert_JAM: Waze jam alert
# alert_ROAD_CLOSED: Waze road closed alert
# alert_ACCIDENT: Waze crash alert
78 changes: 78 additions & 0 deletions src/config/config_losangeles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# City name
city: Los Angeles, CA, USA
# City centerpoint latitude & longitude (default geocoded values set)
city_latitude: 34.0522
city_longitude: -118.2437

# City's time zone: defaults to the local time zone of computer initializing the city's config file
timezone: America/Los_Angeles
# Radius of city's road network from centerpoint in km, required if OSM has no polygon data (defaults to 20km)
city_radius: 50

# The folder under data where this city's data is stored
name: losangeles

# If given, limit crashes to after startdate and no later than enddate
# Recommended to limit to just a few years for now
startdate: 1/1/2016
enddate:

# The type of predictions to generate, 'segment' is default, 'week' is legacy
level: 'segment'

#################################################################
# Configuration for data standardization

# crash file configurations
crashes_files:
LA_TrafficData.csv:
required:
id: ID
latitude: Latitude
longitude: Longitude
# If date supplied in single column:
date_complete: Date
# If date is separated into year/month/day:
date_year:
date_month:
# Leave date_day empty if not available
date_day:
# If time is available and separate from date:
time: Time
# If time specified, time_format is one of:
# default (HH:MM:SS)
# seconds (since midnight)
# military (HHMM)
time_format: military
optional:
summary:
# If the crash file doesn't have a lat/lon, you must give the address field
# and you will need to run the geocode_batch script - see the README
address: Address
vehicles:
bikes:

# If using legacy 'week' predictions:
# specify year & week on which to predict crashes (best practice is year & week towards the end of your crash data set
# in format [month, year]
time_target: [30, 2017]
# specify how many weeks back to predict in output of train_model
weeks_back: 1

#################################################################
# Configuration for default features

# Default features from open street map. You can remove features you don't want
# Note: we don't support adding features in the config file.
# If there is an additional feature you want from open street map, contact the development team
openstreetmap_features:
categorical:
width: Width
cycleway_type: Bike lane
signal: Signal
oneway: One Way
lanes: Number of lanes
continuous:
width_per_lane: Average width per lane


2 changes: 1 addition & 1 deletion src/data/TMC_scraping/parse_tmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def snap_inter_and_non_inter(summary):
# Create spatial index for quick lookup
segments_index = rtree.index.Index()
for idx, element in enumerate(inter):
segments_index.insert(idx, element[0].bounds)
segments_index.insert(idx, element.geometry.bounds)
print("Snapping tmcs to intersections")

address_records = util.raw_to_record_list(
Expand Down
22 changes: 11 additions & 11 deletions src/data/add_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,15 @@ def get_int_mapping(lines, buffered, buffered_index):
# Go through each line from the osm map
for i, line in enumerate(lines):
util.track(i, 1000, len(lines))
line_buffer = line[0].buffer(10)
line_buffer = line.geometry.buffer(10)

best_match = {}
best_overlap = 0
for idx in buffered_index.intersection(line_buffer.bounds):
buffer = buffered[idx][0]
# If the new buffered intersection intersects the old one
# figure out how much overlap, and take the best one
if buffer.intersects(line[0]):
if buffer.intersects(line.geometry):
total_area = unary_union([line_buffer, buffer]).area
overlap = max(
line_buffer.area/total_area, buffer.area/total_area)
Expand All @@ -178,7 +178,7 @@ def get_int_mapping(lines, buffered, buffered_index):
best_overlap = overlap
best_match = buffered[idx][2]

line_results.append([line[0], line[1], best_match])
line_results.append([line.geometry, line.properties, best_match])

total = len(line_results)
percent_matched = 100 - 100 * float(
Expand Down Expand Up @@ -212,19 +212,19 @@ def get_candidates(buffered, buffered_index, lines):

# First, get candidates from new map that overlap the buffer
# from the original map
for idx in buffered_index.intersection(line[0].bounds):
for idx in buffered_index.intersection(line.geometry.bounds):
buffer = buffered[idx][0]

# If the new line overlaps the old line
# then check whether it is entirely within the old buffer
if buffer.intersects(line[0]):
if buffer.intersects(line.geometry):

# Add the linestring and the features to the overlap list
overlapping.append((buffered[idx][1], buffered[idx][2]))

results.append({
'line': line[0],
'properties': line[1],
'line': line.geometry,
'properties': line.properties,
'candidates': overlapping,
})

Expand Down Expand Up @@ -316,8 +316,8 @@ def add_int_features(int_lines, dir1, dir2, featlist):

# Buffer all the new lines
for idx, new_line in enumerate(new_map_non_inter):
b = new_line[0].buffer(20)
new_buffered.append((b, new_line[0], new_line[1]))
b = new_line.geometry.buffer(20)
new_buffered.append((b, new_line.geometry, new_line.properties))
new_index.insert(idx, b.bounds)

non_ints_with_candidates = get_candidates(
Expand Down Expand Up @@ -348,8 +348,8 @@ def add_int_features(int_lines, dir1, dir2, featlist):
new_buffered_inter = []
new_index_inter = rtree.index.Index()
for idx, new_line in enumerate(new_map_inter):
b = new_line[0].buffer(10)
new_buffered_inter.append((b, new_line[0], new_line[1]))
b = new_line.geometry.buffer(10)
new_buffered_inter.append((b, new_line.geometry, new_line.properties))
new_index_inter.insert(idx, b.bounds)

int_results = get_int_mapping(
Expand Down
Loading

0 comments on commit 9be385c

Please sign in to comment.