7272from openeo_driver .users .auth import HttpAuthHandler
7373from openeo_driver .util .geometry import BoundingBox , reproject_geometry
7474from openeo_driver .util .logging import ExtraLoggingFilter , FlaskRequestCorrelationIdLogging
75+ from openeo_driver .util .stac import sniff_stac_extension_prefix
7576from openeo_driver .utils import EvalEnv , filter_supported_kwargs , smart_bool
7677
7778_log = logging .getLogger (__name__ )
@@ -1166,7 +1167,9 @@ def job_results_canonical_url() -> str:
11661167 )
11671168
11681169 assets = {
1169- filename : _asset_object (job_id , user_id , filename , asset_metadata , job_info )
1170+ filename : _asset_object (
1171+ job_id = job_id , user_id = user_id , filename = filename , asset_metadata = asset_metadata , job_info = job_info
1172+ )
11701173 for filename , asset_metadata in result_assets .items ()
11711174 if asset_metadata .get ("asset" , True )
11721175 }
@@ -1211,7 +1214,7 @@ def job_result_item_url(item_id) -> str:
12111214 "type" : "Collection" ,
12121215 "stac_version" : "1.0.0" ,
12131216 "stac_extensions" : [
1214- STAC_EXTENSION .EO ,
1217+ STAC_EXTENSION .EO_V110 ,
12151218 STAC_EXTENSION .FILEINFO ,
12161219 STAC_EXTENSION .PROCESSING ,
12171220 STAC_EXTENSION .PROJECTION ,
@@ -1274,8 +1277,8 @@ def job_result_item_url(item_id) -> str:
12741277 STAC_EXTENSION .FILEINFO ,
12751278 ]
12761279
1277- if any ( "eo:bands" in asset_object for asset_object in result ["assets" ].values ()):
1278- result ["stac_extensions" ].append (STAC_EXTENSION .EO )
1280+ if sniff_stac_extension_prefix ( result ["assets" ].values (), prefix = "eo:" ):
1281+ result ["stac_extensions" ].append (STAC_EXTENSION .EO_V110 )
12791282
12801283 if any (key .startswith ("proj:" ) for key in result ["properties" ]) or any (
12811284 key .startswith ("proj:" ) for key in result ["assets" ]
@@ -1439,9 +1442,9 @@ def _get_job_result_item(job_id, item_id, user_id):
14391442 "type" : "Feature" ,
14401443 "stac_version" : "1.0.0" ,
14411444 "stac_extensions" : [
1442- STAC_EXTENSION .EO ,
1445+ STAC_EXTENSION .EO_V110 ,
14431446 STAC_EXTENSION .FILEINFO ,
1444- STAC_EXTENSION .PROJECTION
1447+ STAC_EXTENSION .PROJECTION ,
14451448 ],
14461449 "id" : item_id ,
14471450 "geometry" : geometry ,
@@ -1514,6 +1517,7 @@ def _asset_object(job_id, user_id, filename: str, asset_metadata: dict, job_info
15141517 ),
15151518 "type" : asset_metadata .get ("type" , asset_metadata .get ("media_type" , "application/octet-stream" )),
15161519 "roles" : asset_metadata .get ("roles" , ["data" ]),
1520+ # TODO: eliminate this legacy "raster:bands" construct at some point?
15171521 "raster:bands" : asset_metadata .get ("raster:bands" ),
15181522 "file:size" : asset_metadata .get ("file:size" ),
15191523 "alternate" : asset_metadata .get ("alternate" ),
@@ -1524,20 +1528,31 @@ def _asset_object(job_id, user_id, filename: str, asset_metadata: dict, job_info
15241528 return result_dict
15251529 bands = asset_metadata .get ("bands" )
15261530
1531+ if bands :
1532+ # TODO: eliminate this legacy "eo:bands" construct at some point?
1533+ result_dict ["eo:bands" ] = [
1534+ dict_no_none (
1535+ {
1536+ "name" : band .name ,
1537+ "center_wavelength" : band .wavelength_um ,
1538+ }
1539+ )
1540+ for band in bands
1541+ ]
1542+ # TODO: "bands" is a STAC>=1.1 feature, but here we don't know what version we are in.
1543+ result_dict ["bands" ] = [
1544+ dict_no_none (
1545+ {
1546+ "name" : band .name ,
1547+ "eo:center_wavelength" : band .wavelength_um ,
1548+ }
1549+ )
1550+ for band in bands
1551+ ]
1552+
15271553 result_dict .update (
15281554 dict_no_none (
15291555 ** {
1530- "eo:bands" : [
1531- dict_no_none (
1532- ** {
1533- "name" : band .name ,
1534- "center_wavelength" : band .wavelength_um ,
1535- }
1536- )
1537- for band in bands
1538- ]
1539- if bands
1540- else None ,
15411556 "proj:bbox" : asset_metadata .get ("proj:bbox" , job_info .proj_bbox ),
15421557 "proj:epsg" : asset_metadata .get ("proj:epsg" , job_info .epsg ),
15431558 "proj:shape" : asset_metadata .get ("proj:shape" , job_info .proj_shape ),
@@ -1835,7 +1850,9 @@ def _normalize_collection_metadata(metadata: dict, api_version: ComparableVersio
18351850 # Version dependent metadata conversions
18361851 cube_dims_100 = deep_get (metadata , "cube:dimensions" , default = None )
18371852 cube_dims_040 = deep_get (metadata , "properties" , "cube:dimensions" , default = None )
1853+ bands_110 = deep_get (metadata , "summaries" , "bands" , default = None )
18381854 eo_bands_100 = deep_get (metadata , "summaries" , "eo:bands" , default = None )
1855+ # TODO do we still need normalization of openEO 0.4 style eo:bands?
18391856 eo_bands_040 = deep_get (metadata , "properties" , "eo:bands" , default = None )
18401857 extent_spatial_100 = deep_get (metadata , "extent" , "spatial" , "bbox" , default = None )
18411858 extent_spatial_040 = deep_get (metadata , "extent" , "spatial" , default = None )
@@ -1845,6 +1862,19 @@ def _normalize_collection_metadata(metadata: dict, api_version: ComparableVersio
18451862 if full and not cube_dims_100 and cube_dims_040 :
18461863 _log .warning ("Collection metadata 'cube:dimensions' in API 0.4 style instead of 1.0 style" )
18471864 metadata ["cube:dimensions" ] = cube_dims_040
1865+ if full and not bands_110 and eo_bands_100 :
1866+ _log .warning ("_normalize_collection_metadata: converting eo:bands to bands metadata" )
1867+ # TODO #298/#363: "bands" is a STAC>=1.1 feature, but here we don't know what version we are in.
1868+ metadata ["summaries" ]["bands" ] = [
1869+ dict_no_none (
1870+ {
1871+ "name" : b .get ("name" ),
1872+ "eo:common_name" : b .get ("common_name" ),
1873+ "eo:center_wavelength" : b .get ("center_wavelength" ),
1874+ }
1875+ )
1876+ for b in eo_bands_100
1877+ ]
18481878 if full and not eo_bands_100 and eo_bands_040 :
18491879 _log .warning ("Collection metadata 'eo:bands' in API 0.4 style instead of 1.0 style" )
18501880 metadata .setdefault ("summaries" , {})
@@ -1872,13 +1902,14 @@ def _normalize_collection_metadata(metadata: dict, api_version: ComparableVersio
18721902 dim ["extent" ] = interval
18731903
18741904 # Make sure some required fields are set.
1905+ # TODO #363 bump stac_version default to 1.0.0 or even 1.1.0?
18751906 metadata .setdefault ("stac_version" , "0.9.0" )
18761907 metadata .setdefault (
18771908 "stac_extensions" ,
18781909 [
18791910 # TODO: enable these extensions only when necessary?
18801911 STAC_EXTENSION .DATACUBE ,
1881- STAC_EXTENSION .EO ,
1912+ STAC_EXTENSION .EO_V110 ,
18821913 ],
18831914 )
18841915
0 commit comments