|
7 | 7 | import geopandas as gpd
|
8 | 8 | from stplanpy import od
|
9 | 9 | from stplanpy import dist
|
| 10 | +from stplanpy import cycle |
| 11 | +from stplanpy import route |
10 | 12 |
|
11 | 13 | in_dir = os.path.expanduser("../pct-inputs/02_intermediate/")
|
12 | 14 | out_dir = os.path.expanduser("../pct-outputs/static/commute/")
|
|
35 | 37 | # share in counties and places
|
36 | 38 | flow_data = flow_data.orig_dest(taz)
|
37 | 39 |
|
38 |
| -# Compute origin destination lines, distances, and gradient |
| 40 | +# Compute origin-destination lines |
39 | 41 | flow_data["geometry"] = flow_data.od_lines(taz_cent)
|
| 42 | + flow_data["od_lines"] = flow_data["geometry"] |
| 43 | + |
| 44 | +# Read the Cycle Streets API key |
| 45 | + cyclestreets_key = cycle.read_key() |
| 46 | + |
| 47 | +# Compute routes |
| 48 | + flow_data["geometry"] = flow_data.routes(api_key=cyclestreets_key) |
| 49 | + flow_data["routes"] = flow_data["geometry"] |
| 50 | + flow_data.find_cent() |
| 51 | + |
| 52 | +# Compute distances, gradients, and directness |
40 | 53 | flow_data["distance"] = flow_data.distances()
|
41 | 54 | flow_data["gradient"] = flow_data.gradient(taz_cent)
|
| 55 | + flow_data["directness"] = flow_data.directness() |
42 | 56 |
|
43 |
| -# Compute go_dutch scenario |
| 57 | +# Compute go_dutch and ebike scenarios |
44 | 58 | flow_data["go_dutch"] = flow_data.go_dutch()
|
| 59 | + flow_data["ebike"] = flow_data.ebike() |
45 | 60 |
|
46 | 61 | flow_data = gpd.GeoDataFrame(flow_data)
|
47 | 62 | flow_data = flow_data.set_crs("EPSG:6933")
|
|
59 | 74 | else:
|
60 | 75 | print("Compute taz")
|
61 | 76 |
|
62 |
| - taz = taz.mode_share(flow_data) |
| 77 | +# Compute mode share |
| 78 | + taz[["bike", "go_dutch", "ebike", "all"]] = taz.mode_share( |
| 79 | + flow_data, modes=["bike", "go_dutch", "ebike"]) |
| 80 | +# Compute mode share for trips shorter than 7.5km (4.5 miles) |
| 81 | + taz[["bike75", "go_dutch75", "ebike75", "all75"]] = taz.mode_share( |
| 82 | + flow_data.loc[flow_data["distance"] <= 7500], modes=["bike", "go_dutch", "ebike"]) |
63 | 83 | taz.to_pickle("taz.pkl")
|
64 | 84 |
|
65 | 85 | ################################################################################
|
66 | 86 |
|
67 | 87 | # Read place data
|
68 | 88 | place = pd.read_pickle(in_dir + "01_geographies/bayArea_place.pkl")
|
69 | 89 |
|
70 |
| -# Compute mode shares |
71 |
| -place = place.mode_share(flow_data) |
| 90 | +# Compute mode share |
| 91 | +place[["bike", "go_dutch", "ebike", "all"]] = place.mode_share( |
| 92 | + flow_data, modes=["bike", "go_dutch", "ebike"]) |
| 93 | +# Compute mode share for trips shorter than 7.5km (4.5 miles) |
| 94 | +place[["bike75", "go_dutch75", "ebike75", "all75"]] = place.mode_share( |
| 95 | + flow_data.loc[flow_data["distance"] <= 7500], modes=["bike", "go_dutch", "ebike"]) |
72 | 96 |
|
73 | 97 | # Write to disk
|
74 | 98 | place.to_crs("EPSG:4326").to_file(out_dir + "bayArea_place.GeoJson", driver="GeoJSON")
|
75 | 99 | place.to_pickle(out_dir + "bayArea_place.pkl")
|
76 | 100 |
|
77 | 101 | # Organize per place
|
78 |
| -for placefp in place.iterrows(): |
79 |
| - tz = taz.loc[(taz["placefp"] == placefp[0])].copy() |
| 102 | +for row in place.iterrows(): |
| 103 | + placefp = place.loc[row[0], "placefp"] |
| 104 | + tz = taz.loc[(taz["placefp"] == placefp)].copy() |
80 | 105 | if not tz.empty:
|
81 |
| - name = place.loc[placefp[0], "name"] |
| 106 | + name = place.loc[row[0], "name"] |
82 | 107 | print(name)
|
83 | 108 | # filter out place
|
84 | 109 | pc = place.loc[place["name"] != name]
|
|
90 | 115 | tz["name"] = tz.index
|
91 | 116 |
|
92 | 117 | # Remove NaN (countyfp)
|
93 |
| - tz = tz[["name", "all", "sov", "bike", "go_dutch", "geometry"]] |
94 |
| - pc = pc[["name", "all", "sov", "bike", "go_dutch", "geometry"]] |
| 118 | + tz = tz[["name", "all", "bike", "go_dutch", "ebike", "geometry"]] |
| 119 | + pc = pc[["name", "all", "bike", "go_dutch", "ebike", "geometry"]] |
95 | 120 |
|
96 | 121 | tz["geometry"] = tz["geometry"].simplify(5.0)
|
97 | 122 | pc["geometry"] = pc["geometry"].simplify(25.0)
|
98 | 123 |
|
99 | 124 | tz.to_crs("EPSG:4326").to_file(path + "/taz.GeoJson", driver="GeoJSON")
|
100 | 125 | pc.to_crs("EPSG:4326").to_file(path + "/place.GeoJson", driver="GeoJSON")
|
101 | 126 |
|
102 |
| - fd = flow_data.loc[(flow_data["orig_plc"] == placefp[0]) | (flow_data["dest_plc"] == placefp[0])] |
| 127 | + fd = flow_data.to_frm(placefp) |
103 | 128 |
|
104 |
| - name = place.loc[placefp[0], "name"] |
| 129 | + name = place.loc[row[0], "name"] |
105 | 130 | name = name.replace(" ","")
|
106 | 131 | path = out_dir + "place/" + name
|
107 | 132 | if not os.path.isdir(path):
|
108 | 133 | os.mkdir(path)
|
109 | 134 |
|
110 |
| -# stp.plot_dist(fd, path) |
111 |
| - |
112 |
| - fd = fd[["all", "bike", "go_dutch", "geometry", "distance", "gradient"]] |
| 135 | + fd = fd[["all", "bike", "go_dutch", "ebike", "geometry", "od_lines", "routes", "distance", "gradient", "directness"]] |
113 | 136 | if not fd.empty:
|
114 | 137 | fd = fd.loc[fd["distance"] > 0]
|
115 | 138 | fd = fd.loc[fd["distance"] < 30000]
|
| 139 | + network = fd.network() |
116 | 140 | fd = fd.nlargest(100, "bike")
|
117 |
| - fd.to_crs("EPSG:4326").to_file(path + "/line.GeoJson", driver="GeoJSON") |
| 141 | + fd.set_geometry("od_lines", crs=flow_data.crs).to_crs("EPSG:4326").drop(columns=["geometry","routes"]).to_file(path + "/line.GeoJson", driver="GeoJSON") |
| 142 | + fd.set_geometry("routes", crs=flow_data.crs).to_crs("EPSG:4326").drop(columns=["geometry","od_lines"]).to_file(path + "/route.GeoJson", driver="GeoJSON") |
| 143 | + network.to_crs("EPSG:4326").to_file(path + "/network.GeoJson", driver="GeoJSON") |
118 | 144 | else:
|
119 | 145 | ar = np.empty([1,6])
|
120 | 146 | ar[:,:] = np.nan
|
121 | 147 | fd = pd.DataFrame(data=ar, columns=fd.columns)
|
122 | 148 |
|
123 | 149 | fd.to_pickle(path + "/line.pkl")
|
| 150 | + network.to_pickle(path + "/network.pkl") |
124 | 151 |
|
125 | 152 | ################################################################################
|
126 | 153 |
|
127 | 154 | # Read county data
|
128 | 155 | county = pd.read_pickle(in_dir + "01_geographies/bayArea_county.pkl")
|
129 | 156 |
|
130 |
| -# Compute mode shares |
131 |
| -county = county.mode_share(flow_data) |
| 157 | +# Compute mode share |
| 158 | +county[["bike", "go_dutch", "ebike", "all"]] = county.mode_share( |
| 159 | + flow_data, modes=["bike", "go_dutch", "ebike"]) |
| 160 | +# Compute mode share for trips shorter than 7.5km (4.5 miles) |
| 161 | +county[["bike75", "go_dutch75", "ebike75", "all75"]] = county.mode_share( |
| 162 | + flow_data.loc[flow_data["distance"] <= 7500], modes=["bike", "go_dutch", "ebike"]) |
132 | 163 |
|
133 | 164 | # Write to disk
|
134 | 165 | county.to_crs("EPSG:4326").to_file(out_dir + "bayArea_county.GeoJson", driver="GeoJSON")
|
135 | 166 | county.to_pickle(out_dir + "bayArea_county.pkl")
|
136 | 167 |
|
137 | 168 | # Organize per county
|
138 |
| -for countyfp in county.iterrows(): |
139 |
| - tz = taz.loc[(taz["countyfp"] == countyfp[0])].copy() |
| 169 | +for row in county.iterrows(): |
| 170 | + countyfp = county.loc[row[0], "countyfp"] |
| 171 | + tz = taz.loc[(taz["countyfp"] == countyfp)].copy() |
140 | 172 | if not tz.empty:
|
141 |
| - name = county.loc[countyfp[0], "name"] |
| 173 | + name = county.loc[row[0], "name"] |
142 | 174 | print(name)
|
143 | 175 | # filter out county
|
144 | 176 | ct = county.loc[county["name"] != name]
|
|
150 | 182 | tz["name"] = tz.index
|
151 | 183 |
|
152 | 184 | # Remove NaN (placefp)
|
153 |
| - tz = tz[["name", "all", "sov", "bike", "go_dutch", "geometry"]] |
154 |
| - ct = ct[["name", "all", "sov", "bike", "go_dutch", "geometry"]] |
| 185 | + tz = tz[["name", "all", "bike", "go_dutch", "ebike", "geometry"]] |
| 186 | + ct = ct[["name", "all", "bike", "go_dutch", "ebike", "geometry"]] |
155 | 187 |
|
156 | 188 | tz["geometry"] = tz["geometry"].simplify(5.0)
|
157 | 189 | ct["geometry"] = ct["geometry"].simplify(25.0)
|
158 | 190 |
|
159 | 191 | tz.to_crs("EPSG:4326").to_file(path + "/taz.GeoJson", driver="GeoJSON")
|
160 | 192 | ct.to_crs("EPSG:4326").to_file(path + "/county.GeoJson", driver="GeoJSON")
|
161 | 193 |
|
162 |
| - fd = flow_data.loc[(flow_data["orig_cnt"] == countyfp[0]) | (flow_data["dest_cnt"] == countyfp[0])] |
| 194 | + fd = flow_data.to_frm(countyfp) |
163 | 195 |
|
164 |
| - name = county.loc[countyfp[0], "name"] |
| 196 | + name = county.loc[row[0], "name"] |
165 | 197 | name = name.replace(" ","")
|
166 | 198 | path = out_dir + "county/" + name
|
167 | 199 | if not os.path.isdir(path):
|
168 | 200 | os.mkdir(path)
|
169 | 201 |
|
170 |
| -# stp.plot_dist(fd, path) |
171 |
| - |
172 |
| - fd = fd[["all", "bike", "go_dutch", "geometry", "distance", "gradient"]] |
| 202 | + fd = fd[["all", "bike", "go_dutch", "ebike", "geometry", "od_lines", "routes", "distance", "gradient", "directness"]] |
173 | 203 | if not fd.empty:
|
174 | 204 | fd = fd.loc[fd["distance"] > 0]
|
175 | 205 | fd = fd.loc[fd["distance"] < 30000]
|
| 206 | + network = fd.network() |
176 | 207 | fd = fd.nlargest(100, "bike")
|
177 |
| - fd.to_crs("EPSG:4326").to_file(path + "/line.GeoJson", driver="GeoJSON") |
| 208 | + fd.set_geometry("od_lines", crs=flow_data.crs).to_crs("EPSG:4326").drop(columns=["geometry","routes"]).to_file(path + "/line.GeoJson", driver="GeoJSON") |
| 209 | + fd.set_geometry("routes", crs=flow_data.crs).to_crs("EPSG:4326").drop(columns=["geometry","od_lines"]).to_file(path + "/route.GeoJson", driver="GeoJSON") |
| 210 | + network.to_crs("EPSG:4326").to_file(path + "/network.GeoJson", driver="GeoJSON") |
178 | 211 | else:
|
179 | 212 | ar = np.empty([1,6])
|
180 | 213 | ar[:,:] = np.nan
|
181 | 214 | fd = pd.DataFrame(data=ar, columns=fd.columns)
|
182 | 215 |
|
183 | 216 | fd.to_pickle(path + "/line.pkl")
|
| 217 | + network.to_pickle(path + "/network.pkl") |
184 | 218 |
|
185 | 219 | ################################################################################
|
0 commit comments