Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
"""
Write the region IDs for each pickup and dropoff in the OD data.
For each row in --filename such as "./data/od_part-m-000.pkl",
write the corresponding list of pickup region IDs to string -d
write the corresponding list of dropoff region IDs to string -p
"""
import pandas as pd
import numpy as np
from math import floor, ceil
from matplotlib import path
import argparse
def process_line(line):
# Not sure what these values are used for tbh!
val1 = line[0]
val2 = line[1]
polyline = [float(v) for v in line[2:]]
polyline = np.array(list(zip(polyline[0::2], polyline[1::2])))
return val1, val2, polyline
def point_to_rids(point, polypaths, radius=0.0):
RIDs = []
for rid, polypath in enumerate(polypaths):
if polypath.contains_point(point, radius=radius):
RIDs.append(rid)
return RIDs
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--filename", "-f",
help="Filename of OD data to look at.",
type=str, nargs=1)
parser.add_argument("--drop_outname", "-d",
help="Filename to explort CSV of drop RIDs to",
type=str, nargs=1)
parser.add_argument("--pick_outname", "-p",
help="Filename to explort CSV of pick RIDs to",
type=str, nargs=1)
args = parser.parse_args()
fn = args.filename[0]
print(f"Processing {fn}")
with open("./DataForUConn/DecideRegion/area.txt") as f:
area = [process_line(line.split(",")) for line in f.read().strip().split("\n")]
polypaths = [path.Path(line[2][1:]) for line in area]
df = pd.read_pickle(fn)
pick_RIDs_outfile = open(args.pick_outname[0], "w+")
drop_RIDs_outfile = open(args.drop_outname[0], "w+")
for ii in range(len(df)):
if ii % 10000 == 0:
print(f" Processing point {ii} of {len(df)}...")
# Log points that correspond to 0 or multiple RIDs.
pick_point = (df["plon"][ii], df["plat"][ii])
drop_point = (df["dlon"][ii], df["dlat"][ii])
# List of region IDs for pickup, dropoff
list_of_pick_RIDs = point_to_rids(pick_point, polypaths=polypaths)
list_of_drop_RIDs = point_to_rids(drop_point, polypaths=polypaths)
pick_RIDs_outfile.write(str(list_of_pick_RIDs)[1:-1])
pick_RIDs_outfile.write("\n")
drop_RIDs_outfile.write(str(list_of_drop_RIDs)[1:-1])
drop_RIDs_outfile.write("\n")
pick_RIDs_outfile.close()
drop_RIDs_outfile.close()
"""
Usage:
python -i scr_005_od_rids.py -f ./data/od_part-m-000.pkl -p ./data/od_pick-000.csv -d ./data/od_drop-000.csv
python -i scr_005_od_rids.py -f ./data/od_part-m-001.pkl -p ./data/od_pick-001.csv -d ./data/od_drop-001.csv
python -i scr_005_od_rids.py -f ./data/od_part-m-002.pkl -p ./data/od_pick-002.csv -d ./data/od_drop-002.csv
python -i scr_005_od_rids.py -f ./data/od_part-m-003.pkl -p ./data/od_pick-003.csv -d ./data/od_drop-003.csv
python -i scr_005_od_rids.py -f ./data/od_part-m-004.pkl -p ./data/od_pick-004.csv -d ./data/od_drop-004.csv
python -i scr_005_od_rids.py -f ./data/od_part-m-005.pkl -p ./data/od_pick-005.csv -d ./data/od_drop-005.csv
python -i scr_005_od_rids.py -f ./data/od_part-m-006.pkl -p ./data/od_pick-006.csv -d ./data/od_drop-006.csv
python -i scr_005_od_rids.py -f ./data/od_part-m-007.pkl -p ./data/od_pick-007.csv -d ./data/od_drop-007.csv
python -i scr_005_od_rids.py -f ./data/od_part-m-008.pkl -p ./data/od_pick-008.csv -d ./data/od_drop-008.csv
python -i scr_005_od_rids.py -f ./data/od_part-m-009.pkl -p ./data/od_pick-009.csv -d ./data/od_drop-009.csv
python -i scr_005_od_rids.py -f ./data/od_part-m-010.pkl -p ./data/od_pick-010.csv -d ./data/od_drop-010.csv
python -i scr_005_od_rids.py -f ./data/od_part-m-011.pkl -p ./data/od_pick-011.csv -d ./data/od_drop-011.csv
"""