Exemplo n.º 1
0
def execute(context):
    n = GTFSMerger()
    gtfs_1 = open("%s/gtfs/emtu.zip" % context.config("data_path"), 'rb').read()
    gtfs_2 = open("%s/gtfs/sptrans.zip" % context.config("data_path"), 'rb').read()
    n.merge_from_bytes_list([ gtfs_1, gtfs_2 ])

    n.get_zipfile("%s/gtfs/gtfs_merged.zip" % context.config("data_path"))
    with zipfile.ZipFile("%s/gtfs/gtfs_merged.zip" % context.config("data_path"), 'r') as zip_ref:
        zip_ref.extractall("%s/gtfs/gtfs_merged/" % context.config("data_path"))
        
    data = pd.read_csv("%s/gtfs/gtfs_merged/calendar.txt" % context.config("data_path"))
    data["end_date"] = data["end_date"].str.replace("-","")
    data["start_date"] = data["start_date"].str.replace("-","")
    data.to_csv("%s/gtfs/gtfs_merged/calendar.txt" % context.config("data_path"))

    data = pd.read_csv("%s/gtfs/gtfs_merged/calendar_dates.txt" % context.config("data_path"))
    data["date"] = data["date"].str.replace("-","")
    data.to_csv("%s/gtfs/gtfs_merged/calendar_dates.txt" % context.config("data_path"))

    
    pt2matsim.run(context, "org.matsim.pt2matsim.run.Gtfs2TransitSchedule", [
        "%s/gtfs/gtfs_merged" % context.config("data_path"),
        "dayWithMostServices", "EPSG:29183", # TODO: dayWithMostServices should be made explicit and configurable!
        "%s/transit_schedule.xml.gz" % context.path(),
        "%s/transit_vehicles.xml.gz" % context.path()
    ])

    assert(os.path.exists("%s/transit_schedule.xml.gz" % context.path()))
    assert(os.path.exists("%s/transit_vehicles.xml.gz" % context.path()))

    return dict(
        schedule_path = "transit_schedule.xml.gz",
        vehicles_path = "transit_vehicles.xml.gz"
    )
Exemplo n.º 2
0
def execute(context):
    pt2matsim.run(context, "org.matsim.pt2matsim.run.CreateDefaultOsmConfig",
                  ["config_template.xml"])

    with open("%s/config_template.xml" % context.path()) as f_read:
        content = f_read.read()

        content = content.replace(
            '<param name="osmFile" value="null" />',
            '<param name="osmFile" value="%s/osm/ile-de-france-latest.osm.gz" />'
            % context.config("data_path"))

        content = content.replace(
            '<param name="outputCoordinateSystem" value="null" />',
            '<param name="outputCoordinateSystem" value="EPSG:2154" />')

        content = content.replace(
            '<param name="outputNetworkFile" value="null" />',
            '<param name="outputNetworkFile" value="network.xml.gz" />')

        content = content.replace(
            '<param name="allowedTransportModes" value="car" />',
            '<param name="allowedTransportModes" value="car,car_passenger" />')

        with open("%s/config.xml" % context.path(), "w+") as f_write:
            f_write.write(content)

    pt2matsim.run(context, "org.matsim.pt2matsim.run.Osm2MultimodalNetwork",
                  ["config.xml"])

    assert (os.path.exists("%s/network.xml.gz" % context.path()))
    return "network.xml.gz"
Exemplo n.º 3
0
def execute(context):
    pt2matsim.run(context, "org.matsim.pt2matsim.run.Gtfs2TransitSchedule", [
        "%s/gtfs" % context.config("data_path"),
        "dayWithMostServices", "EPSG:2154", # TODO: dayWithMostServices should be made explicit and configurable!
        "%s/transit_schedule.xml.gz" % context.path(),
        "%s/transit_vehicles.xml.gz" % context.path()
    ])

    assert(os.path.exists("%s/transit_schedule.xml.gz" % context.path()))
    assert(os.path.exists("%s/transit_vehicles.xml.gz" % context.path()))

    return dict(
        schedule_path = "transit_schedule.xml.gz",
        vehicles_path = "transit_vehicles.xml.gz"
    )
