diff --git a/examples/stpaul/ohio_mug/Example.yml b/examples/stpaul/ohio_mug/Example.yml new file mode 100644 index 0000000..283196c --- /dev/null +++ b/examples/stpaul/ohio_mug/Example.yml @@ -0,0 +1,17 @@ +project: Example +tags: '' +dependencies: '' +changes: +- category: Roadway Property Change + facility: + link: + - model_link_id: + - 389369 + properties: + - existing: 0.0 + set: 0.1251 + property: distance + - existing: 2 + set: 3 + property: lanes +valid: false diff --git a/notebooks/Ohio MUG Demonstration.ipynb b/notebooks/Ohio MUG Demonstration.ipynb index 75ad672..3f4f5dc 100644 --- a/notebooks/Ohio MUG Demonstration.ipynb +++ b/notebooks/Ohio MUG Demonstration.ipynb @@ -32,6 +32,16 @@ "from lasso import metcouncil" ] }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "%load_ext autoreload\n", + "%autoreload 2" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -41,7 +51,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -59,12 +69,12 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ - "input_dir = os.path.join(\"C:/\", \"Users\", \"david.ory\", \"documents\", \"GitHub\", \"Lasso\", \"examples\", \"stpaul\")\n", - "lasso_dir = os.path.join(\"C:/\", \"Users\", \"david.ory\", \"documents\", \"GitHub\", \"Lasso\")\n", + "input_dir = os.path.join(\"Z:/Data/Users/Sijia/Met_Council/github/client_met_council_wrangler_utilities\", \"examples\", \"stpaul\")\n", + "lasso_dir = os.path.join(\"Z:/Data/Users/Sijia/Met_Council/github/client_met_council_wrangler_utilities\")\n", "output_dir = input_dir\n", "\n", "stpaul_shape_file = os.path.join(input_dir, \"shape.geojson\")\n", @@ -74,14 +84,14 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "2021-03-11 14:51:37, INFO: Lasso base directory set as: C:/Users\\david.ory\\documents\\GitHub\\Lasso\n" + "2021-03-16 13:53:42, INFO: Lasso base directory set as: Z:/Data/Users/Sijia/Met_Council/github/client_met_council_wrangler_utilities\n" ] } ], @@ -98,27 +108,27 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "2021-03-11 14:51:37, INFO: Reading from following files:\n", - "-C:/Users\\david.ory\\documents\\GitHub\\Lasso\\examples\\stpaul\\link.json\n", - "-C:/Users\\david.ory\\documents\\GitHub\\Lasso\\examples\\stpaul\\node.geojson\n", - "-C:/Users\\david.ory\\documents\\GitHub\\Lasso\\examples\\stpaul\\shape.geojson.\n", - "2021-03-11 14:51:52, INFO: Read 66253 links from C:/Users\\david.ory\\documents\\GitHub\\Lasso\\examples\\stpaul\\link.json\n", - "2021-03-11 14:51:52, INFO: Read 17159 nodes from C:/Users\\david.ory\\documents\\GitHub\\Lasso\\examples\\stpaul\\node.geojson\n", - "2021-03-11 14:51:52, INFO: Read 66253 shapes from C:/Users\\david.ory\\documents\\GitHub\\Lasso\\examples\\stpaul\\shape.geojson\n", - "2021-03-11 14:52:13, INFO: Read in transit feed from: C:/Users\\david.ory\\documents\\GitHub\\Lasso\\examples\\stpaul\n", - "2021-03-11 14:52:13, INFO: Removing calendar.txt from transit network config because file not found\n", - "2021-03-11 14:52:13, INFO: Removing calendar_dates.txt from transit network config because file not found\n", - "2021-03-11 14:52:13, INFO: Removing fare_attributes.txt from transit network config because file not found\n", - "2021-03-11 14:52:13, INFO: Removing fare_rules.txt from transit network config because file not found\n", - "2021-03-11 14:52:13, INFO: Removing transfers.txt from transit network config because file not found\n", - "2021-03-11 14:52:13, INFO: Removing feed_info.txt from transit network config because file not found\n" + "2021-03-16 13:53:42, INFO: Reading from following files:\n", + "-Z:/Data/Users/Sijia/Met_Council/github/client_met_council_wrangler_utilities\\examples\\stpaul\\link.json\n", + "-Z:/Data/Users/Sijia/Met_Council/github/client_met_council_wrangler_utilities\\examples\\stpaul\\node.geojson\n", + "-Z:/Data/Users/Sijia/Met_Council/github/client_met_council_wrangler_utilities\\examples\\stpaul\\shape.geojson.\n", + "2021-03-16 13:53:53, INFO: Read 66253 links from Z:/Data/Users/Sijia/Met_Council/github/client_met_council_wrangler_utilities\\examples\\stpaul\\link.json\n", + "2021-03-16 13:53:53, INFO: Read 17159 nodes from Z:/Data/Users/Sijia/Met_Council/github/client_met_council_wrangler_utilities\\examples\\stpaul\\node.geojson\n", + "2021-03-16 13:53:53, INFO: Read 66253 shapes from Z:/Data/Users/Sijia/Met_Council/github/client_met_council_wrangler_utilities\\examples\\stpaul\\shape.geojson\n", + "2021-03-16 13:54:05, INFO: Read in transit feed from: Z:/Data/Users/Sijia/Met_Council/github/client_met_council_wrangler_utilities\\examples\\stpaul\n", + "2021-03-16 13:54:05, INFO: Removing calendar.txt from transit network config because file not found\n", + "2021-03-16 13:54:05, INFO: Removing calendar_dates.txt from transit network config because file not found\n", + "2021-03-16 13:54:05, INFO: Removing fare_attributes.txt from transit network config because file not found\n", + "2021-03-16 13:54:05, INFO: Removing fare_rules.txt from transit network config because file not found\n", + "2021-03-16 13:54:05, INFO: Removing transfers.txt from transit network config because file not found\n", + "2021-03-16 13:54:05, INFO: Removing feed_info.txt from transit network config because file not found\n" ] } ], @@ -135,7 +145,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -150,7 +160,7 @@ " dtype='object')" ] }, - "execution_count": 6, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -169,14 +179,14 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "2021-03-11 14:52:13, INFO: Creating Scenario\n" + "2021-03-16 13:54:05, INFO: Creating Scenario\n" ] } ], @@ -193,69 +203,53 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "2021-03-11 14:52:16, INFO: Lasso base directory set as: C:\\Users\\david.ory\\Documents\\GitHub\\Lasso\n", - "2021-03-11 14:52:16, INFO: Calculating Centroid Connector and adding as roadway network variable: centroidconnect\n", - "2021-03-11 14:52:16, INFO: Finished calculating centroid connector variable: centroidconnect\n", - "2021-03-11 14:52:16, INFO: Renaming roadway attributes to be consistent with what metcouncil's model is expecting\n", - "2021-03-11 14:52:16, INFO: Didn't detect managed lanes in network.\n", - "2021-03-11 14:52:16, INFO: Creating calculated roadway variables.\n", - "2021-03-11 14:52:16, INFO: Calculating Area Type from Spatial Data and adding as roadway network variable: area_type\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "c:\\users\\david.ory\\documents\\github\\lasso\\lasso\\roadway.py:423: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation.\n", - "\n", - " centroids_gdf[\"geometry\"] = centroids_gdf[\"geometry\"].centroid\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2021-03-11 14:52:20, INFO: Finished Calculating Area Type from Spatial Data into variable: area_type\n", - "2021-03-11 14:52:20, INFO: Adding roadway network variable for county using a spatial join with: C:\\Users\\david.ory\\Documents\\GitHub\\Lasso\\metcouncil_data\\county\\cb_2017_us_county_5m.shp\n" + "2021-03-16 13:54:07, INFO: Lasso base directory set as: z:\\Data\\Users\\Sijia\\Met_Council\\github\\client_met_council_wrangler_utilities\n", + "2021-03-16 13:54:07, INFO: Calculating Centroid Connector and adding as roadway network variable: centroidconnect\n", + "2021-03-16 13:54:07, INFO: Finished calculating centroid connector variable: centroidconnect\n", + "2021-03-16 13:54:07, INFO: Renaming roadway attributes to be consistent with what metcouncil's model is expecting\n", + "2021-03-16 13:54:07, INFO: Didn't detect managed lanes in network.\n", + "2021-03-16 13:54:07, INFO: Creating calculated roadway variables.\n", + "2021-03-16 13:54:07, INFO: Calculating Area Type from Spatial Data and adding as roadway network variable: area_type\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "c:\\users\\david.ory\\documents\\github\\lasso\\lasso\\roadway.py:288: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation.\n", - "\n", - " centroids_gdf[\"geometry\"] = centroids_gdf[\"geometry\"].centroid\n" + "C:\\Users\\wangs1\\.conda\\envs\\lasso\\lib\\site-packages\\geopandas\\tools\\sjoin.py:56: UserWarning: CRS of frames being joined does not match!(4326 != {'init': 'epsg:4326', 'no_defs': True})\n", + " '(%s != %s)' % (left_df.crs, right_df.crs))\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ - "2021-03-11 14:52:24, INFO: Finished Calculating county variable: county\n", - "2021-03-11 14:52:24, INFO: Calculating MPO as roadway network variable: mpo\n", - "2021-03-11 14:52:24, INFO: Finished calculating MPO variable: mpo\n", - "2021-03-11 14:52:24, INFO: Adding Counts\n", - "2021-03-11 14:52:24, INFO: Adding Variable AADT using Shared Streets Reference from C:\\Users\\david.ory\\Documents\\GitHub\\Lasso\\metcouncil_data\\count_mn\\mn_count_ShSt_API_match.csv\n", - "2021-03-11 14:52:24, INFO: Added variable: AADT using Shared Streets Reference\n", - "2021-03-11 14:52:24, INFO: Adding Variable AADT using Shared Streets Reference from C:\\Users\\david.ory\\Documents\\GitHub\\Lasso\\metcouncil_data\\Wisconsin_Lanes_Counts_Median\\wi_count_ShSt_API_match.csv\n", - "2021-03-11 14:52:24, INFO: Added variable: AADT using Shared Streets Reference\n", - "2021-03-11 14:52:24, INFO: Finished adding counts variable: AADT\n", - "2021-03-11 14:52:24, INFO: Finished creating ML lanes variable: ML_lanes\n", - "2021-03-11 14:52:24, INFO: Finished creating hov corridor variable: segment_id\n", - "2021-03-11 14:52:24, INFO: Finished creating managed variable: managed\n", - "2021-03-11 14:52:24, INFO: Overwriting existing distance Variable 'distance' already in network\n", - "2021-03-11 14:52:25, INFO: Calculating distance for all links\n", - "2021-03-11 14:52:25, INFO: Filling nan for network from network wrangler\n", - "2021-03-11 14:52:25, INFO: Splitting variables by time period and category\n", - "2021-03-11 14:52:26, WARNING: Specified variable to split: ML_lanes not in network variables: Index(['model_link_id', 'osm_link_id', 'shstReferenceId', 'shstGeometryId',\n", + "2021-03-16 13:54:08, INFO: Finished Calculating Area Type from Spatial Data into variable: area_type\n", + "2021-03-16 13:54:08, INFO: Adding roadway network variable for county using a spatial join with: z:\\Data\\Users\\Sijia\\Met_Council\\github\\client_met_council_wrangler_utilities\\metcouncil_data\\county\\cb_2017_us_county_5m.shp\n", + "2021-03-16 13:54:10, INFO: Finished Calculating county variable: county\n", + "2021-03-16 13:54:10, INFO: Calculating MPO as roadway network variable: mpo\n", + "2021-03-16 13:54:10, INFO: Finished calculating MPO variable: mpo\n", + "2021-03-16 13:54:10, INFO: Adding Counts\n", + "2021-03-16 13:54:10, INFO: Adding Variable AADT using Shared Streets Reference from z:\\Data\\Users\\Sijia\\Met_Council\\github\\client_met_council_wrangler_utilities\\metcouncil_data\\count_mn\\mn_count_ShSt_API_match.csv\n", + "2021-03-16 13:54:10, INFO: Added variable: AADT using Shared Streets Reference\n", + "2021-03-16 13:54:10, INFO: Adding Variable AADT using Shared Streets Reference from z:\\Data\\Users\\Sijia\\Met_Council\\github\\client_met_council_wrangler_utilities\\metcouncil_data\\Wisconsin_Lanes_Counts_Median\\wi_count_ShSt_API_match.csv\n", + "2021-03-16 13:54:10, INFO: Added variable: AADT using Shared Streets Reference\n", + "2021-03-16 13:54:10, INFO: Finished adding counts variable: AADT\n", + "2021-03-16 13:54:10, INFO: Finished creating ML lanes variable: ML_lanes\n", + "2021-03-16 13:54:10, INFO: Finished creating hov corridor variable: segment_id\n", + "2021-03-16 13:54:10, INFO: Finished creating managed variable: managed\n", + "2021-03-16 13:54:10, INFO: Overwriting existing distance Variable 'distance' already in network\n", + "2021-03-16 13:54:10, INFO: Calculating distance for all links\n", + "2021-03-16 13:54:10, INFO: Filling nan for network from network wrangler\n", + "2021-03-16 13:54:10, INFO: Splitting variables by time period and category\n", + "2021-03-16 13:54:10, WARNING: Specified variable to split: ML_lanes not in network variables: Index(['model_link_id', 'osm_link_id', 'shstReferenceId', 'shstGeometryId',\n", " 'shape_id', 'u', 'v', 'A', 'B', 'locationReferences', 'distance',\n", " 'roadway', 'name', 'ref', 'bridge', 'tunnel', 'width', 'max_speed',\n", " 'bike_facility', 'drive_access', 'walk_access', 'bike_access',\n", @@ -268,8 +262,8 @@ " 'ttime_assert_PM', 'ttime_assert_NT', 'lanes_AM', 'lanes_MD',\n", " 'lanes_PM', 'lanes_NT'],\n", " dtype='object'). Returning 0.\n", - "2021-03-11 14:52:26, INFO: Converting variable type to MetCouncil standard\n", - "2021-03-11 14:52:26, INFO: Setting Coordinate Reference System to EPSG 26915\n" + "2021-03-16 13:54:11, INFO: Converting variable type to MetCouncil standard\n", + "2021-03-16 13:54:11, INFO: Setting Coordinate Reference System to EPSG 26915\n" ] } ], @@ -283,7 +277,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -298,7 +292,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -315,25 +309,34 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "2021-03-11 14:52:29, INFO: No base transit network.\n", - "2021-03-11 14:52:29, INFO: No transit changes given or processed.\n", - "2021-03-11 14:52:29, INFO: Reading logfile: C:/Users\\david.ory\\documents\\GitHub\\Lasso\\examples\\stpaul\\cube\\st_paul_example.log\n", - "2021-03-11 14:52:29, INFO: Processed 0 Node lines and 1 Link lines\n", - "2021-03-11 14:52:29, INFO: Lasso base directory set as: C:\\Users\\david.ory\\Documents\\GitHub\\Lasso\n", - "2021-03-11 14:52:29, INFO: Evaluating compatibility between roadway network changes and base network. Not evaluating deletions.\n", - "2021-03-11 14:52:29, INFO: Evaluating project changes.\n", - "2021-03-11 14:52:29, WARNING: The following attributes are specified in the changes but do not exist in the base network: ['OPERATION_final']\n", - "2021-03-11 14:52:29, INFO: Lasso base directory set as: C:\\Users\\david.ory\\Documents\\GitHub\\Lasso\n", - "2021-03-11 14:52:29, INFO: Lasso base directory set as: C:\\Users\\david.ory\\Documents\\GitHub\\Lasso\n", - "2021-03-11 14:52:29, INFO: Lasso base directory set as: C:\\Users\\david.ory\\Documents\\GitHub\\Lasso\n", - "2021-03-11 14:52:29, INFO: Lasso base directory set as: C:\\Users\\david.ory\\Documents\\GitHub\\Lasso\n" + "2021-03-16 13:54:12, INFO: No base transit network.\n", + "2021-03-16 13:54:12, INFO: No transit changes given or processed.\n", + "2021-03-16 13:54:12, INFO: Reading logfile: Z:/Data/Users/Sijia/Met_Council/github/client_met_council_wrangler_utilities\\examples\\stpaul\\cube\\st_paul_example.log\n", + "2021-03-16 13:54:12, INFO: Processed 0 Node lines and 1 Link lines\n", + "2021-03-16 13:54:12, INFO: Lasso base directory set as: z:\\Data\\Users\\Sijia\\Met_Council\\github\\client_met_council_wrangler_utilities\n", + "2021-03-16 13:54:12, INFO: Evaluating compatibility between roadway network changes and base network. Not evaluating deletions.\n", + "2021-03-16 13:54:12, INFO: Evaluating project changes.\n", + "2021-03-16 13:54:12, WARNING: The following attributes are specified in the changes but do not exist in the base network: ['OPERATION_final']\n", + "2021-03-16 13:54:12, INFO: Lasso base directory set as: z:\\Data\\Users\\Sijia\\Met_Council\\github\\client_met_council_wrangler_utilities\n", + "2021-03-16 13:54:12, INFO: Lasso base directory set as: z:\\Data\\Users\\Sijia\\Met_Council\\github\\client_met_council_wrangler_utilities\n", + "2021-03-16 13:54:12, INFO: Lasso base directory set as: z:\\Data\\Users\\Sijia\\Met_Council\\github\\client_met_council_wrangler_utilities\n", + "2021-03-16 13:54:12, INFO: Lasso base directory set as: z:\\Data\\Users\\Sijia\\Met_Council\\github\\client_met_council_wrangler_utilities\n", + "2021-03-16 13:54:12, INFO: Lasso base directory set as: z:\\Data\\Users\\Sijia\\Met_Council\\github\\client_met_council_wrangler_utilities\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "z:\\data\\users\\sijia\\met_council\\github\\client_met_council_wrangler_utilities\\lasso\\project.py:613: RuntimeWarning: divide by zero encountered in double_scalars\n", + " / base_row[col].astype(float)\n" ] } ], @@ -347,19 +350,19 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "2021-03-11 14:52:29, INFO: Wrote project card to: C:/Users\\david.ory\\documents\\GitHub\\Lasso\\examples\\stpaul\\ohio_mug\\Example.yml\n" + "2021-03-16 13:54:12, INFO: Wrote project card to: Z:/Data/Users/Sijia/Met_Council/github/client_met_council_wrangler_utilities\\examples\\stpaul\\ohio_mug\\Example.yml\n" ] } ], "source": [ - "# project.write_project_card(os.path.join(output_dir, \"ohio_mug\", \"Example.yml\"))" + "project.write_project_card(os.path.join(output_dir, \"ohio_mug\", \"Example.yml\"))" ] }, { @@ -371,16 +374,27 @@ }, { "cell_type": "code", - "execution_count": 13, - "metadata": {}, + "execution_count": 16, + "metadata": { + "scrolled": true + }, "outputs": [], "source": [ - "# build_scenario = Scenario.create_scenario(base_scenario = {\"road_net\": roadway_net, \"transit_net\": transit_net},\n", - "# card_directory = os.path.join(lasso_dir, \"examples\", \"stpaul\", \"ohio_mug\"),\n", - "# tags = ['checked'],\n", + "#build_scenario = Scenario.create_scenario(base_scenario = {\"road_net\": roadway_net, \"transit_net\": transit_net},\n", + "# card_directory = os.path.join(lasso_dir, \"examples\", \"stpaul\", \"ohio_mug\"),\n", + "# #tags = ['checked'],\n", "# validate_project_cards = False)" ] }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [], + "source": [ + "#build_scenario.apply_all_projects()" + ] + }, { "cell_type": "code", "execution_count": 14, @@ -390,7 +404,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "2021-03-11 14:52:29, INFO: Creating Scenario\n" + "2021-03-16 13:54:13, INFO: Creating Scenario\n" ] } ], @@ -407,37 +421,21 @@ "name": "stdout", "output_type": "stream", "text": [ - "2021-03-11 14:52:29, INFO: Applying Example\n", - "2021-03-11 14:52:29, INFO: Applying Example\n", - "2021-03-11 14:52:29, INFO: Applying Project to Roadway Network: Example\n" + "2021-03-16 13:54:13, INFO: Applying Example\n", + "2021-03-16 13:54:13, INFO: Applying Example\n", + "2021-03-16 13:54:13, INFO: Applying Project to Roadway Network: Example\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "C:\\Users\\david.ory\\anaconda3\\envs\\lasso_x\\lib\\site-packages\\geopandas\\geodataframe.py:853: SettingWithCopyWarning: \n", + "z:\\data\\users\\sijia\\met_council\\github\\client_met_council_wrangler_utilities\\lasso\\src\\network-wrangler\\network_wrangler\\roadwaynetwork.py:870: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", - "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", - " super(GeoDataFrame, self).__setitem__(key, value)\n" - ] - }, - { - "ename": "KeyError", - "evalue": "'change'", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mbuild_scenario\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mapply_project\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mproject\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcard_data\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[1;32mc:\\users\\david.ory\\documents\\github\\network_wrangler\\network_wrangler\\scenario.py\u001b[0m in \u001b[0;36mapply_project\u001b[1;34m(self, p)\u001b[0m\n\u001b[0;32m 531\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mpc\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mp\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"changes\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 532\u001b[0m \u001b[0mpc\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"project\"\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mp\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"project\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 533\u001b[1;33m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mapply_project\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpc\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 534\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 535\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32mc:\\users\\david.ory\\documents\\github\\network_wrangler\\network_wrangler\\scenario.py\u001b[0m in \u001b[0;36mapply_project\u001b[1;34m(self, p)\u001b[0m\n\u001b[0;32m 537\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mroad_net\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 538\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;34m\"Missing Roadway Network\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 539\u001b[1;33m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mroad_net\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mapply\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mp\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 540\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mp\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"category\"\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mProjectCard\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mTRANSIT_CATEGORIES\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 541\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtransit_net\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32mc:\\users\\david.ory\\documents\\github\\network_wrangler\\network_wrangler\\roadwaynetwork.py\u001b[0m in \u001b[0;36mapply\u001b[1;34m(self, project_card_dictionary)\u001b[0m\n\u001b[0;32m 1333\u001b[0m \u001b[0m_apply_individual_change\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mproject_dictionary\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1334\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1335\u001b[1;33m \u001b[0m_apply_individual_change\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mproject_card_dictionary\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 1336\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1337\u001b[0m def apply_python_calculation(\n", - "\u001b[1;32mc:\\users\\david.ory\\documents\\github\\network_wrangler\\network_wrangler\\roadwaynetwork.py\u001b[0m in \u001b[0;36m_apply_individual_change\u001b[1;34m(project_dictionary)\u001b[0m\n\u001b[0;32m 1309\u001b[0m self.apply_roadway_feature_change(\n\u001b[0;32m 1310\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mselect_roadway_features\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mproject_dictionary\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"facility\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1311\u001b[1;33m \u001b[0mproject_dictionary\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"properties\"\u001b[0m\u001b[1;33m]\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 1312\u001b[0m )\n\u001b[0;32m 1313\u001b[0m \u001b[1;32melif\u001b[0m \u001b[0mproject_dictionary\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"category\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlower\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;34m\"parallel managed lanes\"\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32mc:\\users\\david.ory\\documents\\github\\network_wrangler\\network_wrangler\\roadwaynetwork.py\u001b[0m in \u001b[0;36mapply_roadway_feature_change\u001b[1;34m(self, link_idx, properties, in_place)\u001b[0m\n\u001b[0;32m 1387\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1388\u001b[0m self.links_df.loc[link_idx, attribute] = (\n\u001b[1;32m-> 1389\u001b[1;33m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlinks_df\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mloc\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mlink_idx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mattribute\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mp\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"change\"\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 1390\u001b[0m )\n\u001b[0;32m 1391\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mKeyError\u001b[0m: 'change'" + "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", + " candidate_links[\"i\"] = 0\n" ] } ], @@ -447,13 +445,70 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['Example']" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "build_scenario.applied_projects" ] }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'project': 'Example',\n", + " 'changes': [{'category': 'Roadway Property Change',\n", + " 'facility': {'link': [{'model_link_id': [389369]}]},\n", + " 'properties': [{'existing': 0.0, 'set': 0.1251, 'property': 'distance'},\n", + " {'existing': 2, 'set': 3, 'property': 'lanes'}],\n", + " 'project': 'Example'}]}" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "project.card_data" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "7588 3\n", + "Name: lanes, dtype: int64" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "build_scenario.road_net.links_df[build_scenario.road_net.links_df.model_link_id == 389369].lanes" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -463,19 +518,111 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2021-03-15 18:21:47, INFO: Lasso base directory set as: z:\\Data\\Users\\Sijia\\Met_Council\\github\\client_met_council_wrangler_utilities\n", + "2021-03-15 18:21:47, INFO: Renaming roadway attributes to be consistent with what metcouncil's model is expecting\n", + "2021-03-15 18:21:47, INFO: Didn't detect managed lanes in network.\n", + "2021-03-15 18:21:47, INFO: Creating calculated roadway variables.\n", + "2021-03-15 18:21:47, INFO: Calculating Area Type from Spatial Data and adding as roadway network variable: area_type\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\wangs1\\.conda\\envs\\lasso\\lib\\site-packages\\geopandas\\tools\\sjoin.py:56: UserWarning: CRS of frames being joined does not match!(4326 != {'init': 'epsg:4326', 'no_defs': True})\n", + " '(%s != %s)' % (left_df.crs, right_df.crs))\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2021-03-15 18:21:56, INFO: Finished Calculating Area Type from Spatial Data into variable: area_type\n", + "2021-03-15 18:21:56, INFO: Adding roadway network variable for county using a spatial join with: z:\\Data\\Users\\Sijia\\Met_Council\\github\\client_met_council_wrangler_utilities\\metcouncil_data\\county\\cb_2017_us_county_5m.shp\n", + "2021-03-15 18:22:01, INFO: Finished Calculating county variable: county\n", + "2021-03-15 18:22:01, INFO: Calculating MPO as roadway network variable: mpo\n", + "2021-03-15 18:22:01, INFO: Finished calculating MPO variable: mpo\n", + "2021-03-15 18:22:01, INFO: Adding Counts\n", + "2021-03-15 18:22:01, INFO: Adding Variable AADT using Shared Streets Reference from z:\\Data\\Users\\Sijia\\Met_Council\\github\\client_met_council_wrangler_utilities\\metcouncil_data\\count_mn\\mn_count_ShSt_API_match.csv\n", + "2021-03-15 18:22:02, INFO: Added variable: AADT using Shared Streets Reference\n", + "2021-03-15 18:22:02, INFO: Adding Variable AADT using Shared Streets Reference from z:\\Data\\Users\\Sijia\\Met_Council\\github\\client_met_council_wrangler_utilities\\metcouncil_data\\Wisconsin_Lanes_Counts_Median\\wi_count_ShSt_API_match.csv\n", + "2021-03-15 18:22:02, INFO: Added variable: AADT using Shared Streets Reference\n", + "2021-03-15 18:22:02, INFO: Finished adding counts variable: AADT\n", + "2021-03-15 18:22:02, INFO: Finished creating ML lanes variable: ML_lanes\n", + "2021-03-15 18:22:02, INFO: Finished creating hov corridor variable: segment_id\n", + "2021-03-15 18:22:02, INFO: Finished creating managed variable: managed\n", + "2021-03-15 18:22:02, INFO: Overwriting existing distance Variable 'distance' already in network\n", + "2021-03-15 18:22:04, INFO: Calculating distance for all links\n", + "2021-03-15 18:22:04, INFO: Filling nan for network from network wrangler\n", + "2021-03-15 18:22:05, INFO: Splitting variables by time period and category\n", + "2021-03-15 18:22:06, WARNING: Specified variable to split: ML_lanes not in network variables: Index(['model_link_id', 'osm_link_id', 'shstReferenceId', 'shstGeometryId',\n", + " 'shape_id', 'u', 'v', 'A', 'B', 'locationReferences', 'distance',\n", + " 'roadway', 'name', 'ref', 'bridge', 'tunnel', 'width', 'max_speed',\n", + " 'bike_facility', 'drive_access', 'walk_access', 'bike_access',\n", + " 'truck_access', 'bus_only', 'rail_only', 'lanes', 'access', 'price',\n", + " 'trn_priority', 'ttime_assert', 'geometry', 'area_type', 'county',\n", + " 'mpo', 'AADT', 'count_AM', 'count_MD', 'count_PM', 'count_NT',\n", + " 'count_daily', 'count_year', 'segment_id', 'managed', 'trn_priority_AM',\n", + " 'trn_priority_MD', 'trn_priority_PM', 'trn_priority_NT',\n", + " 'ttime_assert_AM', 'ttime_assert_MD', 'ttime_assert_PM',\n", + " 'ttime_assert_NT', 'lanes_AM', 'lanes_MD', 'lanes_PM', 'lanes_NT'],\n", + " dtype='object'). Returning 0.\n", + "2021-03-15 18:22:07, INFO: Converting variable type to MetCouncil standard\n", + "2021-03-15 18:22:07, INFO: Setting Coordinate Reference System to EPSG 26915\n" + ] + } + ], "source": [ - "model_road_net = ModelRoadwayNetwork.from_RoadwayNetwork(edit_scenario.road_net)\n", + "model_road_net = ModelRoadwayNetwork.from_RoadwayNetwork(build_scenario.road_net)\n", "model_road_net.roadway_standard_to_met_council_network()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "7588 3\n", + "Name: lanes_AM, dtype: int32" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "model_road_net.links_metcouncil_df[model_road_net.links_metcouncil_df.model_link_id == 389369][\"lanes_AM\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2021-03-15 18:22:56, INFO: Starting fixed width conversion\n", + "2021-03-15 18:24:25, INFO: Writing out link database\n", + "2021-03-15 18:24:28, INFO: Writing out link header and width ----\n", + "2021-03-15 18:24:28, INFO: Starting fixed width conversion\n", + "2021-03-15 18:24:31, INFO: Writing out node database\n", + "2021-03-15 18:24:31, INFO: Writing out node header and width\n" + ] + } + ], "source": [ "model_road_net.write_roadway_as_fixedwidth(\n", " output_link_txt = os.path.join(output_dir, \"links.txt\"),\n", @@ -489,9 +636,9 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "lasso", "language": "python", - "name": "python3" + "name": "lasso" }, "language_info": { "codemirror_mode": { @@ -503,7 +650,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.7" + "version": "3.7.4" } }, "nbformat": 4,