def make_config_file(yml_file, timezone, city, folder, crash_file_path, map_file_path, map_inters_file_path, atmosphere_file_path, merged_file_path, cat_feat, cont_feat, keep_feat): address = geocode_address(city) f = open(yml_file, 'w') f.write( "# City name\n" + "city: {}\n".format(city) + "# City centerpoint latitude & longitude\n" + "city_latitude: {}\n".format(address[1]) + "city_longitude: {}\n".format(address[2]) + "# City's time zone [defaults to local to,e of computer]\n" + "timezone: {}\n".format(timezone) + "# The folder under data where this city's data is stored\n" + "name: {}\n".format(folder) + "# Limit crashes to between start and end date\n" + "startdate: \n" + "enddate: \n" + "#################################################################\n" + "crash_files:\n" + " {}\n".format(crash_file_path) + " {}\n".format(map_file_path) + " {}\n".format(map_inters_file_path) + " {}\n".format(atmosphere_file_path) + "cat_feat: {} \n".format(cat_feat) + "cont_feat: {} \n".format(cont_feat) + "keep_feat: {} \n".format(keep_feat) + "merged_data: {}".format(merged_file_path)) f.close() print("Wrote new configuration file in {}".format(yml_file))
def make_config_file(yml_file, city, timezone, folder, crash, concern, waze, additional_map=None, supplemental=[]): address = geocode_address(city) f = open(yml_file, 'w') f.write( "# City name\n" + "city: {}\n".format(city) + "# City centerpoint latitude & longitude (default geocoded values set)\n" + "city_latitude: {}\n".format(address[1]) + "city_longitude: {}\n\n".format(address[2]) + "# City's time zone: defaults to the local time zone of computer initializing the city's config file\n" + "timezone: {}\n".format(timezone) + "# Radius of city's road network from centerpoint in km, required if OSM has no polygon data (defaults to 20km)\n" + "city_radius: 20\n\n" + "# The folder under data where this city's data is stored\n" + "name: {}\n\n".format(folder) + "# If given, limit crashes to after startdate and no later than enddate\n" + "# Recommended to limit to just a few years for now\n" + "startdate: \n" + "enddate: \n\n" + "#################################################################\n" + "# Configuration for data standardization\n\n" + "# crash file configurations\n" + "crashes_files:\n" + " {}:\n".format(crash) + " required:\n" + " id: \n" + " latitude: \n" + " longitude: \n" + " # If date supplied in single column:\n" + " date_complete: \n" + " # If date is separated into year/month/day:\n" + " date_year: \n" + " date_month: \n" + " # Leave date_day empty if not available\n" + " date_day: \n" + " # If time is available and separate from date:\n" + " time: \n" + " # If time specified, time_format is one of:\n" + " # default (HH:MM:SS)\n" + " # seconds (since midnight)\n" + " # military (HHMM)\n" + " time_format: \n" + " optional:\n" + " summary: \n" + " # If the crash file doesn't have a lat/lon, you must give the address field\n" + " # and you will need to run the geocode_batch script - see the README\n" + " address: \n" + " vehicles: \n" + " bikes: \n\n") if concern: f.write("# List of concern type information\n" + "concern_files:\n" + " - name: concern\n" + " filename: {}\n".format(concern) + " latitude: \n" + " longitude: \n" + " time: \n\n") write_default_features(f, waze, supplemental, additional_map) f.write("") f.close() print("Wrote new configuration file in {}".format(yml_file))
def make_js_config(jsfile, city, folder): address = geocode_address(city) f = open(jsfile, 'w') f.write('var config = {\n' + ' MAPBOX_TOKEN: "",\n' + ' cities: [\n' + ' {\n' + ' name: "{}",\n'.format(city) + ' id: "{}",\n'.format(folder) + ' latitude: {},\n'.format(str(address[1])) + ' longitude: {},\n'.format(str(address[2])) + ' }\n' + ' ]\n' + '}\n') f.close()
def make_js_config(jsfile, city, folder): address = geocode_address(city) f = open(jsfile, 'w') f.write( 'var config = {\n' + ' MAPBOX_TOKEN: "pk.eyJ1IjoiZGVsZXdpczEzIiwiYSI6ImNqb3BjaTYzaDAwdjQzcWxsa3hsNzFtbmYifQ.yKj5c8ODg6yN0xTwmYS1LQ",\n' + ' cities: [\n' + ' {\n' + ' name: "{}",\n'.format(city) + ' id: "{}",\n'.format(folder) + ' latitude: {},\n'.format(str(address[1])) + ' longitude: {},\n'.format(str(address[2])) + ' }\n' + ' ]\n' + '}\n') f.close()
def make_config_file(yml_file, city, folder, crash, concern, supplemental=[]): address = geocode_address(city) f = open(yml_file, 'w') f.write( "# City name\n" + "city: {}\n".format(city) + "# City centerpoint latitude & longitude (default geocoded values set)\n" + "city_latitude: {}\n".format(address[1]) + "city_longitude: {}\n".format(address[2]) + "# Radius of city's road network from centerpoint in km, required if OSM has no polygon data (defaults to 20km)\n" + "city_radius: 20\n" + "# The folder under data where this city's data is stored\n" + "name: {}\n".format(folder) + "# If given, limit crashes to after start_year and before end_year\n" + "# Recommended to limit to just a few years for now\n" + "start_year: \n" + "end_year: \n" + "# level of predictions, either 'week' or 'segment'\n" + "level: 'segment'\n\n" + "#################################################################\n" + "# Configuration for data standardization\n\n" + "# crash file configurations\n" + "crashes_files:\n" + " {}:\n".format(crash) + " required:\n" + " id: \n" + " latitude: \n" + " longitude: \n" + " # If date supplied in single column:\n" + " date_complete: \n" + " # If date is separated into year/month/day:\n" + " date_year: \n" + " date_month: \n" + " # Leave date_day empty if not available\n" + " date_day: \n" + " # If time is available and separate from date:\n" + " time: \n" + " # If time specified, time_format is one of:\n" + " # default (HH:MM:SS)\n" + " # seconds (since midnight)\n" + " # military (HHMM)\n" + " time_format: \n" + " optional:\n" + " summary: \n" + " address: \n" + " vehicles: \n" + " bikes: \n\n") if concern: f.write("# List of concern type information\n" + "concern_files:\n" + " - name: concern\n" + " filename: {}\n".format(concern) + " latitude: \n" + " longitude: \n" + " time: \n\n\n") if supplemental: f.write("# Additional data sources\n" + "data_source:\n") for filename in supplemental: f.write( " - name: parking_tickets\n" + " filename: {}\n".format(filename) + " address: \n" + " date: \n" + " time: \n" + " category: \n" + " notes: \n" + " # Feature is categorical (f_cat) or continuous (f_cont)\n" + " feat: \n") f.write("\n") f.write( "# week on which to predict crashes (week, year)\n" + "# Best practice is to choose a week towards the end of your crash data set\n" + "# in format [month, year]\n" + "time_target: [30, 2017]\n" + "# specify how many weeks back to predict in output of train_model\n" + "weeks_back: 1") f.close() print("Wrote new configuration file in {}".format(yml_file))
"--address", type=str, help="Address you want to look up crashes for") parser.add_argument("-d", "--date", type=str, help="Date you want to look up crashes for." + "Needs either address or date") args = parser.parse_args() crash_items = json.load( open(os.path.join(args.datadir, 'processed', 'crash_joined.json'))) if args.address: address = util.geocode_address(args.address) combined_seg, segments_index = util.read_segments( dirname=os.path.join(args.datadir, 'processed/maps')) if address: print(address) # For now, need to get the address into the record type that # util.find_nearest needs. Eventually this should be cleaned up inproj = pyproj.Proj(init='epsg:4326') outproj = pyproj.Proj(init='epsg:3857') re_point = pyproj.transform(inproj, outproj, address[2], address[1]) point = Point(re_point) record = [{'point': point, 'properties': {}}]
parser.add_argument("-minx", "--minx", type=str) parser.add_argument("-miny", "--miny", type=str) parser.add_argument("-maxx", "--maxx", type=str) parser.add_argument("-maxy", "--maxy", type=str) args = parser.parse_args() feats = [] # Get a large buffer around the intersection address intersection = None if args.address: address = None if args.latlon: lat, lon = args.latlon.split(',') address = args.address, lat, lon else: address, lat, lon = util.geocode_address(args.address) intersection = Record({ 'location': { 'latitude': lat, 'longitude': lon }, 'address': address }) buffer = (intersection.point).buffer(250) else: # Convert to 3857 projection and get the bounding box minx = float(args.minx) miny = float(args.miny) maxx = float(args.maxx)
def make_config_file(yml_file, city, timezone, folder, crash, waze, additional_map=None, supplemental=[]): address = geocode_address(city) city_segments = city.split() speed_unit = 'kph' if city_segments[-1] == 'USA': speed_unit = 'mph' f = open(yml_file, 'w') f.write( "# City name\n" + "city: {}\n".format(city) + "# City centerpoint latitude & longitude (default geocoded values set)\n" + "city_latitude: {}\n".format(address[1]) + "city_longitude: {}\n\n".format(address[2]) + "# City's time zone: defaults to the local time zone of computer initializing the city's config file\n" + "timezone: {}\n".format(timezone) + "# Radius of city's road network from centerpoint in km, required if OSM has no polygon data (defaults to 20km)\n" + "city_radius: 20\n" + "speed_unit: {}\n\n".format(speed_unit) + "# By default, maps are created from OSM's polygon data and fall back to radius\n" + "# if there is no polygon data, but but you can change the openstreetmap_geography\n" + "# to 'radius' if preferred\n" + "map_geography: polygon\n\n" + "# The folder under data where this city's data is stored\n" + "name: {}\n\n".format(folder) + "# If given, limit crashes to after startdate and no later than enddate\n" + "# Recommended to limit to just a few years for now\n" + "startdate: \n" + "enddate: \n\n" + "#################################################################\n" + "# Configuration for data standardization\n\n" + "# crash file configurations\n" + "crashes_files:\n" + " {}:\n".format(crash) + " required:\n" + " id: \n" + " latitude: \n" + " longitude: \n" + " # If date supplied in single column:\n" + " date_complete: \n" + " # If date is separated into year/month/day:\n" + " date_year: \n" + " date_month: \n" + " # Leave date_day empty if not available\n" + " date_day: \n" + " # If time is available and separate from date:\n" + " time: \n" + " # If time specified, time_format is one of:\n" + " # default (HH:MM:SS)\n" + " # seconds (since midnight)\n" + " # military (HHMM)\n" + " time_format: \n" + " optional:\n" + " summary: \n" + " # If the crash file doesn't have a lat/lon, you must give the address field\n" + " # and you will need to run the geocode_batch script - see the README\n" + " address: \n" + " # This section allows you to specify additional feature in the crash file\n" + " # (split_columns) to go into the training set\n" + " # Most commonly split_columns are used for mode (pedestrian/bike/vehicle)\n" + " # but you can specify other fields in the crash data file.\n" + " # See the README for examples\n\n") write_default_features(f, waze, supplemental, additional_map) f.write("") f.close() print("Wrote new configuration file in {}".format(yml_file))
# If it's not a numbered street address, need to parse address if not re.match('[0-9]+', lines[0]): street1 = None street2 = None if ' & ' in lines[0]: street1, street2 = lines[0].split(' & ') elif r['Street Name'] and r['Cross Street']: street1 = r['Street Name'] street2 = r['Cross Street'] else: pass if street1 and street2: if count < 200: address = util.geocode_address(street1 + " & " + street2 + " Cambridge, MA") latitude = address[1] longitude = address[2] print(address) print(count) count += 1 else: latlong = lines[len(lines) - 1] latitude, longitude = lines[-1][1:-1].split(', ') r['X'] = longitude r['Y'] = latitude results.append(r)