Exemplo n.º 4
0
def execute(context):
    gtfs_path = os.path.realpath(
        "%s/%s" % (context.config("data_path"), context.config("gtfs_path")))

    pt2matsim.run(context, "org.matsim.pt2matsim.run.Gtfs2TransitSchedule", [
        gtfs_path,
        context.config("gtfs_date"), "EPSG:2154",
        "%s/transit_schedule.xml.gz" % context.path(),
        "%s/transit_vehicles.xml.gz" % context.path()
    ])

    assert (os.path.exists("%s/transit_schedule.xml.gz" % context.path()))
    assert (os.path.exists("%s/transit_vehicles.xml.gz" % context.path()))

    return dict(schedule_path="transit_schedule.xml.gz",
                vehicles_path="transit_vehicles.xml.gz")
Exemplo n.º 5
0
def execute(context):
    osm_path = "%s/output.osm.gz" % context.path("data.osm.cleaned")

    pt2matsim.run(context, "org.matsim.pt2matsim.run.CreateDefaultOsmConfig", [
        "config_template.xml"
    ])

    with open("%s/config_template.xml" % context.path()) as f_read:
        content = f_read.read()

        content = content.replace(
            '<param name="osmFile" value="null" />',
            '<param name="osmFile" value="%s" />' % osm_path
        )

        content = content.replace(
            '<param name="outputCoordinateSystem" value="null" />',
            '<param name="outputCoordinateSystem" value="EPSG:2154" />'
        )

        content = content.replace(
            '<param name="outputNetworkFile" value="null" />',
            '<param name="outputNetworkFile" value="network.xml.gz" />'
        )

        content = content.replace(
            '</module>',
            """
                <parameterset type="routableSubnetwork">
                    <param name="allowedTransportModes" value="car" />
                    <param name="subnetworkMode" value="car_passenger" />
                </parameterset>
            </module>
            """
        )

        with open("%s/config.xml" % context.path(), "w+") as f_write:
            f_write.write(content)

    pt2matsim.run(context, "org.matsim.pt2matsim.run.Osm2MultimodalNetwork", [
        "config.xml"
    ])

    assert(os.path.exists("%s/network.xml.gz" % context.path()))
    return "network.xml.gz"
Exemplo n.º 6
0
def execute(context):
    # Prepare input paths
    network_path = "%s/%s" % (
        context.path("matsim.scenario.supply.osm"),
        context.stage("matsim.scenario.supply.osm")
    )

    schedule_path = "%s/%s" % (
        context.path("matsim.scenario.supply.gtfs"),
        context.stage("matsim.scenario.supply.gtfs")["schedule_path"]
    )

    # Create and modify config file
    pt2matsim.run(context, "org.matsim.pt2matsim.run.CreateDefaultPTMapperConfig", [
        "config_template.xml"
    ])

    with open("%s/config_template.xml" % context.path()) as f_read:
        content = f_read.read()

        content = content.replace(
            '<param name="inputNetworkFile" value="" />',
            '<param name="inputNetworkFile" value="%s" />' % network_path
        )
        content = content.replace(
            '<param name="inputScheduleFile" value="" />',
            '<param name="inputScheduleFile" value="%s" />' % schedule_path
        )
        content = content.replace(
            '<param name="numOfThreads" value="2" />',
            '<param name="numOfThreads" value="%d" />' % context.config("processes")
        )
        content = content.replace(
            '<param name="outputNetworkFile" value="" />',
            '<param name="outputNetworkFile" value="network.xml.gz" />'
        )
        content = content.replace(
            '<param name="outputScheduleFile" value="" />',
            '<param name="outputScheduleFile" value="schedule.xml.gz" />'
        )
        content = content.replace(
            '<param name="outputStreetNetworkFile" value="" />',
            '<param name="outputStreetNetworkFile" value="road_network.xml.gz" />'
        )
        content = content.replace(
            '<param name="modesToKeepOnCleanUp" value="car" />',
            '<param name="modesToKeepOnCleanUp" value="car,car_passenger,truck" />'
        )

        with open("%s/config.xml" % context.path(), "w+") as f_write:
            f_write.write(content)

    # Run mapping process
    pt2matsim.run(context, "org.matsim.pt2matsim.run.PublicTransitMapper", [
        "config.xml"
    ])

    assert(os.path.exists("%s/network.xml.gz" % context.path()))
    assert(os.path.exists("%s/schedule.xml.gz" % context.path()))

    # Run plausibility checks
    #pt2matsim.run(context, "org.matsim.pt2matsim.run.CheckMappedSchedulePlausibility", [
    #    "schedule.xml.gz", "network.xml.gz", "EPSG:2154", context.path()
    #])
    #assert(os.path.exists("%s/allPlausibilityWarnings.csv" % context.path()))

    return dict(
        network_path = "network.xml.gz",
        schedule_path = "schedule.xml.gz",
        #plausibility_path = "allPlausibilityWarnings.xml.gz"
    )
