def plot_intersects(lat_a, lon_a, doa_a, lat_b, lon_b, doa_b, max_distance=50000): # plot another point on the lob # v.direct(lat_a, lon_a, doa_a, d) # returns (lat_a2, lon_a2) # Get normal to planes containing great circles # np.cross product of vector to each point from the origin coord_a2 = v.direct(lat_a, lon_a, doa_a, d) coord_b2 = v.direct(lat_b, lon_b, doa_b, d) plane_a = plot_polar(lat_a, lon_a, *coord_a2) plane_b = plot_polar(lat_b, lon_b, *coord_b2) N1 = np.cross(plane_a[0], plane_a[1]) N2 = np.cross(plane_b[0], plane_b[1]) # Find line of intersection between two planes L = np.cross(N1, N2) # Find two intersection points X1 = L / np.sqrt(L[0]**2 + L[1]**2 + L[2]**2) X2 = -X1 mag = lambda q: np.sqrt(np.vdot(q, q)) dist1 = mag(X1 - plane_a[0]) dist2 = mag(X2 - plane_a[0]) #return the (lon_lat pair of the closer intersection) if dist1 < dist2: i_lat = math.asin(X1[2]) * 180. / np.pi i_long = math.atan2(X1[1], X1[0]) * 180. / np.pi else: i_lat = math.asin(X2[2]) * 180. / np.pi i_long = math.atan2(X2[1], X2[0]) * 180. / np.pi check_bearing = v.get_heading((lat_a, lon_a), (i_lat, i_long)) if abs(check_bearing - doa_a) < 5: km = v.inverse([lat_a, lon_a], [i_lat, i_long]) if km[0] < max_distance: return (i_lat, i_long) else: return None
def rx(rx_location, freq, tx_location, heading=0, tx_active=True): # def rx(station_id, DOA_res_fd, rx_location, freq, tx_location, heading=0, tx_active = True): dist_and_heading = vincenty.inverse(rx_location, tx_location) distance_to_target = dist_and_heading[0] raw_doa = dist_and_heading[1] pwr = pathloss(distance_to_target, freq) if tx_active and pwr > 1 == True: conf = min(int(round(0.1 * pwr**2, 0)), 255) err_factor = 30 * math.exp(-conf / 8) + 3 doa_error = int(random.triangular(-err_factor, err_factor, 0)) doa = round(doa_error + raw_doa - heading) if doa < 0: doa += 360 elif doa > 359: doa -= 360 else: pwr, conf, doa = nosignal() #Add Error: doa = 360 - doa #Simulates KSDR Inverted Bearing return freq, rx_location, heading, doa, conf, pwr
def interpolate_two_points(coord1, coord2, speed, resolution): if coord1 == coord2: return coord1 distance_and_heading = vincenty.inverse(coord1, coord2) distance = distance_and_heading[0] #print(f"Distance: {distance}") heading = distance_and_heading[1] #print(f"Heading: {heading}") nsteps = round(((distance / speed) * (1 / resolution)) / (1 / resolution)) / resolution #print(f"N Steps: {nsteps}") step_distance = speed * resolution #print(f"Step Distance: {step_distance}") steps = [coord1] current_coord = coord1 steps_left = nsteps while steps_left > 0: #print(f"In the loop, {steps_left} to go.") next_coord = vincenty.direct(current_coord[0], current_coord[1], heading, step_distance) #print(f"Plotted: {next_coord}") steps.append(tuple(next_coord)) current_coord = next_coord steps_left -= 1 return steps
def process_data(database_name, outfile): conn = sqlite3.connect(database_name) c = conn.cursor() intersect_list = [] try: # c.execute("SELECT COUNT(*) FROM intersects") # n_intersects = int(c.fetchone()[0]) c.execute("SELECT longitude, latitude, time FROM intersects") intersect_array = np.array(c.fetchall()) except sqlite3.OperationalError: n_intersects = 0 intersect_array = np.array([]) likely_location = [] # weighted_location = [] ellipsedata = [] n_std=3.0 if intersect_array.size != 0: if ms.eps > 0: X = StandardScaler().fit_transform(intersect_array[:,0:2]) # Compute DBSCAN db = DBSCAN(eps=ms.eps, min_samples=ms.min_samp).fit(X) core_samples_mask = np.zeros_like(db.labels_, dtype=bool) core_samples_mask[db.core_sample_indices_] = True labels = db.labels_ intersect_array = np.column_stack((intersect_array, labels)) # Number of clusters in labels, ignoring noise if present. n_clusters_ = len(set(labels)) - (1 if -1 in labels else 0) n_noise_ = list(labels).count(-1) clear(debugging) print('Number of clusters: %d' % n_clusters_) print('Outliers Removed: %d' % n_noise_) for x in range(n_clusters_): cluster = np.array([]).reshape(0,3) for y in range(len(intersect_array)): if intersect_array[y][-1] == x: cluster = np.concatenate((cluster, [intersect_array[y][0:-1]]), axis = 0) # weighted_location.append(np.average(cluster[:,0:2], weights=cluster[:,2], axis=0).tolist()) clustermean = np.mean(cluster[:,0:2], axis=0) likely_location.append(clustermean.tolist()) cov = np.cov(cluster[:,0], cluster[:,1]) a = cov[0,0] b = cov[0,1] c = cov[1,1] lam1 = a+c/2 + np.sqrt((a-c/2)**2 + b**2) lam2 = a+c/2 - np.sqrt((a-c/2)**2 + b**2) pearson = b/np.sqrt(a * c) ell_radius_x = np.sqrt(1 + pearson) * np.sqrt(a) * n_std ell_radius_y = np.sqrt(1 - pearson) * np.sqrt(c) * n_std axis_x = v.inverse(Reverse(clustermean.tolist()), (ell_radius_x + clustermean[1], clustermean[0]))[0] axis_y = v.inverse(Reverse(clustermean.tolist()), (clustermean[1], ell_radius_y + clustermean[0]))[0] if b == 0 and a >= c: rotation = 0 elif b == 0 and a < c: rotation = np.pi/2 else: rotation = math.atan2(lam1 - a, b) ellipsedata.append([axis_x, axis_y, rotation, *clustermean.tolist()]) for x in likely_location: print(Reverse(x)) # else: # likely_location = None for x in intersect_array: try: if x[-1] >= 0: intersect_list.append(x[0:3].tolist()) except IndexError: intersect_list.append(x.tolist()) else: print("No Intersections.") # return None return likely_location, intersect_list, ellipsedata