Пример #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)