Exemplo n.º 7
0
def execute(context):
    content = """<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE config SYSTEM "http://www.matsim.org/files/dtd/config_v2.dtd">
    <config>
	<module name="OsmConverter" >
		<!-- Sets whether the detailed geometry of the roads should be retained in the conversion or not.
		Keeping the detailed paths results in a much higher number of nodes and links in the resulting MATSim network.
		Not keeping the detailed paths removes all nodes where only one road passes through, thus only real intersections
		or branchings are kept as nodes. This reduces the number of nodes and links in the network, but can in some rare
		cases generate extremely long links (e.g. for motorways with only a few ramps every few kilometers).
		Defaults to <code>false</code>. -->
		<param name="keepPaths" value="false" />
		<!-- If true: The osm tags for ways and containing relations are saved as link attributes in the network. Increases filesize. Default: true. -->
		<param name="keepTagsAsAttributes" value="true" />
		<!-- Keep all ways (highway=* and railway=*) with public transit even if they don't have wayDefaultParams defined -->
		<param name="keepWaysWithPublicTransit" value="true" />
		<param name="maxLinkLength" value="1500.0" />
		<!-- The path to the osm file. -->
		<param name="osmFile" value="/nas/balacm/California/Data/LA/osm/la5counties.osm.gz" />
		<param name="outputCoordinateSystem" value="EPSG:2227" />
		<param name="outputNetworkFile" value="network.xml.gz" />
		<!-- In case the speed limit allowed does not represent the speed a vehicle can actually realize, e.g. by constrains of
		traffic lights not explicitly modeled, a kind of "average simulated speed" can be used.
		Defaults to false. Set true to scale the speed limit down by the value specified by the wayDefaultParams) -->
		<param name="scaleMaxSpeed" value="false" />
		<parameterset type="routableSubnetwork" >
			<param name="allowedTransportModes" value="car" />
			<param name="subnetworkMode" value="car" />
		</parameterset>
		<parameterset type="routableSubnetwork" >
			<param name="allowedTransportModes" value="car" />
			<param name="subnetworkMode" value="car_passenger" />
		</parameterset>
		<parameterset type="routableSubnetwork" >
			<param name="allowedTransportModes" value="car" />
			<param name="subnetworkMode" value="taxi" />
		</parameterset>
		<parameterset type="routableSubnetwork" >
			<param name="allowedTransportModes" value="bus" />
			<param name="subnetworkMode" value="bus" />
		</parameterset>
		<parameterset type="wayDefaultParams" >
			<param name="allowedTransportModes" value="car" />
			<param name="freespeed" value="95.3333" />
			<param name="freespeedFactor" value="1.0" />
			<param name="laneCapacity" value="1800.0" />
			<param name="lanes" value="3.0" />
			<param name="oneway" value="true" />
			<param name="osmKey" value="highway" />
			<param name="osmValue" value="motorway" />
		</parameterset>
		<parameterset type="wayDefaultParams" >
			<param name="allowedTransportModes" value="car" />
			<param name="freespeed" value="51.55" />
			<param name="freespeedFactor" value="1.0" />
			<param name="laneCapacity" value="1500.0" />
			<param name="lanes" value="1.0" />
			<param name="oneway" value="true" />
			<param name="osmKey" value="highway" />
			<param name="osmValue" value="motorway_link" />
		</parameterset>
		<parameterset type="wayDefaultParams" >
			<param name="allowedTransportModes" value="car" />
			<param name="freespeed" value="80" />
			<param name="freespeedFactor" value="1.0" />
			<param name="laneCapacity" value="2000.0" />
			<param name="lanes" value="2.0" />
			<param name="oneway" value="false" />
			<param name="osmKey" value="highway" />
			<param name="osmValue" value="trunk" />
		</parameterset>
		<parameterset type="wayDefaultParams" >
			<param name="allowedTransportModes" value="car" />
			<param name="freespeed" value="51" />
			<param name="freespeedFactor" value="1.0" />
			<param name="laneCapacity" value="1500.0" />
			<param name="lanes" value="1.0" />
			<param name="oneway" value="false" />
			<param name="osmKey" value="highway" />
			<param name="osmValue" value="trunk_link" />
		</parameterset>
		<parameterset type="wayDefaultParams" >
			<param name="allowedTransportModes" value="car" />
			<param name="freespeed" value="73.5555" />
			<param name="freespeedFactor" value="1.0" />
			<param name="laneCapacity" value="1500.0" />
			<param name="lanes" value="2.0" />
			<param name="oneway" value="false" />
			<param name="osmKey" value="highway" />
			<param name="osmValue" value="primary" />
		</parameterset>
		<parameterset type="wayDefaultParams" >
			<param name="allowedTransportModes" value="car" />
			<param name="freespeed" value="51" />
			<param name="freespeedFactor" value="1.0" />
			<param name="laneCapacity" value="1500.0" />
			<param name="lanes" value="1.0" />
			<param name="oneway" value="false" />
			<param name="osmKey" value="highway" />
			<param name="osmValue" value="primary_link" />
		</parameterset>
		<parameterset type="wayDefaultParams" >
			<param name="allowedTransportModes" value="car" />
			<param name="freespeed" value="51" />
			<param name="freespeedFactor" value="1.0" />
			<param name="laneCapacity" value="1100.0" />
			<param name="lanes" value="2.0" />
			<param name="oneway" value="false" />
			<param name="osmKey" value="highway" />
			<param name="osmValue" value="secondary" />
		</parameterset>
		<parameterset type="wayDefaultParams" >
			<param name="allowedTransportModes" value="car" />
			<param name="freespeed" value="51" />
			<param name="freespeedFactor" value="1.0" />
			<param name="laneCapacity" value="1100.0" />
			<param name="lanes" value="1.0" />
			<param name="oneway" value="false" />
			<param name="osmKey" value="highway" />
			<param name="osmValue" value="secondary_link" />
		</parameterset>
		<parameterset type="wayDefaultParams" >
			<param name="allowedTransportModes" value="car" />
			<param name="freespeed" value="44" />
			<param name="freespeedFactor" value="1.0" />
			<param name="laneCapacity" value="800.0" />
			<param name="lanes" value="1.0" />
			<param name="oneway" value="false" />
			<param name="osmKey" value="highway" />
			<param name="osmValue" value="tertiary" />
		</parameterset>
		<parameterset type="wayDefaultParams" >
			<param name="allowedTransportModes" value="car" />
			<param name="freespeed" value="44" />
			<param name="freespeedFactor" value="1.0" />
			<param name="laneCapacity" value="800.0" />
			<param name="lanes" value="1.0" />
			<param name="oneway" value="false" />
			<param name="osmKey" value="highway" />
			<param name="osmValue" value="tertiary_link" />
		</parameterset>
		<parameterset type="wayDefaultParams" >
			<param name="allowedTransportModes" value="car" />
			<param name="freespeed" value="36" />
			<param name="freespeedFactor" value="1.0" />
			<param name="laneCapacity" value="600.0" />
			<param name="lanes" value="1.0" />
			<param name="oneway" value="false" />
			<param name="osmKey" value="highway" />
			<param name="osmValue" value="minor" />
		</parameterset>
		<parameterset type="wayDefaultParams" >
			<param name="allowedTransportModes" value="car" />
			<param name="freespeed" value="36" />
			<param name="freespeedFactor" value="1.0" />
			<param name="laneCapacity" value="600.0" />
			<param name="lanes" value="1.0" />
			<param name="oneway" value="false" />
			<param name="osmKey" value="highway" />
			<param name="osmValue" value="unclassified" />
		</parameterset>
		<parameterset type="wayDefaultParams" >
			<param name="allowedTransportModes" value="car" />
			<param name="freespeed" value="36" />
			<param name="freespeedFactor" value="1.0" />
			<param name="laneCapacity" value="600.0" />
			<param name="lanes" value="1.0" />
			<param name="oneway" value="false" />
			<param name="osmKey" value="highway" />
			<param name="osmValue" value="residential" />
		</parameterset>
		<parameterset type="wayDefaultParams" >
			<param name="allowedTransportModes" value="car" />
			<param name="freespeed" value="29" />
			<param name="freespeedFactor" value="1.0" />
			<param name="laneCapacity" value="600.0" />
			<param name="lanes" value="1.0" />
			<param name="oneway" value="false" />
			<param name="osmKey" value="highway" />
			<param name="osmValue" value="living_street" />
		</parameterset>
		<parameterset type="wayDefaultParams" >
			<param name="allowedTransportModes" value="rail" />
			<param name="freespeed" value="127" />
			<param name="freespeedFactor" value="1.0" />
			<param name="laneCapacity" value="9999.0" />
			<param name="lanes" value="1.0" />
			<param name="oneway" value="false" />
			<param name="osmKey" value="railway" />
			<param name="osmValue" value="rail" />
		</parameterset>
		<parameterset type="wayDefaultParams" >
			<param name="allowedTransportModes" value="rail" />
			<param name="freespeed" value="30" />
			<param name="freespeedFactor" value="1.0" />
			<param name="laneCapacity" value="9999.0" />
			<param name="lanes" value="1.0" />
			<param name="oneway" value="true" />
			<param name="osmKey" value="railway" />
			<param name="osmValue" value="tram" />
		</parameterset>
		<parameterset type="wayDefaultParams" >
			<param name="allowedTransportModes" value="rail" />
			<param name="freespeed" value="60" />
			<param name="freespeedFactor" value="1.0" />
			<param name="laneCapacity" value="9999.0" />
			<param name="lanes" value="1.0" />
			<param name="oneway" value="false" />
			<param name="osmKey" value="railway" />
			<param name="osmValue" value="light_rail" />
		</parameterset>
	</module>

    </config>
    """
    pt2matsim.run(context, "org.matsim.pt2matsim.run.CreateDefaultOsmConfig",
                  ["config_template.xml"])

    with open("%s/config.xml" % context.path(), "w+") as f_write:
        f_write.write(content)

    pt2matsim.run(context, "org.matsim.pt2matsim.run.Osm2MultimodalNetwork",
                  ["config.xml"])

    assert (os.path.exists("%s/network.xml.gz" % context.path()))
    return "network.xml.gz"