-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create 02-BCM_ApplyTransitProjectCards.ipynb
Added Yue's clean script to add transit project cards
- Loading branch information
1 parent
c9c7495
commit 60052ac
Showing
1 changed file
with
278 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,278 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"import sys\n", | ||
"import yaml\n", | ||
"\n", | ||
"import numpy as np\n", | ||
"import pandas as pd\n", | ||
"\n", | ||
"from network_wrangler import RoadwayNetwork\n", | ||
"from network_wrangler import TransitNetwork\n", | ||
"from network_wrangler import ProjectCard\n", | ||
"from network_wrangler import Scenario\n", | ||
"from network_wrangler import WranglerLogger\n", | ||
"\n", | ||
"from lasso import ModelRoadwayNetwork\n", | ||
"from lasso import StandardTransit\n", | ||
"from lasso import Parameters\n", | ||
"from lasso import mtc\n", | ||
"from lasso import util\n", | ||
"\n", | ||
"from lasso import Project\n", | ||
"\n", | ||
"from lasso import bicounty\n", | ||
"\n", | ||
"import pickle" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"%load_ext autoreload\n", | ||
"%autoreload 2" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import logging\n", | ||
"logger = logging.getLogger(\"WranglerLogger\")\n", | ||
"logger.setLevel(logging.INFO)" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Remote I/O" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"root_dir = \"\"\n", | ||
"input_dir = os.path.join(root_dir, 'data', 'processed', 'version_03')\n", | ||
"output_dir = os.path.join(root_dir, 'data', 'processed', 'version_04')\n", | ||
"lasso_dir = os.path.join(f\"{root_dir}/software/Lasso\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"parameters = Parameters(lasso_base_dir = lasso_dir)" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Load Scenario" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"pickle_file_name = f\"{input_dir}/version_03_scenario.pickle\"\n", | ||
"curr_scenario = pickle.load(open(pickle_file_name, 'rb'))" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Make Travel Model Network" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"model_net = ModelRoadwayNetwork.from_RoadwayNetwork(\n", | ||
" roadway_network_object = curr_scenario.road_net, \n", | ||
" parameters = parameters\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"model_net.nodes_mtc_df = model_net.nodes_df.copy()\n", | ||
"model_net.links_mtc_df = model_net.links_df.copy()" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Write to disk" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Write model network as geopackage" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# MODEL_ROADWAY_LINK_VARIABLES = [\n", | ||
"# 'A','B','model_link_id','shstGeometryId','name','roadway', # IDs\n", | ||
"# 'ft','assignable','cntype','distance','county', # Misc attributes\n", | ||
"# 'bike_access','drive_access','walk_access','rail_only','bus_only','transit', # Mode attributes\n", | ||
"# 'managed','tollbooth','tollseg','segment_id', # Managed roadway\n", | ||
"# 'lanes_EA','lanes_AM','lanes_MD','lanes_PM','lanes_EV', # Lanes\n", | ||
"# 'useclass_EA','useclass_AM','useclass_MD','useclass_PM','useclass_EV', # Use classes\n", | ||
"# 'nmt2010', 'nmt2020', # bicounty nm variable \n", | ||
"# 'geometry' # geometry\n", | ||
"# ]\n", | ||
"\n", | ||
"# MODEL_ROADWAY_NODE_VARIABLES = [\n", | ||
"# 'N','osm_node_id','tap_id', # IDs\n", | ||
"# 'county', # Misc attributes\n", | ||
"# 'bike_access','drive_access','walk_access','rail_only','farezone', 'pnr', # Mode attributes\n", | ||
"# 'geometry' # geometry\n", | ||
"# ]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# model_net.write_roadway_as_shp(\n", | ||
"# output_dir= os.path.join(output_dir, 'model_networks', 'geopackages'),\n", | ||
"# link_output_variables = MODEL_ROADWAY_LINK_VARIABLES,\n", | ||
"# node_output_variables = MODEL_ROADWAY_NODE_VARIABLES,\n", | ||
"# output_gpkg = 'model_net.gpkg',\n", | ||
"# output_link_gpkg_layer = 'roadway_links',\n", | ||
"# output_node_gpkg_layer = 'roadway_nodes',\n", | ||
"# #output_gpkg_link_filter = args.gpkg_link_filter\n", | ||
"# )" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Write model network for Cube" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"model_net.write_roadway_as_fixedwidth(\n", | ||
" output_dir = os.path.join(output_dir, 'model_networks'),\n", | ||
" output_link_txt = 'links.txt',\n", | ||
" output_node_txt = 'nodes.txt',\n", | ||
" output_link_header_width_txt = 'links_header_width.txt',\n", | ||
" output_node_header_width_txt = 'nodes_header_width.txt',\n", | ||
" output_cube_network_script = 'make_complete_network_from_fixed_width_file.s',\n", | ||
" #drive_only = True\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### write pickle file" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"working_scenario_filename = os.path.join(output_dir, 'scenario_2020.pickle')\n", | ||
"pickle.dump(curr_scenario, open(working_scenario_filename, 'wb'))" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### write to standard format" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# model_net.write(path = os.path.join(output_dir, 'standard_networks'))" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3.7.12 ('bicounty')", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.7.12" | ||
}, | ||
"vscode": { | ||
"interpreter": { | ||
"hash": "e0dd45cdd72f7ee8b001e53dc4a07864935ca72b45255f9ee986f16092d7a114" | ||
} | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |