Skip to content

Commit

Permalink
Updated Notebook to apply transit project card and renamed to 01
Browse files Browse the repository at this point in the history
  • Loading branch information
jawadmhoque committed Mar 11, 2024
1 parent 5565e2b commit 96a9961
Show file tree
Hide file tree
Showing 2 changed files with 197 additions and 278 deletions.
197 changes: 197 additions & 0 deletions scripts/01-BCM_ApplyTransitProjectCards.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import sys\n",
"import pickle\n",
"from pyproj import CRS\n",
"import pandas as pd\n",
"import geopandas as gpd\n",
"\n",
"from network_wrangler import RoadwayNetwork\n",
"from network_wrangler import TransitNetwork\n",
"from network_wrangler import Scenario\n",
"from network_wrangler import WranglerLogger\n",
"from network_wrangler import ProjectCard\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",
"%load_ext autoreload\n",
"%autoreload 2\n",
"\n"
]
},
{
"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": [
"pickle_dir = \"../../\" #Set to directory where the pickle files are stored\n",
"card_dir = \"../../ProjectCards\"#Set to directory where the cards are stored\n",
"transit_dir = \"../../Transit\"\n",
"lasso_dir = '..'\n",
"transit_project_card_dir = os.path.join(card_dir, \"transit\")\n",
"highway_project_card_dir = os.path.join(card_dir, '2035','1-2')\n",
"\n",
"parameters = Parameters(lasso_base_dir = lasso_dir)\n"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Load Scenario"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pickle_file_name = os.path.join(pickle_dir, \"scenario_pre_2020.pickle\")\n",
"curr_scenario = pickle.load(open(pickle_file_name, 'rb'))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Step 01: Apply Associal Highway Project Cards"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"step1_version_04_scenario = Scenario.create_scenario(\n",
" base_scenario = curr_scenario,\n",
" card_directory = highway_project_card_dir,\n",
" project_cards_list=[], \n",
" validate_project_cards=False\n",
")\n",
"\n",
"step1_version_04_scenario.apply_all_projects()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"step1_version_04_scenario.road_net.links_df = gpd.GeoDataFrame(step1_version_04_scenario.road_net.links_df, geometry=step1_version_04_scenario.road_net.links_df.geometry)\n",
"step1_version_04_scenario.road_net.nodes_df = gpd.GeoDataFrame(step1_version_04_scenario.road_net.nodes_df, geometry=step1_version_04_scenario.road_net.nodes_df.geometry)\n",
"step1_version_04_scenario.transit_net.set_roadnet(step1_version_04_scenario.road_net, validate_consistency=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Step 02: Apply Transit Project Cards"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"step2_version_04_scenario = Scenario.create_scenario(\n",
" base_scenario = step1_version_04_scenario,\n",
" card_directory = transit_project_card_dir,\n",
" project_cards_list=[],\n",
" validate_project_cards=False\n",
")\n",
"step2_version_04_scenario.apply_all_projects()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# in case any transit shapes are broken because of the roadway network changes\n",
"step2_version_04_scenario.update_transit_net_with_new_road_net()"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Write model network for Cube"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"standard_transit_net = StandardTransit.fromTransitNetwork(step2_version_04_scenario.transit_net, parameters=parameters)\n",
"mtc.write_as_cube_lin(standard_transit_net, parameters, outpath = os.path.join(transit_dir, \"2035\", \"transit.lin\"))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.9.7 ('base')",
"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.9.7"
},
"vscode": {
"interpreter": {
"hash": "ad2bdc8ecc057115af97d19610ffacc2b4e99fae6737bb82f5d7fb13d2f2c186"
}
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading

0 comments on commit 96a9961

Please sign in to comment.