diff --git a/src/stac_asset/functions.py b/src/stac_asset/functions.py index 6b2e58e..87b53a9 100644 --- a/src/stac_asset/functions.py +++ b/src/stac_asset/functions.py @@ -62,13 +62,10 @@ async def download_item( if config.file_name: item_path = directory_as_path / config.file_name + item.set_self_href(str(item_path)) else: - self_href = item.get_self_href() - if self_href: - item_path = directory_as_path / os.path.basename(self_href) - else: - item_path = None - item.set_self_href(str(item_path)) + item_path = None + item.set_self_href(None) file_names: Set[str] = set() assets: Dict[str, Tuple[Asset, Path]] = dict() @@ -222,6 +219,10 @@ def guess_client_class(asset: Asset, config: Config) -> Type[Client]: "invalid alternate asset definition (missing href): " f"{alternate}" ) + if asset.href.startswith("abfs://") and asset.media_type == "application/x-parquet": + storage_account = asset.extra_fields["table:storage_options"]["account_name"] + asset.href = f"https://{storage_account}.blob.core.windows.net/{asset.href[7:]}" + asset.media_type = None return guess_client_class_from_href(asset.href) diff --git a/tests/test_planetary_computer_client.py b/tests/test_planetary_computer_client.py index f7b1781..b49d298 100644 --- a/tests/test_planetary_computer_client.py +++ b/tests/test_planetary_computer_client.py @@ -2,6 +2,8 @@ from pathlib import Path import pytest +import stac_asset +from pystac import Item from stac_asset import Config, PlanetaryComputerClient pytestmark = [ @@ -20,3 +22,12 @@ async def test_download(tmp_path: Path, asset_href: str) -> None: await client.download_href(asset_href, tmp_path / "out.tif") assert os.path.getsize(tmp_path / "out.tif") == 4096 + + +async def test_abfs(tmp_path: Path) -> None: + href = ( + "https://planetarycomputer.microsoft.com/api/stac/v1/" + "collections/ms-buildings/items/Vatican%20City_2022-07-06" + ) + await stac_asset.download_item(Item.from_file(href), tmp_path) + assert os.path.getsize(tmp_path / "Vatican%20City_2022-07-06") == 2260