@@ -411,3 +411,42 @@ def read_nwp_transit_segment_results(nwp_fp: Union[str, PathLike]) -> pd.DataFra
411
411
segments = segments [['line' , 'inode' , 'jnode' , 'seg_seq' , 'loop' , 'boardings' , 'alightings' , 'volume' ]].copy ()
412
412
413
413
return segments
414
+
415
+
416
+ def read_nwp_transit_vehicles (nwp_fp : Union [str , PathLike ]) -> pd .DataFrame :
417
+ """A function to read the transit vehicles from a Network Package file (exported from Emme using the TMG Toolbox)
418
+ into DataFrames.
419
+
420
+ Args:
421
+ nwp_fp (str | PathLike): File path to the network package.
422
+
423
+ Returns:
424
+ pd.DataFrame: DataFrame containing the transit vehicles.
425
+ """
426
+ nwp_fp = Path (nwp_fp )
427
+ if not nwp_fp .exists ():
428
+ raise FileNotFoundError (f'File `{ nwp_fp .as_posix ()} ` not found.' )
429
+
430
+ with zipfile .ZipFile (nwp_fp ) as zf :
431
+ # Get header
432
+ header = None
433
+ for i , line in enumerate (zf .open ('vehicles.202' ), start = 1 ):
434
+ line = line .strip ().decode ('utf-8' )
435
+ if line .startswith ('c' ):
436
+ continue # Skip comment lines
437
+ if line .startswith ('t vehicles' ):
438
+ header = i
439
+
440
+ # Read data
441
+ data_types = {
442
+ 'id' : int , 'description' : str , 'mode' : str , 'fleet_size' : int , 'seated_capacity' : float ,
443
+ 'total_capacity' : float , 'cost_time_coeff' : float , 'cost_distance_coeff' : float , 'energy_time_coeff' : float ,
444
+ 'energy_distance_coeff' : float , 'auto_equivalent' : float
445
+ }
446
+ vehicles = pd .read_csv (
447
+ zf .open ('vehicles.202' ), index_col = 'id' , usecols = data_types .keys (), dtype = data_types , skiprows = header ,
448
+ quotechar = "'" , delim_whitespace = True
449
+ )
450
+ vehicles .index .name = 'veh_id'
451
+
452
+ return vehicles
0 commit comments