Beispiel #1
0
 def test_preserve_dimensions_input(self):
     """Test that the dimensions on the output cube are the same as the
        input cube, apart from the collapsed dimension.
        Add threshold and realization coordinates and check they are in the
        right place after collapsing the topographic_zone coordinate."""
     nbhood_cube = self.weights_cube.copy()
     nbhood_cube.remove_coord("realization")
     nbhood_cube = add_dimensions_to_cube(
         nbhood_cube, {"threshold": 3, "realization": 4})
     result = self.plugin.process(nbhood_cube)
     expected_dims = [coord for coord in nbhood_cube.dim_coords
                      if coord.long_name is not "topographic_zone"]
     self.assertEqual(result.dim_coords, tuple(expected_dims))
     self.assertEqual(result.coord_dims("realization"), (0,))
     self.assertEqual(result.coord_dims("threshold"), (1,))
     self.assertEqual(result.coord_dims("projection_y_coordinate"), (2,))
     self.assertEqual(result.coord_dims("projection_x_coordinate"), (3,))
Beispiel #2
0
 def test_multidimensional_neighbourhood_input(self):
     """Test that we can collapse the right dimension when there
        are additional leading dimensions like threshold."""
     nbhooded_cube = add_dimensions_to_cube(self.nbhooded_cube,
                                            {"threshold": 3})
     expected_result = np.array([[[0.12, 0.13, 0.2, 0.2, 0.2],
                                  [0.13, 0.17, 0.2, 0.2, 0.2],
                                  [0.17, 0.19, 0.2, 0.2, 0.2],
                                  [0.2, 0.2, 0.2, 0.19, 0.15],
                                  [0.2, 0.2, 0.2, 0.16, 0.12]],
                                 [[0.12, 0.13, 0.2, 0.2, 0.2],
                                  [0.13, 0.17, 0.2, 0.2, 0.2],
                                  [0.17, 0.19, 0.2, 0.2, 0.2],
                                  [0.2, 0.2, 0.2, 0.19, 0.15],
                                  [0.2, 0.2, 0.2, 0.16, 0.12]],
                                 [[0.12, 0.13, 0.2, 0.2, 0.2],
                                  [0.13, 0.17, 0.2, 0.2, 0.2],
                                  [0.17, 0.19, 0.2, 0.2, 0.2],
                                  [0.2, 0.2, 0.2, 0.19, 0.15],
                                  [0.2, 0.2, 0.2, 0.16, 0.12]]])
     result = self.plugin.process(nbhooded_cube)
     self.assertArrayAlmostEqual(expected_result, result.data)