Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions notebooks/Ranch-Demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,22 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 1,
"id": "186f2501",
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "NameError",
"evalue": "name 'external_dir' is not defined",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32mC:\\Users\\LOCAL_~1\\Temp/ipykernel_26752/3410258116.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m input_polygon_file = os.path.join(\n\u001b[1;32m----> 4\u001b[1;33m \u001b[0mexternal_dir\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 5\u001b[0m \u001b[1;34m\"sharedstreets_extract\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[1;34m\"merced.shp\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mNameError\u001b[0m: name 'external_dir' is not defined"
]
}
],
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why committing an error message?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should Probably Roll Back that file

"source": [
"# the polygon file for the area\n",
"\n",
Expand Down Expand Up @@ -1004,7 +1016,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3.7.10 64-bit ('env_tm2')",
"language": "python",
"name": "python3"
},
Expand All @@ -1019,6 +1031,11 @@
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.10"
},
"vscode": {
"interpreter": {
"hash": "9f2482f23d4c236f44d514af3ad984f5be74b05148b9f5e6233ac2798070880b"
}
}
},
"nbformat": 4,
Expand Down
22 changes: 20 additions & 2 deletions ranch/roadway.py
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,19 @@ def build_centroid_connectors(
"Missing taz node file, will use input taz polygon centroid"
)

if "county_gdf" not in self.__dict__.keys():
print('counhty not initialised')
self.county_gdf = gpd.read_file(r"\\corp.pbwan.net\us\CentralData\DCCLDA00\Standard\sag\projects\MTC\31000152\Network_Rebuild\LP_Local_folders\data\external\county_boundaries\county.shp")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like having this part in Ranch. Can we move this part to MTC's lasso?

self.county_variable_name = "NAME"


taz_polygon_gdf = gpd.sjoin(
taz_polygon_gdf,
self.county_gdf[['geometry', self.county_variable_name]],
how = 'left',
predicate = 'intersects'
)

if "county" not in taz_polygon_gdf.columns:
taz_polygon_gdf = gpd.sjoin(
taz_polygon_gdf,
Expand Down Expand Up @@ -1101,7 +1114,7 @@ def build_centroid_connectors(
"Missing maz node file, will use input maz polygon centroid"
)

maz_node_gdf = maz_polygon_gdf["geometry"].representative_centroids()
maz_node_gdf = maz_polygon_gdf["geometry"].centroid
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use representative_point() to force zone centroid to be within the polygon boundary.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ill have to check because my version of geopandas did not have a representative point, I will have to fiddle with environment


# convert to lat-long
maz_polygon_gdf = maz_polygon_gdf.to_crs(self.parameters.standard_crs)
Expand Down Expand Up @@ -1152,7 +1165,8 @@ def build_taz_drive_connector(
# geometries (not reference) - good intersections

taz_good_intersection_df = Roadway.get_nodes_in_zones(
node_two_geometry_df, taz_polygon_df
node_two_geometry_df.drop(columns=["index_left", "index_right"], errors="ignore"),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this? If these two columns exist in the MTC workflow, I'd rather clean up the MTC data before calling this method. We should keep Ranch as generic as possible.

taz_polygon_df.drop(columns=["index_left", "index_right"], errors="ignore")
)

# step 3
Expand Down Expand Up @@ -1419,6 +1433,10 @@ def get_nodes_in_zones(nodes_gdf, zones_gdf):
nodes_gdf: nodes geo data frame, points
zones_gdf: zones geo data frame, polygons
"""

nodes_gdf = nodes_gdf.drop(columns=["index_left", "index_right"], errors="ignore")
zones_gdf = zones_gdf.drop(columns=["index_left", "index_right"], errors="ignore")

polygon_buffer_gdf = zones_gdf.copy()

polygon_buffer_gdf["geometry_buffer"] = polygon_buffer_gdf["geometry"].apply(
Expand Down
5 changes: 4 additions & 1 deletion ranch/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,9 @@ def generate_centroid_connectors_shape(zone_loading_node_df):
columns={"osm_node_id": "u", "model_node_id_x": "A", "model_node_id_y": "B"}
)

if ("A" not in new_cc_gdf.columns ) and ("B" not in new_cc_gdf.columns):
new_cc_gdf = new_cc_gdf.rename(columns={"X": "A", "Y": "B"})
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

X/Y are the coordinates, A/B are the node IDs, what's the meaning of this rename?


new_cc_gdf = new_cc_gdf[
["A", "B", "u", "fromIntersectionId", "shstGeometryId", "id", "geometry"]
]
Expand Down Expand Up @@ -680,7 +683,7 @@ def get_non_near_connectors(all_cc_link_gdf, num_connectors_per_centroid, zone_i
centroid = zone_cc_gdf.c_point.iloc[0]

# if the zone has less than 4 cc, keep all
if len(zone_cc_gdf) <= num_connectors_per_centroid:
if len(zone_cc_gdf) <= 4:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make more sense to change the value to num_connectors_per_centroid than hardcoding?

keep_cc_gdf = keep_cc_gdf.append(zone_cc_gdf, sort=False, ignore_index=True)

# if the zone has more than 4 cc
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
lark-parser
jupyter
pywin32 == 306
notebook
numpy
pandas > 1.0
Expand Down