Пример #1
0
def cal_dist(name,GROUND_TRUTH):
	distance=[150.453623567463]
	df=pd.read_csv(name)
	l=len(df)
	i=0
	while i+1<l:
		lat1=df.iloc[i]['latitude']
		long1=df.iloc[i][' longitude']
		lat2=df.iloc[i+1]['latitude']
		long2=df.iloc[i+1][' longitude']

		dist=get_spherical_distance(lat1,lat2,long1,long2)

		distance.append(dist)
		i+=1
	df['cons_dist']=distance
	df.to_csv(name,index=False)
	insert_time(name)
	#print(GROUND_TRUTH)
	dec_zone(name,GROUND_TRUTH)
Пример #2
0
def compare_ground_truth(ground_truth_file, bus_stop_file,
                         GROUND_TRUTH_THRESHOLD):

    gt = []
    bus_stops = []
    text = open(ground_truth_file, "r")
    gt_1 = text.readlines()[1:]
    for gt_point in gt_1:
        gt_point = gt_point.replace('\n', '')
        k = gt_point.split(',')
        #print(k)
        #print('\n')
        for i in k:
            gt.append(float(i))

    #print(gt)
    #print('\n')

    text.close()
    text = open(bus_stop_file, "r")
    bus_stops_1 = text.readlines()[1:]
    for gt_point in bus_stops_1:
        gt_point = gt_point.replace('\n', '')
        k = gt_point.split(',')
        #print(k)
        #print('\n')
        cnt = 0
        for i in k:
            if cnt != 2:
                bus_stops.append(float(i))
                cnt += 1
        #bus_stops.append(k)
    #print(bus_stops)
    text.close()
    #bus_stops = read_file()
    df = pd.read_csv(bus_stop_file)

    #print "GT: ",len(gt)
    #print "all bus_stops: ",len(bus_stops)
    #print gt[0]
    #print bus_stops[0]

    #detected  = []
    #false_negative=[]

    #gt_dict={}
    used = []
    stop = []
    l_gt = len(gt)
    l_bs = len(bus_stops)
    cnt_gt = 0
    #for gt_point in gt:
    while cnt_gt < l_gt:
        #distances = []

        #min_point = None
        #min_dist = 100000000000000
        cnt_bs = 0
        #for bs_point in bus_stops:
        while cnt_bs < l_bs:
            #pas
            #print("p")
            if bus_stops[cnt_bs] in used and bus_stops[cnt_bs + 1] in used:
                #print("l")
                cnt_bs += 2
                continue

            lats1, longs1 = gt[cnt_gt], gt[cnt_gt + 1]
            lat1, long1 = float(lats1), float(longs1)

            lats2, longs2 = bus_stops[cnt_bs], bus_stops[cnt_bs + 1]
            lat2, long2 = float(lats2), float(longs2)
            #print(lats1,",",longs1,",",lats2,",",longs2)
            #print(lat1,",",long1,",",lat2,",",long2)
            dist = get_spherical_distance(lat1, lat2, long1, long2)
            #print(dist)
            #the stoppage at the closest distance goes at the end of the list
            if dist < GROUND_TRUTH_THRESHOLD:
                #min_dist = dist
                #min_point = bs_point
                stop.append(cnt_bs / 2)
                used.append(bus_stops[cnt_bs])
                used.append(bus_stops[cnt_bs + 1])
                #print(used)
            #else:
            #	stop.append("0")
            cnt_bs += 2
            #print("b")
            #print(l_gt)
            #print(l_bs)
            #print(cnt_bs)
        cnt_gt += 2
        #print(cnt_gt)
        #print("a")
    #print("s")
    #print(len(stop))
    #print(stop)
    stop_ac = []
    k = 0
    while k < l_bs / 2:
        stop_ac.append(0)
        #print(len(stop_ac))
        k += 1
    j = 0
    while j < l_bs / 2:
        #pass
        if j in stop:
            stop_ac[j] = 1
        j += 1
    #print(stop_ac)
    df['bs_predict'] = stop_ac
    #print(df)
    df.to_csv(bus_stop_file, index=False)
    #gt_dict[gt_point[0]]= points
    '''if min_dist < GROUND_TRUTH_THRESHOLD:
Пример #3
0
def dec_zone(name,GROUND_TRUTH):
	#print(GROUND_TRUTH)
	zone=[]
	zone_class=[]
	l_market=[]
	l_nc=[]
	l_highway=[]
	df=pd.read_csv(name)
	if '54feet' in GROUND_TRUTH:
		Lat_market=23.5631833333 
		Long_market=87.28356
		Lat_nc=23.5440616667 
		Long_nc=87.2887366667
		Lat_high=23.4946766667 
		Long_high=87.3168283333
		l_market.append(get_spherical_distance(Lat_market,Lat_nc,Long_market,Long_nc))
		l_nc.append(get_spherical_distance(Lat_nc,Lat_high,Long_nc,Long_high))
		

		
		l=len(df)
		#print(l)
		i=0
		while i<l:
			#print("a ",i)
			Lat_a=df.iloc[i]['latitude']
			Long_a=df.iloc[i][' longitude']
			#if get_spherical_distance(Lat_a,Lat_market,Long_a,Long_market)+get_spherical_distance(Lat_a,Lat_nc,Long_a,Long_nc)==l_market:
			if get_spherical_distance(Lat_a,Lat_market,Long_a,Long_market)<l_market[0]:
				zone.append('Market')
				zone_class.append('1')
		#elif get_spherical_distance(Lat_a,Lat_nc,Long_a,Long_nc)+get_spherical_distance(Lat_a,Lat_high,Long_a,Long_high)==l_nc:
			elif get_spherical_distance(Lat_a,Lat_nc,Long_a,Long_nc)<l_nc[0]:
				zone.append('Normal city')
				zone_class.append('2')
			else:
				zone.append('Highway')
				zone_class.append('3')
			#print(len(zone))
			#print(zone)
			i+=1
	if 'azone' in GROUND_TRUTH:
		Lat_market=[23.5481833333]
		Long_market=[87.3024633333]
		Lat_nc=[23.564295,23.5074966667]
		Long_nc=[87.28288,87.3101183333]
		Lat_high=[23.5702466667,23.5355883333]
		Long_high=[87.3025383333,87.2982133333]
		Lat=23.494395
		Long=87.317125
		
		l_market.append(get_spherical_distance(Lat_market[0],Lat_high[1],Long_market[0],Long_high[1]))
		#l_market.append(get_spherical_distance(Lat_market[1],Lat_high[0],Long_market[1],Long_high[0]))
		l_nc.append(get_spherical_distance(Lat_nc[0],Lat_high[0],Long_nc[0],Long_high[0]))
		l_nc.append(get_spherical_distance(Lat_nc[1],Lat,Long_nc[1],Long))
		l_highway.append(get_spherical_distance(Lat_high[0],Lat_market[0],Long_high[0],Long_market[0]))
		l_highway.append(get_spherical_distance(Lat_high[1],Lat_nc[1],Long_high[1],Long_nc[1]))
		
		#df=pd.read_csv(name)
		l=len(df)
		#print(l)
		i=0
		while i<l:
			#print("a ",i)
			Lat_a=df.iloc[i]['latitude']
			Long_a=df.iloc[i][' longitude']
			#if get_spherical_distance(Lat_a,Lat_market,Long_a,Long_market)+get_spherical_distance(Lat_a,Lat_nc,Long_a,Long_nc)==l_market:
			if get_spherical_distance(Lat_a,Lat_market[0],Long_a,Long_market[0])<l_market[0]:
				zone.append('Market')
				zone_class.append('1')
		#elif get_spherical_distance(Lat_a,Lat_nc,Long_a,Long_nc)+get_spherical_distance(Lat_a,Lat_high,Long_a,Long_high)==l_nc:
			elif get_spherical_distance(Lat_a,Lat_nc[0],Long_a,Long_nc[0])<l_nc[0] or get_spherical_distance(Lat_a,Lat_nc[1],Long_a,Long_nc[1])<l_nc[1]:
				zone.append('Normal city')
				zone_class.append('2')
			else:
				zone.append('Highway')
				zone_class.append('3')
			#rint(len(zone))
			#print(zone)
			i+=1
	if 'ukhra' in GROUND_TRUTH:
		Lat_market=[23.56451,23.5887733333]
		Long_market=[87.2823233333,87.2085283333]
		Lat_nc=[23.6109329268,23.6407509281]
		Long_nc=[87.217555195,87.2265615539]
		Lat_high=[23.5505989912,23.6276064719]
		Long_high=[87.2686366159,87.2219748885]
		Lat=23.6523530924
		Long=87.2431245943
		
		l_market.append(get_spherical_distance(Lat_market[0],Lat_high[0],Long_market[0],Long_high[0]))
		l_market.append(get_spherical_distance(Lat_market[1],Lat_high[0],Long_market[1],Long_high[0]))
		l_nc.append(get_spherical_distance(Lat_nc[0],Lat_high[1],Long_nc[0],Long_high[1]))
		l_nc.append(get_spherical_distance(Lat_nc[1],Lat,Long_nc[1],Long))
		l_highway.append(get_spherical_distance(Lat_high[0],Lat_market[0],Long_high[0],Long_market[0]))
		l_highway.append(get_spherical_distance(Lat_high[1],Lat_nc[0],Long_high[1],Long_nc[0]))
		
		#df=pd.read_csv(name)
		l=len(df)
		#print(l)
		i=0
		while i<l:
			#print("a ",i)
			Lat_a=df.iloc[i]['latitude']
			Long_a=df.iloc[i][' longitude']
			#if get_spherical_distance(Lat_a,Lat_market,Long_a,Long_market)+get_spherical_distance(Lat_a,Lat_nc,Long_a,Long_nc)==l_market:
			if get_spherical_distance(Lat_a,Lat_market[0],Long_a,Long_market[0])<l_market[0] or get_spherical_distance(Lat_a,Lat_market[1],Long_a,Long_market[1])<l_market[1]:
				zone.append('Market')
				zone_class.append('1')
		#elif get_spherical_distance(Lat_a,Lat_nc,Long_a,Long_nc)+get_spherical_distance(Lat_a,Lat_high,Long_a,Long_high)==l_nc:
			elif get_spherical_distance(Lat_a,Lat_nc[0],Long_a,Long_nc[0])<l_nc[0] or get_spherical_distance(Lat_a,Lat_nc[1],Long_a,Long_nc[1])<l_nc[1]:
				zone.append('Normal city')
				zone_class.append('2')
			else:
				zone.append('Highway')
				zone_class.append('3')
			#print(len(zone))
			#print(zone)
			i+=1
	if '8B' in GROUND_TRUTH:
		Lat_market=[23.56451333,23.52723683,23.5158748,23.49778284]
		Long_market=[87.28308833,87.3419682,87.3548276,87.33484252]
		Lat_nc=[23.56451333,23.53399268,23.52339667]
		Long_nc=[87.28308833,87.34188019,87.33937167]
		Lat_high=[23.54631667,23.50425167]
		Long_high=[87.31860333,87.35286333]
		Lat=23.50697833
		Long=87.31082333
		
		l_market.append(get_spherical_distance(Lat_market[0],Lat_high[0],Long_market[0],Long_high[0]))
		l_market.append(get_spherical_distance(Lat_market[1],Lat_nc[2],Long_market[1],Long_nc[2]))
		l_market.append(get_spherical_distance(Lat_market[2],Lat_high[1],Long_market[2],Long_high[1]))
		l_market.append(get_spherical_distance(Lat_market[3],Lat,Long_market[3],Long))
		l_nc.append(get_spherical_distance(Lat_nc[0],Lat_market[0],Long_nc[0],Long_market[0]))
		l_nc.append(get_spherical_distance(Lat_nc[1],Lat_market[2],Long_nc[1],Long_market[2]))
		l_nc.append(get_spherical_distance(Lat_nc[2],Lat_market[2],Long_nc[2],Long_market[2]))
		l_highway.append(get_spherical_distance(Lat_high[0],Lat_nc[1],Long_high[0],Long_nc[1]))
		l_highway.append(get_spherical_distance(Lat_high[1],Lat_market[3],Long_high[1],Long_market[3]))
		
		#df=pd.read_csv(name)
		l=len(df)
		#print(l)
		i=0
		while i<l:
			#print("a ",i)
			Lat_a=df.iloc[i]['latitude']
			Long_a=df.iloc[i][' longitude']
			#if get_spherical_distance(Lat_a,Lat_market,Long_a,Long_market)+get_spherical_distance(Lat_a,Lat_nc,Long_a,Long_nc)==l_market:
			if get_spherical_distance(Lat_a,Lat_market[0],Long_a,Long_market[0])<l_market[0] or get_spherical_distance(Lat_a,Lat_market[1],Long_a,Long_market[1])<l_market[1] or get_spherical_distance(Lat_a,Lat_market[2],Long_a,Long_market[2])<l_market[2] or get_spherical_distance(Lat_a,Lat_market[3],Long_a,Long_market[3])<l_market[3]:
				zone.append('Market')
				zone_class.append('1')
		#elif get_spherical_distance(Lat_a,Lat_nc,Long_a,Long_nc)+get_spherical_distance(Lat_a,Lat_high,Long_a,Long_high)==l_nc:
			elif get_spherical_distance(Lat_a,Lat_nc[0],Long_a,Long_nc[0])<l_nc[0] or get_spherical_distance(Lat_a,Lat_nc[1],Long_a,Long_nc[1])<l_nc[1] or get_spherical_distance(Lat_a,Lat_nc[2],Long_a,Long_nc[2])<l_nc[2]:
				zone.append('Normal city')
				zone_class.append('2')
			else:
				zone.append('Highway')
				zone_class.append('3')
			#print(len(zone))
			#print(zone)
			i+=1
	#WSSprint(zone)
	#print(zone)
	#print(len(zone))
	df['Zone']=zone
	df['Zone_class']=zone_class
	df.to_csv(name,index=False)
Пример #4
0
def compare_ground_truth(ground_truth_file, bus_stop_file, OUTPUT_FOLDER,
                         threshold, GROUND_TRUTH_THRESHOLD, FP_DISTANCE):

    gt = read_file(ground_truth_file)
    bus_stops = read_file(bus_stop_file)

    print "GT: ", len(gt)
    print "all bus_stops: ", len(bus_stops)
    print gt[0]
    print bus_stops[0]

    detected = []
    false_negative = []

    gt_dict = {}
    used = []

    for gt_point in gt:

        distances = []

        min_point = None
        min_dist = 100000000000000

        points = []

        for bs_point in bus_stops:

            if bs_point in used:
                continue

            lat1, long1 = gt_point[1:]

            lat2, long2 = bs_point[:2]

            dist = get_spherical_distance(lat1, lat2, long1, long2)

            #the stoppage at the closest distance goes at the end of the list
            if dist < min_dist and dist < GROUND_TRUTH_THRESHOLD:
                min_dist = dist
                min_point = bs_point
                points.append(bs_point)
                used.append(bs_point)

        gt_dict[gt_point[0]] = points

        if min_dist < GROUND_TRUTH_THRESHOLD:
            detected.append([gt_point[0]] + min_point)
        else:
            false_negative.append(gt_point)

    false_positive = bus_stops[:]

    # for i in gt_dict:
    # 	gt_dict[i].sort()
    for i, j in gt_dict.items():
        print i, len(j)

    for gt_id, bs_stops in gt_dict.items():

        for point in bs_stops[:-1]:
            bus_stops.remove(point)

    # print "$ ",len(gt_dict)

    for gt_id, bs_stops in gt_dict.items():

        # print "#################"
        for point in bs_stops:
            # print "Deleting ",point
            # print gt_id,point
            false_positive.remove(point)

    ##removing false positives who are within 100m distance of each other
    false_positive_copy = false_positive[:]

    for i in xrange(len(false_positive_copy)):
        for j in xrange(i + 1, len(false_positive_copy)):

            lat1, long1 = false_positive_copy[i][:2]
            lat2, long2 = false_positive_copy[j][:2]
            dist = get_spherical_distance(lat1, lat2, long1, long2)

            if dist < FP_DISTANCE:
                if false_positive_copy[j] in false_positive:
                    print i, j, dist
                    print "removing: ", false_positive_copy[j]
                    false_positive.remove(false_positive_copy[j])

    print "effective bus_stops: ", len(bus_stops)

    print "detected ", len(detected)

    # for bs_point in bus_stops:

    # 	found = False

    # 	for detected_point in detected:

    # 		if bs_point[:2] == detected_point[1:3]:
    # 			found = True
    # 			break

    # 	if found == False:
    # 		false_positive.append(bs_point)

    print "FP: ", len(false_positive), "(", len(false_positive) * 100.0 / len(
        bus_stops), "%", ")"
    print "FN: ", len(
        false_negative), "(", len(false_negative) * 100.0 / len(gt), "%", ")"

    return detected, false_positive, false_negative
Пример #5
0
    if '54feet' in GROUND_TRUTH and s==22:
        s+=1
        continue
    df=pd.read_csv(input_file)
    p=len(df)
    j=0
    while j<p:

        check.append([float(df.iloc[j][0]),float(df.iloc[j][1])])
        j+=1
    s+=1

i=0
while i<length:
    for j in check:
        if get_spherical_distance(grd[i][0],j[0],grd[i][1],j[1])<10:
            test[i]=1
            
    i+=1

i=0
missing=[]
while i<length:
    if test[i]==0:
        cnt+=1
        missing.append(i)
    i+=1


text=open('record_local.txt','a')
text.write(GROUND_TRUTH+'\n')