Skip to content

Commit

Permalink
Expand raster data detection #114
Browse files Browse the repository at this point in the history
- Add pass-list of non-image media types
- Extend extension list
  • Loading branch information
Kirill888 committed May 10, 2023
1 parent de6fd1c commit ea985be
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions odc/stac/_mdtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,27 @@
ROLES_THUMBNAIL = {"thumbnail", "overview"}

# Used to detect image assets when media_type is missing
RASTER_FILE_EXTENSIONS = {"tif", "tiff", "jpeg", "jpg", "jp2", "img"}
RASTER_FILE_EXTENSIONS = {
"tif",
"tiff",
"jpeg",
"jpg",
"jp2",
"img",
"hdf",
"nc",
"zarr",
}

# image/* and these media-type are considered to be raster
NON_IMAGE_RASTER_MEDIA_TYPES = {
"application/x-hdf",
"application/hdf",
"application/x-netcdf",
"application/netcdf",
"application/x-zarr",
"application/zarr",
}


def with_default(v: Optional[T], default_value: T) -> T:
Expand Down Expand Up @@ -207,19 +227,26 @@ def is_raster_data(asset: pystac.asset.Asset, check_proj: bool = False) -> bool:
return True
if "metadata" in roles:
return False
elif "image/" in media_type:

ext = asset.href.split(".")[-1].lower()
return ext in RASTER_FILE_EXTENSIONS

media_type, *_ = media_type.split(";")
media_type = media_type.lower()

if media_type.startswith("image/"):
# Image:
# False -- when thumbnail
# True -- otherwise
if any(r in roles for r in ROLES_THUMBNAIL):
return False
return True
else:
# Some type that is not `image/*`
return False

ext = asset.href.split(".")[-1].lower()
return ext in RASTER_FILE_EXTENSIONS
if media_type in NON_IMAGE_RASTER_MEDIA_TYPES:
return True

# some unsupported mime type
return False


def mk_1x1_geobox(g: Geometry) -> GeoBox:
Expand Down

0 comments on commit ea985be

Please sign in to comment.