Exemplo n.º 1
0
 def test_grid_filter(self):
     lons = np.array([-170, -30, 30, 170])
     lats = np.array([20, -40, 50, -80])
     swath_def = geometry.SwathDefinition(lons, lats)
     data = np.array([1, 2, 3, 4])
     filter_area = geometry.AreaDefinition('test', 'test', 'test', {
         'proj': 'eqc',
         'lon_0': 0.0,
         'lat_0': 0.0
     }, 8, 8, (-20037508.34, -10018754.17, 20037508.34, 10018754.17))
     filter = np.array([
         [1, 1, 1, 1, 0, 0, 0, 0],
         [1, 1, 1, 1, 0, 0, 0, 0],
         [1, 1, 1, 1, 0, 0, 0, 0],
         [1, 1, 1, 1, 0, 0, 0, 0],
         [0, 0, 0, 0, 1, 1, 1, 1],
         [0, 0, 0, 0, 1, 1, 1, 1],
         [0, 0, 0, 0, 1, 1, 1, 1],
         [0, 0, 0, 0, 1, 1, 1, 1],
     ])
     grid_filter = geo_filter.GridFilter(filter_area, filter)
     swath_def_f, data_f = grid_filter.filter(swath_def, data)
     expected = np.array([1, 4])
     self.assertTrue(np.array_equal(data_f, expected),
                     'Failed grid filtering data')
     expected_lons = np.array([-170, 170])
     expected_lats = np.array([20, -80])
     self.assertTrue(
         np.array_equal(swath_def_f.lons[:], expected_lons)
         and np.array_equal(swath_def_f.lats[:], expected_lats),
         'Failed finding grid filtering lon lats')
Exemplo n.º 2
0
 def test_grid_filter2D(self):
     lons = np.array([[-170, -30, 30, 170], [-170, -30, 30, 170]])
     lats = np.array([[20, -40, 50, -80], [25, -35, 55, -75]])
     swath_def = geometry.SwathDefinition(lons, lats)
     data1 = np.ones((2, 4))
     data2 = np.ones((2, 4)) * 2
     data3 = np.ones((2, 4)) * 3
     data = np.dstack((data1, data2, data3))
     filter_area = geometry.AreaDefinition('test', 'test', 'test', {
         'proj': 'eqc',
         'lon_0': 0.0,
         'lat_0': 0.0
     }, 8, 8, (-20037508.34, -10018754.17, 20037508.34, 10018754.17))
     filter = np.array([
         [1, 1, 1, 1, 0, 0, 0, 0],
         [1, 1, 1, 1, 0, 0, 0, 0],
         [1, 1, 1, 1, 0, 0, 0, 0],
         [1, 1, 1, 1, 0, 0, 0, 0],
         [0, 0, 0, 0, 1, 1, 1, 1],
         [0, 0, 0, 0, 1, 1, 1, 1],
         [0, 0, 0, 0, 1, 1, 1, 1],
         [0, 0, 0, 0, 1, 1, 1, 1],
     ])
     grid_filter = geo_filter.GridFilter(filter_area, filter, nprocs=2)
     swath_def_f, data_f = grid_filter.filter(swath_def, data)
     expected = np.array([[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3]])
     self.assertTrue(np.array_equal(data_f, expected),
                     'Failed 2D grid filtering data')
     expected_lons = np.array([-170, 170, -170, 170])
     expected_lats = np.array([20, -80, 25, -75])
     self.assertTrue(
         np.array_equal(swath_def_f.lons[:], expected_lons)
         and np.array_equal(swath_def_f.lats[:], expected_lats),
         'Failed finding 2D grid filtering lon lats')
Exemplo n.º 3
0
 def test_grid_filter_valid(self):
     lons = np.array([-170, -30, 30, 170])
     lats = np.array([20, -40, 50, -80])
     swath_def = geometry.SwathDefinition(lons, lats)
     filter_area = geometry.AreaDefinition('test', 'test', 'test',
                                           {'proj': 'eqc', 'lon_0': 0.0,
                                               'lat_0': 0.0},
                                           8, 8,
                                           (-20037508.34, -10018754.17, 20037508.34, 10018754.17))
     filter = np.array([[1, 1, 1, 1, 0, 0, 0, 0],
                        [1, 1, 1, 1, 0, 0, 0, 0],
                        [1, 1, 1, 1, 0, 0, 0, 0],
                        [1, 1, 1, 1, 0, 0, 0, 0],
                        [0, 0, 0, 0, 1, 1, 1, 1],
                        [0, 0, 0, 0, 1, 1, 1, 1],
                        [0, 0, 0, 0, 1, 1, 1, 1],
                        [0, 0, 0, 0, 1, 1, 1, 1],
                        ])
     grid_filter = geo_filter.GridFilter(filter_area, filter)
     valid_index = grid_filter.get_valid_index(swath_def)
     expected = np.array([1, 0, 0, 1])
     self.assertTrue(
         np.array_equal(valid_index, expected), 'Failed to find grid filter')