示例#1
0
 def test_bottom_left_cell(self):
     xi = np.array([[0, 1], [0, 1]], dtype=np.float64)
     yi = np.array([[self.ny - 1, self.ny - 1], [self.ny, self.ny]],
                   dtype=np.float64)
     raster(self.weights, xi, yi)
     self.assertEqual(self.weights.sum(), 255)
     self.assertEqual(self.weights[self.ny - 1, 0], 255)
示例#2
0
 def test_top_right_cell(self):
     xi = np.array([[self.nx - 1, self.nx], [self.nx - 1, self.nx]],
                   dtype=np.float64)
     yi = np.array([[0, 0], [1, 1]], dtype=np.float64)
     raster(self.weights, xi, yi)
     self.assertEqual(self.weights.sum(), 255)
     self.assertEqual(self.weights[0, self.nx - 1], 255)
示例#3
0
 def test_inset_by_one_cell(self):
     xi = np.array([[1, self.nx - 1], [1, self.nx - 1]], dtype=np.float64)
     yi = np.array([[1, 1], [self.ny - 1, self.ny - 1]], dtype=np.float64)
     raster(self.weights, xi, yi)
     expected = np.ones((self.ny, self.nx), dtype=np.float64) * 255
     expected[0, :] = expected[-1, :] = 0
     expected[:, 0] = expected[:, -1] = 0
     assert_array_equal(self.weights, expected)
示例#4
0
 def test_inset_by_one_cell(self):
     xi = np.array([[1, self.nx - 1], [1, self.nx - 1]], dtype=np.float64)
     yi = np.array([[1, 1], [self.ny - 1, self.ny - 1]], dtype=np.float64)
     raster(self.weights, xi, yi)
     expected = np.ones((self.ny, self.nx), dtype=np.float64) * 255
     expected[0, :] = expected[-1, :] = 0
     expected[:, 0] = expected[:, -1] = 0
     assert_array_equal(self.weights, expected)
示例#5
0
 def test_inset_by_half_cell(self):
     xi = np.array([[0.5, self.nx - 0.5], [0.5, self.nx - 0.5]], dtype=np.float64)
     yi = np.array([[0.5, 0.5], [self.ny - 0.5, self.ny - 0.5]], dtype=np.float64)
     raster(self.weights, xi, yi)
     expected = np.ones((self.ny, self.nx), dtype=np.float64) * 255
     half, quarter = 255 // 2, 255 // 4
     expected[0, :] = expected[-1, :] = half
     expected[:, 0] = expected[:, -1] = half
     expected[0, 0] = expected[0, -1] = quarter
     expected[-1, 0] = expected[-1, -1] = quarter
     assert_array_equal(self.weights, expected)
示例#6
0
 def test_inset_by_half_cell(self):
     xi = np.array([[0.5, self.nx - 0.5], [0.5, self.nx - 0.5]],
                   dtype=np.float64)
     yi = np.array([[0.5, 0.5], [self.ny - 0.5, self.ny - 0.5]],
                   dtype=np.float64)
     raster(self.weights, xi, yi)
     expected = np.ones((self.ny, self.nx), dtype=np.float64) * 255
     half, quarter = 255 // 2, 255 // 4
     expected[0, :] = expected[-1, :] = half
     expected[:, 0] = expected[:, -1] = half
     expected[0, 0] = expected[0, -1] = quarter
     expected[-1, 0] = expected[-1, -1] = quarter
     assert_array_equal(self.weights, expected)
示例#7
0
 def test_rotated(self):
     xi = np.array([[1.5, 4.5], [3.5, 6.5]], dtype=np.float64)
     yi = np.array([[3.5, 0.5], [5.5, 2.5]], dtype=np.float64)
     raster(self.weights, xi, yi)
     expected = np.zeros((self.shape), dtype=np.uint8)
     full, half, quarter = 255, 255 // 2, 255 // 4
     # corners ...
     expected[3, 1] = expected[0, 4] = quarter
     expected[5, 3] = expected[2, 6] = quarter
     # edges ...
     expected[2, 2] = expected[1, 3] = half
     expected[4, 2] = half
     expected[1, 5] = half
     expected[4, 4] = expected[3, 5] = half
     # inner ...
     expected[1, 4] = full
     expected[2, 3] = expected[2, 4] = expected[2, 5] = full
     expected[3, 2] = expected[3, 3] = expected[3, 4] = full
     expected[4, 3] = full
     assert_array_equal(self.weights, expected)
