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

Allow single file URL inputs for earthaccess.download #347

Merged
merged 3 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions earthaccess/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def login(strategy: str = "all", persist: bool = False) -> Auth:


def download(
granules: Union[DataGranule, List[DataGranule], List[str]],
granules: Union[DataGranule, List[DataGranule], str, List[str]],
local_path: Union[str, None],
provider: Optional[str] = None,
threads: int = 8,
Expand All @@ -162,7 +162,7 @@ def download(
* If we run it outside AWS (us-west-2 region) and the dataset is cloud hostes we'll use HTTP links

Parameters:
granules: a granule, list of granules, or a list of granule links (HTTP)
granules: a granule, list of granules, a granule link (HTTP), or a list of granule links (HTTP)
local_path: local directory to store the remote data granules
provider: if we download a list of URLs we need to specify the provider.
threads: parallel number of threads to use to download the files, adjust as necessary, default = 8
Expand All @@ -172,6 +172,8 @@ def download(
"""
if isinstance(granules, DataGranule):
granules = [granules]
elif isinstance(granules, str):
granules = [granules]
try:
results = earthaccess.__store__.get(granules, local_path, provider, threads)
except AttributeError as err:
Expand Down
7 changes: 6 additions & 1 deletion tests/integration/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,18 @@ def test_granules_search_returns_valid_results(kwargs):


@pytest.mark.parametrize("selection", [0, slice(None)])
def test_earthaccess_api_can_download_granules(tmp_path, selection):
@pytest.mark.parametrize("use_url", [True, False])
def test_download(tmp_path, selection, use_url):
results = earthaccess.search_data(
count=2,
short_name="ATL08",
cloud_hosted=True,
bounding_box=(-92.86, 16.26, -91.58, 16.97),
)
if use_url:
# Download via file URL string instead of DataGranule object
results = [r.data_links(access="indirect") for r in results]
results = sum(results, start=[]) # flatten to a list of strings
result = results[selection]
files = earthaccess.download(result, str(tmp_path))
assertions.assertIsInstance(files, list)
Expand Down
Loading