Beispiel #1
0
 def test_basic(self):
     """Test function returns a cube with expected metadata"""
     halo_size_km = 162.
     result = create_cube_with_halo(self.cube, 1000. * halo_size_km)
     self.assertIsInstance(result, iris.cube.Cube)
     self.assertEqual(result.name(), 'grid_with_halo')
     self.assertFalse(result.attributes)
Beispiel #2
0
    def test_values(self):
        """Test coordinate values with standard halo radius (rounds down to 1
        grid cell)"""
        halo_size_km = 162.

        x_min = self.cube.coord(axis='x').points[0] - self.grid_spacing
        x_max = self.cube.coord(axis='x').points[-1] + self.grid_spacing
        expected_x_points = np.arange(x_min, x_max + 1, self.grid_spacing)
        y_min = self.cube.coord(axis='y').points[0] - self.grid_spacing
        y_max = self.cube.coord(axis='y').points[-1] + self.grid_spacing
        expected_y_points = np.arange(y_min, y_max + 1, self.grid_spacing)

        result = create_cube_with_halo(self.cube, 1000. * halo_size_km)
        self.assertSequenceEqual(result.data.shape, (13, 13))
        self.assertArrayAlmostEqual(
            result.coord(axis='x').points, expected_x_points)
        self.assertArrayAlmostEqual(
            result.coord(axis='y').points, expected_y_points)

        # check explicitly that the original grid remains an exact subset of
        # the output cube (ie that padding hasn't shifted the existing grid)
        self.assertArrayAlmostEqual(
            result.coord(axis='x').points[1:-1],
            self.cube.coord(axis='x').points)
        self.assertArrayAlmostEqual(
            result.coord(axis='y').points[1:-1],
            self.cube.coord(axis='y').points)
def process(cube, halo_radius=162000.0):
    """Generate a zeroed grid with halo from a source cube.

    Create a template cube defining a new grid by adding a fixed width halo on
    all sides to the input cube grid. The cube contains no meaningful data.

    Args:
        cube (iris.cube.Cube):
            The cube to be processed.
        halo_radius (float):
            Radius in metres of which to pad the input grid.
            Default is 162,000

    Returns:
        result (iris.cube.Cube):
            The processed Cube defining the halo-padded grid (data set to 0)
    """
    result = create_cube_with_halo(cube, halo_radius)
    return result
def process(cube: cli.inputcube, *, halo_radius: float = 162000.0):
    """Generate a zeroed grid with halo from a source cube.

    Create a template cube defining a new grid by adding a fixed width halo on
    all sides to the input cube grid. The cube contains no meaningful data.

    Args:
        cube (iris.cube.Cube):
            Contains data on the source grid.
        halo_radius (float):
            Radius in metres of which to pad the input grid.

    Returns:
        iris.cube.Cube:
            The processed cube defining the halo-padded grid (data set to 0)
    """
    from improver.utilities.pad_spatial import create_cube_with_halo

    result = create_cube_with_halo(cube, halo_radius)
    return result
def main(argv=None):
    """Generate target grid with a halo around the source file grid."""

    parser = ArgParser(description='Generate grid with halo from a source '
                       'domain input file. The grid is populated with zeroes.')
    parser.add_argument('input_file',
                        metavar='INPUT_FILE',
                        help="NetCDF file "
                        "containing data on a source grid.")
    parser.add_argument('output_file',
                        metavar='OUTPUT_FILE',
                        help="NetCDF "
                        "file defining the target grid with additional halo.")
    parser.add_argument('--halo_radius',
                        metavar='HALO_RADIUS',
                        default=162000,
                        type=float,
                        help="Size of halo (in m) with which to "
                        "pad the input grid.  Default is 162 000 m.")
    args = parser.parse_args(args=argv)

    cube = load_cube(args.input_file)
    halo_cube = create_cube_with_halo(cube, args.halo_radius)
    save_netcdf(halo_cube, args.output_file)