@@ -1285,6 +1285,69 @@ def test_bad_grid_mapping_attribute():
12851285 assert grid_mappings == () # No valid grid mappings since 'foo' doesn't exist
12861286
12871287
1288+ @requires_pyproj
1289+ def test_healpix_grid_mapping ():
1290+ """Test GridMapping integration for HEALPix grids."""
1291+ from ..datasets import healpix_ds as ds
1292+
1293+ # Grid mapping discovery
1294+ assert ds .cf .grid_mapping_names == {"healpix" : ["healpix" ]}
1295+
1296+ # Grid mapping propagation to data variables
1297+ da = ds .cf ["air_temperature" ]
1298+ assert "healpix" in da .coords
1299+
1300+ # grid_mapping_name property
1301+ assert da .cf .grid_mapping_name == "healpix"
1302+
1303+ # .cf.grid_mappings property on Dataset
1304+ gms = ds .cf .grid_mappings
1305+ assert len (gms ) == 1
1306+ gm = gms [0 ]
1307+ assert gm .name == "healpix"
1308+ assert gm .crs is not None
1309+ assert gm .crs .is_geographic
1310+ assert gm .array .name == "healpix"
1311+ assert gm .array .shape == () # scalar variable
1312+ assert isinstance (gm .coordinates , tuple )
1313+
1314+ # DataArray grid_mappings should also work
1315+ da_gms = da .cf .grid_mappings
1316+ assert len (da_gms ) == 1
1317+ assert da_gms [0 ].name == "healpix"
1318+ assert da_gms [0 ].crs .is_geographic
1319+
1320+ # Repr should include healpix
1321+ assert "healpix" in ds .cf .__repr__ ()
1322+
1323+
1324+ @requires_pyproj
1325+ def test_healpix_crs_properties ():
1326+ """Test that the CRS built for HEALPix has correct properties."""
1327+ from ..datasets import healpix_ds as ds
1328+
1329+ gm = ds .cf .grid_mappings [0 ]
1330+ crs = gm .crs
1331+
1332+ # Must be geographic (lat/lon on a sphere)
1333+ assert crs .is_geographic
1334+ assert not crs .is_projected
1335+
1336+ # Earth shape parameters from the grid mapping variable
1337+ assert crs .ellipsoid .semi_major_metre == 6371000
1338+ assert crs .ellipsoid .semi_minor_metre == 6371000
1339+
1340+ # Should not have an EPSG code (custom sphere)
1341+ assert crs .to_epsg () is None
1342+
1343+ # Verify HEALPix-specific attributes are preserved in the grid mapping array
1344+ gm_attrs = gm .array .attrs
1345+ assert gm_attrs ["grid_mapping_name" ] == "healpix"
1346+ assert gm_attrs ["refinement_level" ] == 1
1347+ assert gm_attrs ["indexing_scheme" ] == "nested"
1348+ assert gm_attrs ["earth_radius" ] == 6371000
1349+
1350+
12881351def test_docstring () -> None :
12891352 assert "One of ('X'" in airds .cf .groupby .__doc__
12901353 assert "Time variable accessor e.g. 'T.month'" in airds .cf .groupby .__doc__
0 commit comments