Skip to content

Usage: 2.4. Reading Data: CSV

Kasia Kozlowska edited this page Jul 14, 2022 · 2 revisions

Reading a network from CSV

Available as a jupyter notebook or wiki page.

You can read a network from node and link CSV files. For it to be a valid MATSim network, the CSVs need to have the following data columns:

Nodes:

  • id - unique ID for the Node
  • x - x spatial coordinate in a given projection
  • y - y spatial coordinate in a given projection

Links:

  • id - unique ID for the Link
  • from - source Node ID
  • to - target Node ID
  • length - link length in metres
  • freespeed - meter/seconds speed
  • capacity - vehicles/hour
  • permlanes - number of lanes
  • modes - set of modes

Following the MATSim network schema. As well as be strongly connected for modes available to agents. Check out Section/Notebook 6.1. Validating Network - MATSim Specific for more details about validating Network.

csv_nodes = '../example_data/example_csv/nodes.csv'
csv_links = '../example_data/example_csv/links.csv'
from genet import read_csv
n = read_csv(csv_nodes, csv_links, epsg='epsg:27700')
2022-07-14 15:30:48,943 - Reading nodes from ../example_data/example_csv/nodes.csv
2022-07-14 15:30:48,949 - Reading links from ../example_data/example_csv/nodes.csv
2022-07-14 15:30:49,024 - Added 4 nodes
2022-07-14 15:30:49,034 - Added 2 links
n.print()
Graph info: Name: Network graph
Type: MultiDiGraph
Number of nodes: 4
Number of edges: 2
Average in degree:   0.5000
Average out degree:   0.5000 
Schedule info: Schedule:
Number of services: 0
Number of routes: 0
Number of stops: 0

For reading Schedule from csv inputs, head over to Section/Notebook 2.3. Reading GTFS data