Example #1
0
    def test_max_drift_filter_speed(self):
        '''Shall keep only slow drift '''
        x1, y1, x2, y2 = get_match_coords(self.keyPoints1, self.descr1,
                                          self.keyPoints2, self.descr2,
                                          ratio_test=0.7)
        x1f, y1f, x2f, y2f = max_drift_filter(self.n1, x1, y1,
                                          self.n2, x2, y2,
                                          max_speed=0.001)
        self.assertGreater(len(x1f), 0)
        self.assertGreater(len(x1), len(x1f))

        # remove time_coverage_start
        self.n1.vrt.dataset.SetMetadata({})

        # test that
        with self.assertRaises(ValueError):
            x1f, y1f, x2f, y2f = max_drift_filter(self.n1, x1, y1,
                                          self.n2, x2, y2,
                                          max_speed=0.3)


        x1f, y1f, x2f, y2f = max_drift_filter(self.n1, x1, y1,
                                          self.n2, x2, y2,
                                          max_drift=100)
        self.assertGreater(len(x1f), 0)
        self.assertGreater(len(x1), len(x1f))
Example #2
0
    def test_lstsq_filter(self):
        ''' Shall filter out not matching points '''
        x1, y1, x2, y2 = get_match_coords(self.keyPoints1, self.descr1,
                                          self.keyPoints2, self.descr2,
                                          ratio_test=0.8)

        x1f, y1f, x2f, y2f = lstsq_filter(x1, y1, x2, y2)
        self.assertTrue(len(x1) > len(x1f))
Example #3
0
    def test_get_distance_to_nearest_keypoint(self):
        ''' Shall create vector of distances '''
        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)

        dist = get_distance_to_nearest_keypoint(x1, y1, self.img1.shape)
        plt.imsave('sea_ice_drift_tests_%s.png' % inspect.currentframe().f_code.co_name,
                    dist)
        self.assertEqual(dist.shape, self.img1.shape)
Example #4
0
    def test_get_displacement_pix(self):
        ''' Shall find matching coordinates and plot quiver in pixel/line'''
        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)
        u, v = get_displacement_pix(self.n1, x1, y1, self.n2, x2, y2)

        plt.quiver(x1, y1, u, v)
        plt.savefig('sea_ice_drift_tests_%s.png' % inspect.currentframe().f_code.co_name)
        plt.close('all')
        self.assertEqual(len(u), len(x1))
Example #5
0
    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))
Example #6
0
    def test_interpolation_near(self):
        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)
        x2p1, y2p1 = interpolation_near(x1, y1, x2, y2, x1, y1)

        plt.subplot(1,2,1)
        plt.plot(x2, x2p1, '.')
        plt.subplot(1,2,2)
        plt.plot(y2, y2p1, '.')
        plt.savefig('sea_ice_drift_tests_%s.png' % inspect.currentframe().f_code.co_name)
        plt.close('all')
        self.assertEqual(len(x2p1), len(x1))
Example #7
0
    def test_get_drift_vectors(self):
        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)
        u, v, lon1, lat1, lon2, lat2 = get_drift_vectors(self.n1, x1, y1,
                                                   self.n2, x2, y2)

        plt.plot(lon1, lat1, '.')
        plt.plot(lon2, lat2, '.')
        plt.quiver(lon1, lat1, u, v, angles='xy', scale_units='xy', scale=0.25)
        plt.savefig('sea_ice_drift_tests_%s.png' % inspect.currentframe().f_code.co_name)
        plt.close('all')
        self.assertEqual(len(u), len(x1))
        self.assertEqual(len(v), len(x1))
Example #8
0
 def test_get_match_coords(self):
     ''' Shall find matching coordinates '''
     x1, y1, x2, y2 = get_match_coords(self.keyPoints1, self.descr1,
                                       self.keyPoints2, self.descr2)
     self.assertTrue(len(self.keyPoints1) > len(x1))
     self.assertTrue(len(self.keyPoints2) > len(x2))