@@ -929,7 +929,8 @@ def test_rtmt_fix(cubes_regular_grid):
929929 np .testing .assert_allclose (cube .data , [[[0.0 , 2.0 ], [4.0 , 6.0 ]]])
930930
931931
932- # Test siconc (for extra_facets, removal of lev coord and typesi coordinate)
932+ # Test siconc (for extra_facets, removal of lev/ice_class coord and typesi
933+ # coordinate)
933934
934935
935936def test_get_siconc_fix ():
@@ -939,18 +940,19 @@ def test_get_siconc_fix():
939940
940941
941942@pytest .mark .online
942- def test_siconc_fix (cubes_ocean_3d , session ):
943+ @pytest .mark .parametrize ("z_coord_name" , ["lev" , "ice_class" ])
944+ def test_siconc_fix (z_coord_name , cubes_ocean_3d , session ):
943945 """Test fix."""
944946 cubes = CubeList (
945947 [cubes_ocean_3d .extract_cube (NameConstraint (var_name = "to" )).copy ()],
946948 )
947949 cubes [0 ].var_name = "conc"
948950 cubes [0 ].units = None
949951
950- # Add lev coord to test removal of it
952+ # Add Z- coord to test removal of it
951953 cubes [0 ] = cubes [0 ][:, [0 ], :]
952954 cubes [0 ].remove_coord ("depth" )
953- cubes [0 ].add_dim_coord (DimCoord (0.0 , var_name = "lev" ), 1 )
955+ cubes [0 ].add_dim_coord (DimCoord (0.0 , var_name = z_coord_name ), 1 )
954956
955957 fix = get_allvars_fix ("SImon" , "siconc" , session = session )
956958 fixed_cubes = fix .fix_metadata (cubes )
@@ -965,7 +967,7 @@ def test_siconc_fix(cubes_ocean_3d, session):
965967 check_typesi (cube )
966968
967969 assert cube .shape == (1 , 8 )
968- assert not cube .coords (var_name = "lev" )
970+ assert not cube .coords (var_name = z_coord_name )
969971
970972 assert cube .dtype == np .float32
971973 np .testing .assert_allclose (
@@ -1109,6 +1111,34 @@ def test_thetao_fix(cubes_ocean_3d, session):
11091111 assert cube .shape == (1 , 47 , 8 )
11101112
11111113
1114+ @pytest .mark .online
1115+ def test_thetao_fix_switched_depth_coords (cubes_ocean_3d , session ):
1116+ """Test fix."""
1117+ to_cube = cubes_ocean_3d .extract_cube (NameConstraint (var_name = "to" ))
1118+ w_cube = cubes_ocean_3d .extract_cube (NameConstraint (var_name = "w" ))
1119+ to_cube .coord ("depth" ).var_name = "depth_2"
1120+ w_cube .coord ("depth" ).var_name = "depth"
1121+ cubes = CubeList ([to_cube , w_cube ])
1122+
1123+ fix = get_allvars_fix ("Omon" , "thetao" , session = session )
1124+
1125+ fixed_cubes = fix .fix_metadata (cubes )
1126+
1127+ assert len (fixed_cubes ) == 1
1128+ cube = fixed_cubes [0 ]
1129+ assert cube .var_name == "thetao"
1130+ assert cube .standard_name == "sea_water_potential_temperature"
1131+ assert cube .long_name == "Sea Water Potential Temperature"
1132+ assert cube .units == "degC"
1133+ assert "positive" not in cube .attributes
1134+
1135+ depth_coord = cube .coord ("depth" )
1136+ assert depth_coord .has_bounds ()
1137+
1138+ assert cube .dtype == np .float32
1139+ assert cube .shape == (1 , 47 , 8 )
1140+
1141+
11121142@pytest .mark .online
11131143def test_thetao_fix_already_bounds (cubes_ocean_3d , session ):
11141144 """Test fix."""
@@ -1164,6 +1194,36 @@ def test_thetao_fix_no_bounds(cubes_ocean_3d, session):
11641194 assert cube .shape == (1 , 47 , 8 )
11651195
11661196
1197+ @pytest .mark .online
1198+ def test_thetao_fix_no_bounds_invalid_depth_2 (cubes_ocean_3d , session ):
1199+ """Test fix."""
1200+ to_cube = cubes_ocean_3d .extract_cube (NameConstraint (var_name = "to" ))
1201+ w_cube = cubes_ocean_3d .extract_cube (NameConstraint (var_name = "w" ))[
1202+ :,
1203+ :40 ,
1204+ :,
1205+ ]
1206+ cubes = CubeList ([to_cube , w_cube ])
1207+
1208+ fix = get_allvars_fix ("Omon" , "thetao" , session = session )
1209+
1210+ fixed_cubes = fix .fix_metadata (cubes )
1211+
1212+ assert len (fixed_cubes ) == 1
1213+ cube = fixed_cubes [0 ]
1214+ assert cube .var_name == "thetao"
1215+ assert cube .standard_name == "sea_water_potential_temperature"
1216+ assert cube .long_name == "Sea Water Potential Temperature"
1217+ assert cube .units == "degC"
1218+ assert "positive" not in cube .attributes
1219+
1220+ depth_coord = cube .coord ("depth" )
1221+ assert not depth_coord .has_bounds ()
1222+
1223+ assert cube .dtype == np .float32
1224+ assert cube .shape == (1 , 47 , 8 )
1225+
1226+
11671227# Test zg (for extra fix)
11681228
11691229
0 commit comments