示例#8
0
 def test_rotated(self):
     xi = np.array([[1.5, 4.5], [3.5, 6.5]], dtype=np.float64)
     yi = np.array([[3.5, 0.5], [5.5, 2.5]], dtype=np.float64)
     raster(self.weights, xi, yi)
     expected = np.zeros((self.shape), dtype=np.uint8)
     full, half, quarter = 255, 255 // 2, 255 // 4
     # corners ...
     expected[3, 1] = expected[0, 4] = quarter
     expected[5, 3] = expected[2, 6] = quarter
     # edges ...
     expected[2, 2] = expected[1, 3] = half
     expected[4, 2] = half
     expected[1, 5] = half
     expected[4, 4] = expected[3, 5] = half
     # inner ...
     expected[1, 4] = full
     expected[2, 3] = expected[2, 4] = expected[2, 5] = full
     expected[3, 2] = expected[3, 3] = expected[3, 4] = full
     expected[4, 3] = full
     assert_array_equal(self.weights, expected)
示例#9
0
 def test_full_coverage(self):
     xi = np.array([[0, self.nx], [0, self.nx]], dtype=np.float64)
     yi = np.array([[0, 0], [self.ny, self.ny]], dtype=np.float64)
     raster(self.weights, xi, yi)
     expected = np.ones((self.ny, self.nx), dtype=np.float64) * 255
     assert_array_equal(self.weights, expected)
示例#10
0
 def test_xi_bad_shape(self):
     xi = self.xi.flatten()
     with self.assertRaisesRegexp(ValueError, self.emsg):
         raster(self.weights, xi, self.yi)
示例#11
0
 def test_weights_bad_shape(self):
     weights = self.weights.flatten()
     with assertRaisesRegex(self, ValueError, self.emsg):
         raster(weights, self.xi, self.yi)
示例#12
0
 def test_weights_bad_shape(self):
     weights = self.weights.flatten()
     with self.assertRaisesRegexp(ValueError, self.emsg):
         raster(weights, self.xi, self.yi)
示例#13
0
 def test_yi_bad_dtype(self):
     yi = np.arange(4).reshape(2, 2)
     with self.assertRaisesRegexp(ValueError, self.emsg):
         raster(self.weights, self.xi, yi)
示例#14
0
 def test_weights_bad_dtype(self):
     weights = np.zeros((5, 5))
     with self.assertRaisesRegexp(ValueError, self.emsg):
         raster(weights, self.xi, self.yi)
示例#15
0
 def test_full_coverage(self):
     xi = np.array([[0, self.nx], [0, self.nx]], dtype=np.float64)
     yi = np.array([[0, 0], [self.ny, self.ny]], dtype=np.float64)
     raster(self.weights, xi, yi)
     expected = np.ones((self.ny, self.nx), dtype=np.float64) * 255
     assert_array_equal(self.weights, expected)
示例#16
0
 def test_weights_bad_dtype(self):
     weights = np.zeros((5, 5))
     with assertRaisesRegex(self, ValueError, self.emsg):
         raster(weights, self.xi, self.yi)
示例#17
0
 def test_yi_bad_dtype(self):
     yi = np.arange(4).reshape(2, 2)
     with assertRaisesRegex(self, ValueError, self.emsg):
         raster(self.weights, self.xi, yi)
示例#18
0
 def test_yi_bad_shape(self):
     yi = self.yi.flatten()
     with self.assertRaisesRegexp(ValueError, self.emsg):
         raster(self.weights, self.xi, yi)
示例#19
0
 def test_yi_bad_shape(self):
     yi = self.yi.flatten()
     with assertRaisesRegex(self, ValueError, self.emsg):
         raster(self.weights, self.xi, yi)
示例#20
0
 def test_top_right_cell(self):
     xi = np.array([[self.nx - 1, self.nx], [self.nx - 1, self.nx]], dtype=np.float64)
     yi = np.array([[0, 0], [1, 1]], dtype=np.float64)
     raster(self.weights, xi, yi)
     self.assertEqual(self.weights.sum(), 255)
     self.assertEqual(self.weights[0, self.nx - 1], 255)
示例#21
0
 def test_bottom_left_cell(self):
     xi = np.array([[0, 1], [0, 1]], dtype=np.float64)
     yi = np.array([[self.ny - 1, self.ny - 1], [self.ny, self.ny]], dtype=np.float64)
     raster(self.weights, xi, yi)
     self.assertEqual(self.weights.sum(), 255)
     self.assertEqual(self.weights[self.ny - 1, 0], 255)
示例#22
0
 def test_xi_bad_dtype(self):
     xi = np.arange(4).reshape(2, 2)
     with self.assertRaisesRegexp(ValueError, self.emsg):
         raster(self.weights, xi, self.yi)