-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds cli and test to extract a cube from a cubelist (#2044)
* Adds cli and test to extract a cube from a cubelist * Formatting * update doc string
- Loading branch information
1 parent
6e4a898
commit fd6f3f8
Showing
5 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env python | ||
# (C) Crown copyright, Met Office. All rights reserved. | ||
# | ||
# This file is part of IMPROVER and is released under a BSD 3-Clause license. | ||
# See LICENSE in the root of the repository for full licensing details. | ||
"""Script to extract a cube from a cubelist""" | ||
|
||
from improver import cli | ||
|
||
|
||
@cli.clizefy | ||
@cli.with_output | ||
def process(cubes: cli.inputcubelist, *, name: str): | ||
"""Extract a single cube from a cubelist whose name matches | ||
the provided name. | ||
Args: | ||
cubes (iris.cube.CubeList): | ||
A cubelist containing exactly one cube with the provided name to | ||
be extracted. | ||
name (str): | ||
The name of the cube to be extracted. | ||
Returns: | ||
iris.cube.Cube: | ||
The extracted cube whose name matches the provided name. | ||
""" | ||
from improver.utilities.cube_extraction import cubelist_extract | ||
|
||
return cubelist_extract(cubes, name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# (C) Crown copyright, Met Office. All rights reserved. | ||
# | ||
# This file is part of IMPROVER and is released under a BSD 3-Clause license. | ||
# See LICENSE in the root of the repository for full licensing details. | ||
""" | ||
Tests for the cubelist-extract CLI | ||
""" | ||
|
||
import pytest | ||
|
||
from . import acceptance as acc | ||
|
||
pytestmark = [pytest.mark.acc, acc.skip_if_kgo_missing] | ||
CLI = acc.cli_name_with_dashes(__file__) | ||
run_cli = acc.run_cli(CLI) | ||
|
||
|
||
def test_basic(tmp_path): | ||
"""Test basic extraction""" | ||
kgo_dir = acc.kgo_root() / "cubelist-extract" | ||
kgo_path = kgo_dir / "kgo.nc" | ||
input_path = kgo_dir / "input_cubelist.nc" | ||
output_path = tmp_path / "output.nc" | ||
args = [input_path, "--name=grid_eastward_wind", "--output", output_path] | ||
run_cli(args) | ||
acc.compare(output_path, kgo_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters