Skip to content

Commit

Permalink
a guess of the earthdataclient case (#235)
Browse files Browse the repository at this point in the history
* a guess of the earthdataclient case

* Update CHANGELOG

* add test of getting EarthdataClient from url factory
  • Loading branch information
ircwaves authored Oct 29, 2024
1 parent 05cb037 commit 1f7df99
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Added

- Added logic to select `EarthdataClient` when appropriate ([#235](https://github.com/stac-utils/stac-asset/pull/235))

## [0.4.4] - 2024-10-23

### Changed
Expand Down
3 changes: 3 additions & 0 deletions src/stac_asset/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ async def get_client(self, href: str) -> Client:
Returns:
Client: An instance of that client.
"""
from .earthdata_client import EarthdataClient
from .filesystem_client import FilesystemClient
from .http_client import HttpClient
from .planetary_computer_client import PlanetaryComputerClient
Expand All @@ -217,6 +218,8 @@ async def get_client(self, href: str) -> Client:
client_class = S3Client
elif url.host.endswith("blob.core.windows.net"):
client_class = PlanetaryComputerClient
elif url.scheme == "https" and "earthdata" in url.host:
client_class = EarthdataClient
elif url.scheme == "http" or url.scheme == "https":
client_class = HttpClient
else:
Expand Down
9 changes: 8 additions & 1 deletion tests/test_earthdata_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,26 @@
import pytest

from stac_asset import Config, EarthdataClient
from stac_asset.client import Clients

pytestmark = [
pytest.mark.skipif(
os.environ.get("EARTHDATA_PAT") is None,
reason="EARTHDATA_PAT is not set",
),
pytest.mark.asyncio,
pytest.mark.network_access,
]


@pytest.mark.network_access
async def test_download_href(tmp_path: Path) -> None:
href = "https://data.lpdaac.earthdatacloud.nasa.gov/lp-prod-protected/MYD11A1.061/MYD11A1.A2023145.h14v17.061.2023146183035/MYD11A1.A2023145.h14v17.061.2023146183035.hdf"
async with await EarthdataClient.from_config(Config()) as client:
await client.download_href(href, tmp_path / "out.hdf")
assert os.path.getsize(tmp_path / "out.hdf") == 197419


async def test_get_earthdata_client() -> None:
href = "https://data.lpdaac.earthdatacloud.nasa.gov/lp-prod-protected/MOD21A1D.061/MOD21A1D.A2020253.h08v05.061.2020346022258/MOD21A1D.A2020253.h08v05.061.2020346022258.hdf"
clients = Clients(Config())
assert isinstance(await clients.get_client(href=href), EarthdataClient)

0 comments on commit 1f7df99

Please sign in to comment.