Beispiel #1
0
class TestMatrixContentSingle(unittest.TestCase):
    def setUp(self):
        self.kernel = TDKernelDMVW(min_x,
                                   min_y,
                                   max_x,
                                   max_y,
                                   cell_size,
                                   kernel_size,
                                   wind_scale,
                                   time_scale,
                                   low_confidence_calculation_zero=True,
                                   evaluation_radius=evaluation_radius)

    def calculate(self):
        self.kernel.set_measurements(positions_x, positions_y, concentrations,
                                     timestamps, wind_speeds, wind_directions)
        self.kernel.calculate_maps()

    def testMeanValues(self):
        self.calculate()

        # Implies, that x is the first index (0)
        self.assertEqual(71, self.kernel.mean_map.shape[0])
        self.assertEqual(51, self.kernel.mean_map.shape[1])

        self.assertTrue(self.kernel.importance_weight_map[20][40] >
                        self.kernel.importance_weight_map[40][20])
        self.assertTrue(
            self.kernel.mean_map[20][40] > self.kernel.mean_map[40][20])
Beispiel #2
0
 def setUp(self):
     self.kernel = TDKernelDMVW(min_x,
                                min_y,
                                max_x,
                                max_y,
                                cell_size,
                                kernel_size,
                                wind_scale,
                                time_scale,
                                low_confidence_calculation_zero=True,
                                evaluation_radius=evaluation_radius)
Beispiel #3
0
evaluation_radius = 10 * kernel_size

# Create dummy measurement vectors
positions_x = [4, 6.5, 15]
positions_y = [2, 6.5, 15]
concentrations = [2, 2, 2]
wind_directions = [0, 60, 0]
wind_speeds = [0, 1, 0]
timestamps = [0, 60, 60]

# call Kernel
kernel = TDKernelDMVW(min_x,
                      min_y,
                      max_x,
                      max_y,
                      cell_size,
                      kernel_size,
                      wind_scale,
                      time_scale,
                      low_confidence_calculation_zero=True,
                      evaluation_radius=evaluation_radius)
kernel.set_measurements(positions_x, positions_y, concentrations, timestamps,
                        wind_speeds, wind_directions)
kernel.calculate_maps()

# Show result as map
plt.figure()
plt.title("mean map")
plt.contourf(kernel.cell_grid_x, kernel.cell_grid_y, kernel.mean_map)
plt.colorbar()

plt.figure()
Beispiel #4
0
class TestMatrixShape(unittest.TestCase):
    def setUp(self):
        self.kernel = TDKernelDMVW(min_x,
                                   min_y,
                                   max_x,
                                   max_y,
                                   cell_size,
                                   kernel_size,
                                   wind_scale,
                                   time_scale,
                                   low_confidence_calculation_zero=True,
                                   evaluation_radius=evaluation_radius)

    def calculate(self):
        self.kernel.set_measurements(positions_x, positions_y, concentrations,
                                     timestamps, wind_speeds, wind_directions)
        self.kernel.calculate_maps()

    def testBBox(self):

        self.assertEqual(number_of_x_cells, self.kernel.number_of_x_cells)
        self.assertEqual(number_of_y_cells, self.kernel.number_of_y_cells)

        self.assertEqual(min_x, self.kernel.min_x)
        self.assertEqual(min_y, self.kernel.min_y)

        # BBox is increased to handle python floats properly
        self.assertEqual(min_x + round(number_of_x_cells * cell_size, 10),
                         self.kernel.max_x)
        self.assertEqual(min_y + round(number_of_y_cells * cell_size, 10),
                         self.kernel.max_y)

    def testCellGrids(self):
        self.assertEqual(number_of_x_cells, self.kernel.cell_grid_x.shape[0])
        self.assertEqual(number_of_x_cells, self.kernel.cell_grid_y.shape[0])
        self.assertEqual(number_of_y_cells, self.kernel.cell_grid_x.shape[1])
        self.assertEqual(number_of_y_cells, self.kernel.cell_grid_y.shape[1])

    def testMeanShape(self):
        self.calculate()
        self.assertEqual(number_of_x_cells, self.kernel.mean_map.shape[0])
        self.assertEqual(number_of_y_cells, self.kernel.mean_map.shape[1])

    def testVarianceShape(self):
        self.calculate()
        self.assertEqual(number_of_x_cells, self.kernel.variance_map.shape[0])
        self.assertEqual(number_of_y_cells, self.kernel.variance_map.shape[1])

    def testConfidenceShape(self):
        self.calculate()
        self.assertEqual(number_of_x_cells,
                         self.kernel.confidence_map.shape[0])
        self.assertEqual(number_of_y_cells,
                         self.kernel.confidence_map.shape[1])

    def testImportanceShape(self):
        self.calculate()
        self.assertEqual(number_of_x_cells,
                         self.kernel.importance_weight_map.shape[0])
        self.assertEqual(number_of_y_cells,
                         self.kernel.importance_weight_map.shape[1])