@@ -987,6 +987,7 @@ def test_get_bounds_dim_name() -> None:
987
987
ds .cf .get_bounds_dim_name ("longitude" )
988
988
989
989
990
+ @requires_pyproj
990
991
def test_grid_mappings ():
991
992
ds = rotds .copy (deep = False )
992
993
@@ -1036,6 +1037,26 @@ def test_grid_mappings():
1036
1037
# grid_mapping_name
1037
1038
assert ds .cf ["temp" ].cf .grid_mapping_name == "rotated_latitude_longitude"
1038
1039
1040
+ # Test .grid_mappings property with single grid mapping
1041
+ grid_mappings = ds .cf .grid_mappings
1042
+ assert len (grid_mappings ) == 1
1043
+ gm = grid_mappings [0 ]
1044
+ assert gm .name == "rotated_latitude_longitude"
1045
+ assert gm .array .name == "rotated_pole"
1046
+ assert gm .array .shape == () # scalar variable
1047
+ assert isinstance (gm .coordinates , tuple )
1048
+ # Should have rlon and rlat detected from standard names
1049
+ assert gm .coordinates == ("rlon" , "rlat" )
1050
+
1051
+ # Test .grid_mappings property on DataArray with propagated coords
1052
+ da_grid_mappings = ds .cf ["temp" ].cf .grid_mappings
1053
+ assert len (da_grid_mappings ) == 1
1054
+ da_gm = da_grid_mappings [0 ]
1055
+ assert da_gm .name == "rotated_latitude_longitude"
1056
+ assert da_gm .array .name == "rotated_pole"
1057
+ # Should also detect rlon and rlat from standard names
1058
+ assert da_gm .coordinates == ("rlon" , "rlat" )
1059
+
1039
1060
# what if there are really 2 grid mappins?
1040
1061
ds ["temp2" ] = ds .temp
1041
1062
ds ["temp2" ].attrs ["grid_mapping" ] = "rotated_pole2"
@@ -1240,6 +1261,7 @@ def test_grid_mappings_coordinates_attribute():
1240
1261
)
1241
1262
1242
1263
1264
+ @requires_pyproj
1243
1265
def test_bad_grid_mapping_attribute ():
1244
1266
ds = rotds .copy (deep = False )
1245
1267
ds .temp .attrs ["grid_mapping" ] = "foo"
@@ -1255,6 +1277,10 @@ def test_bad_grid_mapping_attribute():
1255
1277
with pytest .warns (UserWarning ):
1256
1278
ds .cf .get_associated_variable_names ("temp" , error = False )
1257
1279
1280
+ # Test .grid_mappings property with bad grid mapping - should return empty tuple
1281
+ grid_mappings = ds .cf .grid_mappings
1282
+ assert grid_mappings == () # No valid grid mappings since 'foo' doesn't exist
1283
+
1258
1284
1259
1285
def test_docstring () -> None :
1260
1286
assert "One of ('X'" in airds .cf .groupby .__doc__
0 commit comments