def max_drift_filter(n1, x1, y1, n2, x2, y2, max_speed=0.5, max_drift=None, **kwargs): ''' Filter out too high drift (m/s) Parameters ---------- n1 : First Nansat object x1 : 1D vector - X coordinates of keypoints on image 1 y1 : 1D vector - Y coordinates of keypoints on image 1 n2 : Second Nansat object x2 : 1D vector - X coordinates of keypoints on image 2 y2 : 1D vector - Y coordinates of keypoints on image 2 max_speed : float - maximum allowed ice drift speed, m/s max_drift : float - maximum allowed drift distance, meters Returns ------- x1 : 1D vector - filtered source X coordinates on img1, pix y1 : 1D vector - filtered source Y coordinates on img1, pix x2 : 1D vector - filtered destination X coordinates on img2, pix y2 : 1D vector - filtered destination Y coordinates on img2, pix Note ---- If time_coverage_start is not avaialabe from input data then the <max_speed> threshold is not used and the user should set value for <max_drift>. ''' # chack if input datasets have time stamp try: n1_time_coverage_start = n1.time_coverage_start n2_time_coverage_start = n2.time_coverage_start except ValueError: data_has_timestamp = False else: data_has_timestamp = True if data_has_timestamp: # if datasets have timestamp compare with speed gpi = get_speed_ms(n1, x1, y1, n2, x2, y2) <= max_speed elif max_drift is not None: # if datasets don't have timestamp compare with displacement gpi = 1000.*get_displacement_km(n1, x1, y1, n2, x2, y2) <= max_drift else: # if max displacement is not given - raise error raise ValueError(''' Error while filtering matching vectors! Input data does not have time stamp, and <max_drift> is not set. Either use data supported by Nansat, or provide a value for <max_drift> - maximum allowed ice displacement between images (meters). Examples: uft, vft, lon1ft, lat1ft, lon2ft, lat2ft = sid.get_drift_FT(max_drift=10000) x1, y1, x2, y2 = feature_tracking(n1, n2, max_drift=10000) Vectors with displacement higher than <max_drift> will be removed. ''') print('MaxDrift filter: %d -> %d' % (len(x1), len(gpi[gpi]))) return x1[gpi], y1[gpi], x2[gpi], y2[gpi]
def test_get_displacement_km(self): ''' Shall find matching coordinates and plot quiver in lon/lat''' keyPoints1, descr1 = find_key_points(self.img1, nFeatures=self.nFeatures) keyPoints2, descr2 = find_key_points(self.img2, nFeatures=self.nFeatures) x1, y1, x2, y2 = get_match_coords(keyPoints1, descr1, keyPoints2, descr2) h = get_displacement_km(self.n1, x1, y1, self.n2, x2, y2) plt.scatter(x1, y1, 30, h) plt.colorbar() plt.savefig('sea_ice_drift_tests_%s.png' % inspect.currentframe().f_code.co_name) plt.close('all') self.assertTrue(len(h) == len(x1))