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

working version, needs cleanup #69

Merged
merged 1 commit into from
Oct 13, 2024
Merged
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
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