runtest_rimea_5.py 1.94 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#!/usr/bin/env python
import os
import sys
import numpy as np
utestdir = os.path.abspath(os.path.dirname(os.path.dirname(sys.path[0])))
from sys import *
sys.path.append(utestdir)
from JPSRunTest import JPSRunTestDriver
from utils import *



def run_rimea_test5(inifile, trajfile):
    reaction_time = 10 # reaction times are [10, 20, 30, ..., 100]
    must_dt = 0
    errors = []
    # pedestrians in force-based models accelerate from 0 to v0 after some time (\tau)
    fps, n, traj = parse_file(trajfile)
Mohcine Chraibi's avatar
Mohcine Chraibi committed
19 20 21

    threshold = 1./fps + 0.01 # second

22
    peds = np.unique(traj[:, 0])
Mohcine Chraibi's avatar
Mohcine Chraibi committed
23
    logging.info("=== npeds: %d, fps: %d, threshold = %.2f", n, fps, threshold)
24 25 26
    for ped in peds:
        must_dt += reaction_time
        ptraj = traj[traj[:, 0] == ped]
Mohcine Chraibi's avatar
Mohcine Chraibi committed
27 28
        xdiff = np.diff(ptraj[:, 2]) # dx
        ydiff = np.diff(ptraj[:, 3]) # dy
Mohcine Chraibi's avatar
Mohcine Chraibi committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

        if (xdiff!=0).any():
            xfr = ptraj[xdiff != 0][1, 1] # second x element, not first
        else: 
            xfr = np.inf

        if (ydiff!=0).any():
            yfr = ptraj[ydiff != 0][1, 1] # second x element, not first
        else: 
            yfr = np.inf

        if np.isinf(yfr) and np.isinf(xfr): # ped did not move at all
            logging.critical("xfr: %d, yfr: %d", xfr, yfr)
            logging.critical("%s exits with FAILURE", argv[0])
            exit(FAILURE)

Mohcine Chraibi's avatar
Mohcine Chraibi committed
45 46

        df = min(xfr, yfr) - ptraj[0, 1]
47 48 49
        dt = 1.0*df/fps
        error = np.abs(dt-must_dt)
        errors.append(error)
Mohcine Chraibi's avatar
Mohcine Chraibi committed
50
        logging.info("ped: %2d, df: %6d, dt: %6.2f, must_time: %3d (error: %2.2f )",
51 52
                     ped, df, dt, must_dt, error)

Mohcine Chraibi's avatar
Mohcine Chraibi committed
53 54
    if not (np.array(errors) <= threshold).all():
        logging.critical("%s exits with FAILURE", argv[0])
55 56 57 58 59 60 61 62 63 64 65 66 67
        exit(FAILURE)


if __name__ == "__main__":
    test = JPSRunTestDriver(5, argv0=argv[0], testdir=sys.path[0], utestdir=utestdir)
    test.run_test(testfunction=run_rimea_test5)
    logging.info("%s exits with SUCCESS" % (argv[0]))
    exit(SUCCESS)





Mohcine Chraibi's avatar
Mohcine Chraibi committed
68