Skip to content

Commit

Permalink
working version, needs cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jessjaco committed Oct 11, 2024
1 parent eaf840f commit b340fed
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions dep_tools/stac_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import numpy as np
from pandas import DataFrame
from pystac import Asset, Item, MediaType
from rio_stac.stac import create_stac_item
import rasterio
from rio_stac.stac import create_stac_item, get_raster_info
from urlpath import URL
from xarray import DataArray, Dataset

Expand Down Expand Up @@ -73,14 +74,20 @@ def get_stac_item(

paths = [itempath.path(item_id, variable) for variable in data]

assets = {
variable: Asset(
assets = {}
for variable, path in zip(data, paths):
raster_info = {}
full_path = str(prefix / path)
if "with_raster" in kwargs.keys() and kwargs["with_raster"]:
with rasterio.open(full_path) as src_dst:
raster_info = {"raster:bands": get_raster_info(src_dst, max_size=1024)}

assets[variable] = Asset(
media_type=MediaType.COG,
href=str(prefix / path),
href=full_path,
roles=["data"],
extra_fields={**raster_info},
)
for variable, path in zip(data, paths)
}
stac_id = itempath.basename(item_id)
collection = itempath.item_prefix
collection_url = f"{collection_url_root}/{collection}"
Expand Down

0 comments on commit b340fed

Please sign in to comment.