Skip to content

Commit 9002c87

Browse files
committed
added migration
1 parent 659a2b6 commit 9002c87

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

pystac/extensions/mlm.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,6 +2086,59 @@ def migrate(props_obj: dict[str, Any]) -> None:
20862086
SyntaxWarning,
20872087
)
20882088

2089+
# if no bands definition is given in mlm:input (bands=[]),
2090+
# raster definitions are not allowed to be in the assets object that is
2091+
# stac:mlm
2092+
if "mlm:input" in props_obj:
2093+
no_bands_present = all(
2094+
not inp["bands"] for inp in props_obj["mlm:input"]
2095+
)
2096+
2097+
if no_bands_present:
2098+
for inner_asset_name in obj["assets"]:
2099+
inner_asset = obj["assets"][inner_asset_name]
2100+
2101+
if "mlm:model" not in inner_asset["roles"]:
2102+
continue
2103+
2104+
if "raster:bands" in inner_asset:
2105+
bands_obj = inner_asset["raster:bands"]
2106+
2107+
warnings.warn(
2108+
"stac:mlm does not allow 'raster:bands' in mlm:model "
2109+
"asset if mlm:input.bands is empty. Moving it to "
2110+
"properties if it contains values, or deleting it if "
2111+
"it does not contain any values.",
2112+
SyntaxWarning,
2113+
)
2114+
2115+
# move the bands_obj if it is not an empty list
2116+
if bands_obj:
2117+
if obj["type"] == "Feature":
2118+
obj["properties"]["raster:bands"] = bands_obj
2119+
if obj["type"] == "Collection":
2120+
obj["raster:bands"] = bands_obj
2121+
inner_asset.pop("raster:bands")
2122+
2123+
if "eo:bands" in inner_asset:
2124+
bands_obj = inner_asset["eo:bands"]
2125+
2126+
warnings.warn(
2127+
"stac:mlm does not allow 'raster:bands' in mlm:model "
2128+
"asset if mlm:input.bands is empty. Moving it to "
2129+
"properties if it contains values, or deleting it if "
2130+
"it does not contain any values.",
2131+
SyntaxWarning,
2132+
)
2133+
2134+
# move the bands_obj if it is not an empty list
2135+
if bands_obj:
2136+
if obj["type"] == "Feature":
2137+
obj["properties"]["eo:bands"] = bands_obj
2138+
if obj["type"] == "Collection":
2139+
obj["eo:bands"] = bands_obj
2140+
inner_asset.pop("eo:bands")
2141+
20892142
if obj["type"] == "Feature":
20902143
migrate(obj["properties"])
20912144
if obj["type"] == "Collection":

0 commit comments

Comments
 (0)