Пример #1
0
def readEventsFile(file, types):
    """Reads a MATSim events file
    Parameters:
        file (string): the path of the events file
        types (string): the event types to consider
    """
    return matsim.event_reader(file, types=types)
Пример #2
0
def count(persons, f):

    counts = Counter({k: 0 for k in persons})

    for ev in event_reader(p + f, types=["actstart"]):

        if ev["actType"] == "leisure":
            counts[ev["person"]] += 1

    return counts
def read_events(f, act=None, lookup=True):
    data = []

    for ev in event_reader(f, types=["episimContact"]):
        
        # Lookup maxgroup size of container
        if lookup and ev["container"] in container.index:
            ev["maxGroupSize"] = container.loc[ev["container"]].maxGroupSize
        
        if not act or any(x in ev["actType"] for x in act):
            data.append(ev)
    
    return pd.DataFrame(data).astype(dtype={"duration": "float", "groupSize": "int",
                                     "type": "str", "actType": "str", "container": "str"})
outfile = "drt-vehicles.json"

print("reading network", sys.argv[1])
network = matsim.read_network(sys.argv[1])

# Build link x/y lookup -- use 'to_node' (endpoint) of link
nodes = network.nodes >> mutate(to_node=X.node_id)
links = network.links >> inner_join(nodes, by="to_node") >> select(
    X.link_id, X.x, X.y)

link_coords = {}
for link in links.values:
    link_coords[link[0]] = (float(link[1]), float(link[2]))

print("reading events", sys.argv[2])
events = matsim.event_reader(sys.argv[2], types="actstart,actend")

# lookups by person's health status, coords, and timepoints
agents = {}

act_ends = {}
cur_location = {}

for event in events:
    # only interested in DRT vehicle events
    if event["actType"] != "DrtBusStop":
        continue

    person_id = event["person"]
    time = int(event["time"])
print(len(facilities), "facilities found")


for day in [9]: # range(1, 2):
    print(f"Processing day {day}")

    # outfile hard-coded for now
    fTrips = "trips.json"
    fInfections = f"{day:03d}-infections.json"

    magic_seconds = (day) * 86400

    # trips are identical across all days; so only read them once.
    whichEvents = "episimPersonStatus,actstart,actend"

    events = matsim.event_reader(f"day_{day:03d}.xml.gz", types=whichEvents)

    # lookups by person's health status, coords, and timepoints
    agents = {}
    infected_people = set()

    act_ends = {}
    cur_location = {}

    facility_missing = 0
    facility_found = 0

    for event in events:
        person_id = event["person"]
        if person_id.startswith("freight"):
            continue
        x0=X.x, y0=X.y, to_node=X.to_node_x) >> inner_join(nodes, by="to_node")
         >> select(X.link_id, X.x0, X.y0, X.x_y, X.y_y))

link_coords = {}
for link in links.values:
    link_coords[link[0]] = (
        float(link[1]),
        float(link[2]),
        float(link[3]),
        float(link[4]),
    )

print("reading events:", p_events)
events = matsim.event_reader(
    p_events,
    types=
    "entered link,left link,vehicle enters traffic,vehicle leaves traffic,PersonEntersVehicle,PersonLeavesVehicle,DrtRequest submitted,PassengersRequest scheduled",
)

# lookups by person's health status, coords, and timepoints
agents = {}
drt_requests = {}
drt_request_list = []

for event in events:
    # only interested in (1) DRT requests and (2) DRT vehicle events
    if event["type"] == "DrtRequest submitted":
        coord = link_coords[event["fromLink"]]
        x, y = (0.5 * (coord[0] + coord[2]), 0.5 * (coord[1] + coord[3]))
        lat, lon = coord_transformer.transform(x, y)
        coord_from = [round(lon, 5), round(lat, 5)]
Пример #7
0
    scenario_path = get_scenario_path(data_path, scenario_name)
    vis_path = scenario_path + '/vis'
    output_path = vis_path + '/custom'
    try:
        os.mkdir(output_path)
    except FileExistsError:
        pass

    # read shp files
    shp_files_path = vis_path + '/genet_standard_output/shp_files'
    network_path = shp_files_path + '/network_links.shp'
    network = gpd.read_file(network_path)

    # stream through events
    events = matsim.event_reader(scenario_path +
                                 '/output/output_events.xml.gz',
                                 types='entered link')
    link_counts = defaultdict(int)
    for event in tqdm(events):
        if event['type'] == 'entered link':
            link_counts[event['link']] += 1
    link_counts = pd.DataFrame.from_dict(link_counts,
                                         orient='index',
                                         columns=['count'
                                                  ]).rename_axis('link_id')

    # merge data
    network_counts = network.rename(columns={
        'id': 'link_id'
    }).merge(link_counts, on='link_id')
Пример #8
0
sample_rate = 10

# disease status numeric codes
disease_code = {
    "susceptible": 0,
    "infectedButNotContagious": 1,
    "contagious": 2,
}

#outfile hard-coded for now
outfile = '00' + str(day) + '-infections.json'

# magic_seconds = 691100 # day 8
magic_seconds = day * 86400  # 345600 # 691200 # 345600

events = matsim.event_reader("day_00" + str(day) + ".xml.gz",
                             types="episimPersonStatus,actstart,actend")

# lookups by person's health status, coords, and timepoints
agents = {}
infected_people = set()

act_ends = {}
cur_location = {}

for event in events:
    person_id = event["person"]
    if person_id.startswith("freight"):
        continue

    time = int(event["time"] - magic_seconds)
    if time < 0: