|
5 | 5 | import pytest |
6 | 6 | from cf_units import Unit |
7 | 7 | from iris import NameConstraint |
8 | | -from iris.coords import DimCoord |
| 8 | +from iris.coords import AuxCoord, DimCoord |
9 | 9 | from iris.cube import Cube, CubeList |
| 10 | +from iris.util import new_axis |
10 | 11 |
|
11 | 12 | import esmvalcore.cmor._fixes.icon.icon_xpp |
12 | 13 | from esmvalcore.cmor._fixes.fix import GenericFix |
|
18 | 19 | Gpp, |
19 | 20 | Hfls, |
20 | 21 | Hfss, |
| 22 | + Msftmz, |
21 | 23 | Rlut, |
22 | 24 | Rlutcs, |
23 | 25 | Rsutcs, |
@@ -704,6 +706,64 @@ def test_hfss_fix(cubes_regular_grid): |
704 | 706 | np.testing.assert_allclose(fixed_cube.data, [[[0.0, -1.0], [-2.0, -3.0]]]) |
705 | 707 |
|
706 | 708 |
|
| 709 | +# Test msftmz (for extra fix) |
| 710 | + |
| 711 | + |
| 712 | +def test_get_msftmz_fix(): |
| 713 | + """Test getting of fix.""" |
| 714 | + fix = Fix.get_fixes("ICON", "ICON-XPP", "Omon", "msftmz") |
| 715 | + assert fix == [Msftmz(None), AllVars(None), GenericFix(None)] |
| 716 | + |
| 717 | + |
| 718 | +def test_msftmz_fix(cubes_regular_grid): |
| 719 | + """Test fix.""" |
| 720 | + depth_coord = AuxCoord( |
| 721 | + 10.0, |
| 722 | + standard_name="depth", |
| 723 | + long_name="depth below sea", |
| 724 | + units="m", |
| 725 | + attributes={"positive": "down"}, |
| 726 | + ) |
| 727 | + cube = cubes_regular_grid[0][..., [0]] |
| 728 | + cube.coord("latitude").var_name = "lat" |
| 729 | + cube.add_aux_coord(depth_coord, ()) |
| 730 | + cube = new_axis(cube, "depth") |
| 731 | + cube.transpose([1, 0, 2, 3]) |
| 732 | + cubes = CubeList([cube.copy() * 0.0, cube.copy() * 1.0, cube.copy() * 2.0]) |
| 733 | + cubes[0].var_name = "atlantic_moc" |
| 734 | + cubes[0].units = "kg s-1" |
| 735 | + cubes[1].var_name = "pacific_moc" |
| 736 | + cubes[1].units = "kg s-1" |
| 737 | + cubes[2].var_name = "global_moc" |
| 738 | + cubes[2].units = "kg s-1" |
| 739 | + |
| 740 | + fixed_cubes = fix_metadata(cubes, "Omon", "msftmz") |
| 741 | + |
| 742 | + assert len(fixed_cubes) == 1 |
| 743 | + cube = fixed_cubes[0] |
| 744 | + assert cube.var_name == "msftmz" |
| 745 | + assert ( |
| 746 | + cube.standard_name |
| 747 | + == "ocean_meridional_overturning_mass_streamfunction" |
| 748 | + ) |
| 749 | + assert cube.long_name == "Ocean Meridional Overturning Mass Streamfunction" |
| 750 | + |
| 751 | + assert cube.units == "kg s-1" |
| 752 | + assert "positive" not in cube.attributes |
| 753 | + assert "invalid_units" not in cube.attributes |
| 754 | + |
| 755 | + np.testing.assert_equal( |
| 756 | + cube.coord("region").points, |
| 757 | + ["atlantic_arctic_ocean", "indian_pacific_ocean", "global_ocean"], |
| 758 | + ) |
| 759 | + |
| 760 | + assert cube.shape == (1, 3, 1, 2) |
| 761 | + np.testing.assert_allclose( |
| 762 | + cube.data, |
| 763 | + [[[[0.0, 0.0]], [[0.0, 2.0]], [[0.0, 4.0]]]], |
| 764 | + ) |
| 765 | + |
| 766 | + |
707 | 767 | # Test rlut (for extra fix) |
708 | 768 |
|
709 | 769 |
|
|
0 commit comments