Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore bands that have role "metadata" when loading with load_stac #971

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion openeogeotrellis/load_stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,28 @@ def supports_item_search(coll: pystac.Collection) -> bool:
conforms_to = coll.get_root().extra_fields.get("conformsTo", [])
return any(conformance_class.endswith("/item-search") for conformance_class in conforms_to)

def is_raster_mime_type(mime_type: str) -> bool:
mime_type = mime_type.lower()
# https://github.com/radiantearth/stac-spec/blob/master/best-practices.md#common-media-types-in-stac
if (
mime_type.startswith("image/tif") # match both tif and tiff, just in case
or mime_type.startswith("image/vnd.stac.geotiff")
or mime_type.startswith("image/jp2")
or mime_type.startswith("image/png")
or mime_type.startswith("image/jpeg")
or mime_type.startswith("application/x-hdf") # matches hdf5 and hdf
or mime_type.startswith("application/x-netcdf")
or mime_type.startswith("application/netcdf")
):
return True

def is_band_asset(asset: pystac.Asset) -> bool:
roles_with_bands = ["data", "data-mask", "snow-ice", "land-water", "water-mask"]
return any(asset.has_role(role) for role in roles_with_bands) or "eo:bands" in asset.extra_fields
return (
any(asset.has_role(role) for role in roles_with_bands)
and (asset.media_type is None or is_raster_mime_type(asset.media_type))
or "eo:bands" in asset.extra_fields
)

def get_band_names(itm: pystac.Item, asst: pystac.Asset) -> List[str]:
def get_band_name(eo_band) -> str:
Expand Down