3.3. Writing data: CSV¶
Available as a jupyter notebook or wiki page.
Let's read in a sample MATSim network into GeNet's Network
object.
In [1]:
Copied!
import os
from genet import read_matsim
path_to_matsim_network = "example_data/pt2matsim_network"
network = os.path.join(path_to_matsim_network, "network.xml")
schedule = os.path.join(path_to_matsim_network, "schedule.xml")
vehicles = os.path.join(path_to_matsim_network, "vehicles.xml")
n = read_matsim(
path_to_network=network, epsg="epsg:27700", path_to_schedule=schedule, path_to_vehicles=vehicles
)
# you don't need to read the vehicles file, but doing so ensures all vehicles
# in the schedule are of the expected type and the definition of the vehicle
# is preserved
n.print()
import os
from genet import read_matsim
path_to_matsim_network = "example_data/pt2matsim_network"
network = os.path.join(path_to_matsim_network, "network.xml")
schedule = os.path.join(path_to_matsim_network, "schedule.xml")
vehicles = os.path.join(path_to_matsim_network, "vehicles.xml")
n = read_matsim(
path_to_network=network, epsg="epsg:27700", path_to_schedule=schedule, path_to_vehicles=vehicles
)
# you don't need to read the vehicles file, but doing so ensures all vehicles
# in the schedule are of the expected type and the definition of the vehicle
# is preserved
n.print()
Graph info: Name: Type: MultiDiGraph Number of nodes: 1662 Number of edges: 3166 Average in degree: 1.9049 Average out degree: 1.9049 Schedule info: Schedule: Number of services: 9 Number of routes: 68 Number of stops: 118
You can export the genet.Network
and the Schedule
(if applicable) to CSV.
In [2]:
Copied!
n.write_to_csv("example_data/outputs/csv")
n.write_to_csv("example_data/outputs/csv")
2022-07-14 15:34:30,652 - Saving Network to CSV in example_data/output_csv/network 2022-07-14 15:34:30,746 - Saving Schedule to GTFS csv in example_data/output_csv/schedule 2022-07-14 15:34:30,990 - Saving example_data/output_csv/schedule/stops.csv 2022-07-14 15:34:30,994 - Saving example_data/output_csv/schedule/routes.csv 2022-07-14 15:34:30,996 - Saving example_data/output_csv/schedule/trips.csv 2022-07-14 15:34:31,006 - Saving example_data/output_csv/schedule/stop_times.csv 2022-07-14 15:34:31,039 - Saving example_data/output_csv/schedule/calendar.csv
The node and link CSVs describing the network will include any and all data stored as attributes on the graph---in contrast to the MATSim output which will only include attributes included in the MATSim network schema.
For Schedule
the outputs are saved to GTFS CSV files. Some data is lost when saving Schedule to GTFS, for example the relationship and paths between network and schedule. The details of this schema and what is lost can be found in Section/Notebook 3.3 Writing GTFS data.