Пример #1
0
    def test_call(self):
        # Test that :func:`iris.analysis.trajectory.interpolate` is called by
        # `Trajectory.interpolate`.
        cube = simple_3d()
        to_patch = 'iris.analysis.trajectory.interpolate'
        waypoints = [{'latitude': 40, 'longitude': 40},
                     {'latitude': 0, 'longitude': 0}]
        sample_count = 3
        trajectory = Trajectory(waypoints, sample_count=sample_count)

        with mock.patch(to_patch, return_value=cube) as mock_interpolate:
            trajectory.interpolate(cube)
        mock_interpolate.assert_called_once()
Пример #2
0
    def test_call(self):
        # Test that :func:`iris.analysis.trajectory.interpolate` is called by
        # `Trajectory.interpolate`.
        cube = simple_3d()
        to_patch = 'iris.analysis.trajectory.interpolate'
        waypoints = [{'latitude': 40, 'longitude': 40},
                     {'latitude': 0, 'longitude': 0}]
        sample_count = 3
        trajectory = Trajectory(waypoints, sample_count=sample_count)

        with mock.patch(to_patch, return_value=cube) as mock_interpolate:
            trajectory.interpolate(cube)
        mock_interpolate.assert_called_once()
Пример #3
0
    def test_cube__anon_dim(self):
        cube = simple_4d_with_hybrid_height()
        cube.remove_coord('model_level_number')  # Make cube dim 1 anonymous.
        waypoints = [{
            'grid_latitude': 21,
            'grid_longitude': 31
        }, {
            'grid_latitude': 23,
            'grid_longitude': 33
        }]
        sample_count = 4
        new_coord_name = 'index'
        trajectory = Trajectory(waypoints, sample_count=sample_count)
        result = trajectory.interpolate(cube)

        dim_names, named_dims, anon_dims = self._result_cube_metadata(result)
        new_coord = result.coord(new_coord_name)
        exp_named_dims = [0, 2]
        exp_anon_dims = [1]

        self.assertEqual(result.ndim, cube.ndim - 1)
        self.assertIn(new_coord_name, dim_names)
        self.assertEqual(named_dims, exp_named_dims)
        self.assertEqual(anon_dims, exp_anon_dims)
        self.assertEqual(len(new_coord.points), sample_count)
Пример #4
0
    def test_cube__simple_3d(self):
        # Test that an 'index' coord is added to the resultant cube.
        cube = simple_3d()
        waypoints = [
            {
                "latitude": 40,
                "longitude": 40
            },
            {
                "latitude": 0,
                "longitude": 0
            },
        ]
        sample_count = 3
        new_coord_name = "index"
        trajectory = Trajectory(waypoints, sample_count=sample_count)
        result = trajectory.interpolate(cube)

        dim_names, named_dims, anon_dims = self._result_cube_metadata(result)
        new_coord = result.coord(new_coord_name)
        exp_named_dims = [0, 1]

        self.assertEqual(result.ndim, cube.ndim - 1)
        self.assertIn(new_coord_name, dim_names)
        self.assertEqual(named_dims, exp_named_dims)
        self.assertIsNone(anon_dims)
        self.assertEqual(len(new_coord.points), sample_count)
Пример #5
0
    def test_cube__simple_3d(self):
        # Test that an 'index' coord is added to the resultant cube.
        cube = simple_3d()
        waypoints = [{'latitude': 40, 'longitude': 40},
                     {'latitude': 0, 'longitude': 0}]
        sample_count = 3
        new_coord_name = 'index'
        trajectory = Trajectory(waypoints, sample_count=sample_count)
        result = trajectory.interpolate(cube)

        dim_names, named_dims, anon_dims = self._result_cube_metadata(result)
        new_coord = result.coord(new_coord_name)
        exp_named_dims = [0, 1]

        self.assertEqual(result.ndim, cube.ndim - 1)
        self.assertIn(new_coord_name, dim_names)
        self.assertEqual(named_dims, exp_named_dims)
        self.assertIsNone(anon_dims)
        self.assertEqual(len(new_coord.points), sample_count)
Пример #6
0
    def test_cube__anon_dim(self):
        cube = simple_4d_with_hybrid_height()
        cube.remove_coord('model_level_number')  # Make cube dim 1 anonymous.
        waypoints = [{'grid_latitude': 21, 'grid_longitude': 31},
                     {'grid_latitude': 23, 'grid_longitude': 33}]
        sample_count = 4
        new_coord_name = 'index'
        trajectory = Trajectory(waypoints, sample_count=sample_count)
        result = trajectory.interpolate(cube)

        dim_names, named_dims, anon_dims = self._result_cube_metadata(result)
        new_coord = result.coord(new_coord_name)
        exp_named_dims = [0, 2]
        exp_anon_dims = [1]

        self.assertEqual(result.ndim, cube.ndim - 1)
        self.assertIn(new_coord_name, dim_names)
        self.assertEqual(named_dims, exp_named_dims)
        self.assertEqual(anon_dims, exp_anon_dims)
        self.assertEqual(len(new_coord.points), sample_count)