Skip to content
This repository has been archived by the owner on Sep 22, 2023. It is now read-only.

Fix calculation of direction coverage #114

Open
stklik opened this issue May 26, 2022 · 0 comments
Open

Fix calculation of direction coverage #114

stklik opened this issue May 26, 2022 · 0 comments

Comments

@stklik
Copy link

stklik commented May 26, 2022

It seems that the pipeline uses the following direction_coverage function for the road analysis.

I found two issues:

  • first n_bins is 25 by default, but should be 35, so it's 36 bins in total. The calculated data is thus split differently than the comment indicates
  • second, the code uses np.arccos(dot_product) for the calculation of the angle. However, np.arccos produces values in the range [0, π] (i.e. [0, 180] degrees). In other words, this function calculates the smallest angle between THE_NORTH and the segment, independent of the side.

I suggest the following code to fix it (note, it uses numpy throughout and is thus faster than the previous method).

def get_thetas(xs, ys, skip=1):
    """Transform x,y coordinates of points and return each segment's offset from x-axis in the range [np.pi, np.pi]"""
    xdiffs = xs[1:] - xs[0:-1]
    ydiffs = ys[1:] - ys[0:-1]
    thetas = np.arctan2(ydiffs, xdiffs) 
    return thetas

def dir_cov(the_test, n_bins=36):
    np_arr = np.array(the_test)
    thetas, kappas = get_thetas(np_arr[:,0], np_arr[:,1])
    coverage_buckets = np.linspace(-np.pi, np.pi, num=n_bins)
    covered_elements = set(np.digitize(thetas, coverage_buckets))
    return len(covered_elements) / len(coverage_buckets)

According to my tests on the data, this behaviour should be correct.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant