@@ -937,6 +937,93 @@ def test_metadata_from_stac_temporal_dimension(tmp_path, stac_dict, expected):
937937 assert not metadata .has_temporal_dimension ()
938938
939939
940+ @pytest .mark .skipif (
941+ not _PYSTAC_1_9_EXTENSION_INTERFACE ,
942+ reason = "No backport of implementation/test below PySTAC 1.9 extension interface" ,
943+ )
944+ @pytest .mark .parametrize (
945+ ["stac_dict" , "expected" ],
946+ [
947+ (
948+ # Item without cube:dimensions metadata -> assume spatial dimensions x and y
949+ StacDummyBuilder .item (),
950+ {"x" : [None , None ], "y" : [None , None ]},
951+ ),
952+ (
953+ StacDummyBuilder .item (
954+ cube_dimensions = {
955+ "t" : {"type" : "temporal" , "extent" : ["2024-04-04" , "2024-06-06" ]},
956+ "x" : {"type" : "spatial" , "axis" : "x" , "extent" : [- 10 , 20 ]},
957+ "y" : {"type" : "spatial" , "axis" : "y" , "extent" : [30 , 50 ]},
958+ }
959+ ),
960+ {"x" : [- 10 , 20 ], "y" : [30 , 50 ]},
961+ ),
962+ (
963+ # Custom dimension names
964+ StacDummyBuilder .item (
965+ cube_dimensions = {
966+ "TTT" : {"type" : "temporal" , "extent" : ["2024-04-04" , "2024-06-06" ]},
967+ "XXX" : {"type" : "spatial" , "axis" : "x" , "extent" : [- 10 , 20 ]},
968+ "YYY" : {"type" : "spatial" , "axis" : "y" , "extent" : [30 , 50 ]},
969+ }
970+ ),
971+ {"XXX" : [- 10 , 20 ], "YYY" : [30 , 50 ]},
972+ ),
973+ (
974+ # Explicitly absent spatial dimensions
975+ StacDummyBuilder .item (
976+ cube_dimensions = {
977+ "t" : {"type" : "temporal" , "extent" : ["2024-04-04" , "2024-06-06" ]},
978+ }
979+ ),
980+ {},
981+ ),
982+ (
983+ # No cube:dimensions metadata -> assume spatial dimensions x and y
984+ StacDummyBuilder .collection (),
985+ {"x" : [None , None ], "y" : [None , None ]},
986+ ),
987+ (
988+ StacDummyBuilder .collection (
989+ cube_dimensions = {
990+ "t" : {"type" : "temporal" , "extent" : ["2024-04-04" , "2024-06-06" ]},
991+ "x" : {"type" : "spatial" , "axis" : "x" , "extent" : [- 10 , 20 ]},
992+ "y" : {"type" : "spatial" , "axis" : "y" , "extent" : [30 , 50 ]},
993+ }
994+ ),
995+ {"x" : [- 10 , 20 ], "y" : [30 , 50 ]},
996+ ),
997+ (
998+ # Explicitly absent spatial dimensions
999+ StacDummyBuilder .collection (
1000+ cube_dimensions = {
1001+ "t" : {"type" : "temporal" , "extent" : ["2024-04-04" , "2024-06-06" ]},
1002+ }
1003+ ),
1004+ {},
1005+ ),
1006+ (
1007+ StacDummyBuilder .catalog (),
1008+ {"x" : [None , None ], "y" : [None , None ]},
1009+ ),
1010+ (
1011+ # Note: a catalog is not supposed to have datacube extension enabled, but we should not choke on that
1012+ StacDummyBuilder .catalog (stac_extensions = [StacDummyBuilder ._EXT_DATACUBE ]),
1013+ {"x" : [None , None ], "y" : [None , None ]},
1014+ ),
1015+ ],
1016+ )
1017+ def test_metadata_from_stac_spatial_dimensions (tmp_path , stac_dict , expected ):
1018+ path = tmp_path / "stac.json"
1019+ # TODO #738 real request mocking of STAC resources compatible with pystac?
1020+ path .write_text (json .dumps (stac_dict ))
1021+ metadata = metadata_from_stac (str (path ))
1022+ dims = metadata .spatial_dimensions
1023+ assert all (isinstance (d , SpatialDimension ) for d in dims )
1024+ assert {d .name : d .extent for d in dims } == expected
1025+
1026+
9401027@pytest .mark .parametrize (
9411028 ["kwargs" , "expected_x" , "expected_y" ],
9421029 [
0 commit comments