@@ -103,6 +103,7 @@ def calculate_facility_type(
103
103
join_gdf ["oneWay" ].fillna ("" , inplace = True )
104
104
join_gdf ["oneWay" ] = join_gdf ["oneWay" ].apply (lambda x : "NA" if x in [None , np .nan , float ('nan' )] else x )
105
105
join_gdf ["oneWay" ] = join_gdf ["oneWay" ].apply (lambda x : str (x ) if type (x ) == bool else x )
106
+ join_gdf ["oneWay" ] = join_gdf ["oneWay" ].apply (lambda x : str (x ) if type (x ) == int else x )
106
107
join_gdf ["oneWay" ] = join_gdf ["oneWay" ].apply (lambda x : x if type (x ) == str else ',' .join (map (str , x )))
107
108
join_gdf ["oneWay_binary" ] = join_gdf ["oneWay" ].apply (lambda x : 0 if "False" in x else 1 )
108
109
@@ -286,6 +287,8 @@ def determine_number_of_lanes(
286
287
"""
287
288
mtc_osm_df = pd .read_csv (mtc_osm_lanes_attributes )
288
289
mtc_osm_df = mtc_osm_df .rename (columns = {"min_lanes" : "osm_min_lanes" , "max_lanes" : "osm_max_lanes" })
290
+ mtc_osm_df .loc [mtc_osm_df ['oneWay' ].str .contains ('False' ), 'osm_min_lanes' ] = np .ceil (mtc_osm_df ['osm_min_lanes' ] / 2 )
291
+ mtc_osm_df .loc [mtc_osm_df ['oneWay' ].str .contains ('False' ), 'osm_max_lanes' ] = np .ceil (mtc_osm_df ['osm_max_lanes' ] / 2 )
289
292
290
293
sj_osm_df = pd .read_csv (sj_osm_lanes_attributes )
291
294
sj_osm_df = sj_osm_df .rename (columns = {'osm_lanes_min' : 'osm_min_lanes' , 'osm_lanes_max' :'osm_max_lanes' })
@@ -1710,7 +1713,7 @@ def roadway_standard_to_mtc_network(
1710
1713
roadway_network .links_df ["assignable" ]
1711
1714
)
1712
1715
1713
- roadway_network = calculate_cntype (roadway_network , parameters )
1716
+ roadway_network = calculate_cntype (roadway_network , parameters , overwrite = True )
1714
1717
roadway_network = calculate_transit (roadway_network , parameters )
1715
1718
roadway_network = calculate_useclass (roadway_network , parameters )
1716
1719
roadway_network = calculate_facility_type (roadway_network , parameters , update_network_variable = True )
@@ -1735,6 +1738,8 @@ def roadway_standard_to_mtc_network(
1735
1738
on = "id"
1736
1739
)
1737
1740
1741
+ roadway_network .links_mtc_df = gpd .GeoDataFrame (roadway_network .links_mtc_df , geometry = roadway_network .links_mtc_df .geometry )
1742
+ roadway_network .nodes_mtc_df = gpd .GeoDataFrame (roadway_network .nodes_mtc_df , geometry = roadway_network .nodes_mtc_df .geometry )
1738
1743
roadway_network .links_mtc_df .crs = roadway_network .crs
1739
1744
roadway_network .nodes_mtc_df .crs = roadway_network .crs
1740
1745
WranglerLogger .info ("Setting Coordinate Reference System to {}" .format (output_proj ))
@@ -1747,9 +1752,13 @@ def roadway_standard_to_mtc_network(
1747
1752
roadway_network .nodes_mtc_df ["Y" ] = roadway_network .nodes_mtc_df .geometry .apply (
1748
1753
lambda g : g .y
1749
1754
)
1755
+ # roadway_network.nodes_mtc_df["pnr"]=roadway_network.nodes_mtc_df["pnr"].fillna(0)
1756
+ WranglerLogger .info ("Setting PNR value and converting it to string" )
1757
+ roadway_network .nodes_mtc_df ["pnr" ] = np .where (roadway_network .nodes_mtc_df ['pnr' ].isin ([0 ,'' ,' ' ]), '0.0' , '1.0' )
1750
1758
1751
1759
# CUBE expect node id to be N
1752
1760
roadway_network .nodes_mtc_df .rename (columns = {"model_node_id" : "N" }, inplace = True )
1761
+ # roadway_network.nodes_mtc_df['model_node_id']=roadway_network.nodes_mtc_df['N']
1753
1762
1754
1763
return roadway_network
1755
1764
@@ -1860,17 +1869,19 @@ def route_properties_gtfs_to_cube(
1860
1869
1861
1870
trip_df ["agency_id" ].fillna ("" , inplace = True )
1862
1871
1872
+ trip_df ['dir_shp_index' ] = trip_df .groupby (["TM2_operator" , "route_id" , "tod_name" ]).cumcount ()
1873
+
1863
1874
trip_df ["NAME" ] = trip_df .apply (
1864
1875
lambda x : str (x .TM2_operator )
1865
1876
+ "_"
1866
1877
+ str (x .route_id )
1867
1878
+ "_"
1868
- + x .tod_name
1879
+ + str ( x .tod_name )
1869
1880
+ "_"
1870
1881
+ "d"
1871
- + str (int (x .direction_id ))
1882
+ + str (int (x .dir_shp_index ))
1872
1883
+ "_s"
1873
- + x .shape_id ,
1884
+ + str ( x .shape_id ),
1874
1885
axis = 1 ,
1875
1886
)
1876
1887
@@ -1929,11 +1940,14 @@ def cube_format(transit_network, row):
1929
1940
s += "\n OPERATOR={}," .format (int (row .TM2_operator ) if ~ math .isnan (row .TM2_operator ) else 99 )
1930
1941
s += '\n SHORTNAME=\" %s",' % (row .route_short_name ,)
1931
1942
s += '\n VEHICLETYPE={},' .format (row .vehtype_num )
1932
- if row .TM2_line_haul_name in ["Light rail" , "Heavy rail" , "Commuter rail" , "Ferry service" ]:
1943
+ if row .TM2_line_haul_name in ["Light rail" , "Heavy rail" , "Commuter rail" , "Ferry service" , "Cable Car" ]:
1933
1944
add_nntime = True
1934
1945
else :
1935
1946
add_nntime = False
1936
- s += "\n N={}" .format (transit_network .shape_gtfs_to_cube (row , add_nntime ))
1947
+ nodes , runtime = transit_network .shape_gtfs_to_cube (row , add_nntime )
1948
+ if add_nntime :
1949
+ s += '\n RUNTIME={},' .format (runtime )
1950
+ s += "\n N={}" .format (nodes )
1937
1951
1938
1952
# TODO: need NNTIME, ACCESS_C
1939
1953
@@ -1952,6 +1966,19 @@ def write_as_cube_lin(
1952
1966
outpath: File location for output cube line file.
1953
1967
1954
1968
"""
1969
+
1970
+ transit_network .feed .trips ['trip_id' ] = transit_network .feed .trips ['trip_id' ].astype (int )
1971
+ transit_network .feed .trips ['shape_id' ] = transit_network .feed .trips ['shape_id' ].astype (int )
1972
+
1973
+ transit_network .feed .stop_times ['trip_id' ] = transit_network .feed .stop_times ['trip_id' ].astype (int )
1974
+ transit_network .feed .stop_times ['stop_id' ] = transit_network .feed .stop_times ['stop_id' ].astype (float ).astype (int )
1975
+
1976
+ transit_network .feed .shapes ['shape_id' ] = transit_network .feed .shapes ['shape_id' ].astype (int )
1977
+
1978
+ transit_network .feed .stops ['stop_id' ] = transit_network .feed .stops ['stop_id' ].astype (float ).astype (int )
1979
+
1980
+ transit_network .feed .frequencies ['trip_id' ] = transit_network .feed .frequencies ['trip_id' ].astype (int )
1981
+
1955
1982
if not outpath :
1956
1983
outpath = os .path .join (parameters .scratch_location ,"outtransit.lin" )
1957
1984
trip_cube_df = route_properties_gtfs_to_cube (transit_network , parameters , outpath )
@@ -2151,7 +2178,9 @@ def _is_express_bus(x):
2151
2178
if (x .route_short_name .startswith ("J" )) | (x .route_short_name .startswith ("Lynx" )):
2152
2179
return 1
2153
2180
if x .agency_name == "SolTrans" :
2154
- if (x .route_short_name in ["80" , "92" , "78" ]) | (x .route_long_name in ["80" , "92" , "78" ]):
2181
+ if ((x .route_short_name in ["80" , "92" , "78" ,"Green" ,"Blue" ,"Red" ]) |
2182
+ (x .route_long_name in ["80" , "92" , "78" ,"Green" ,"Blue" ,"Red" ])
2183
+ ):
2155
2184
return 1
2156
2185
if x .agency_name == "Vine (Napa County)" :
2157
2186
if x .route_short_name in ["29" ]:
0 commit comments