Skip to content

Commit

Permalink
Merge pull request #10 from NASA-IMPACT/landsat-downloader
Browse files Browse the repository at this point in the history
Return Landsat granule id for landsat downloader.
  • Loading branch information
sharkinsspatial authored Oct 22, 2021
2 parents 0d2b0e3 + 48a9971 commit b9b3de2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 6 additions & 1 deletion download_landsat/download_landsat.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,13 @@ def get_landsat(bucket, path, output_directory):
client = boto3.client("s3")
if(key_exists(client, bucket, path)):
download_files(client, bucket, path, output_directory)
id = Path(path).parts[-1]
return id
else:
updated_path = get_updated_key(client, bucket, path)
download_files(client, bucket, updated_path, output_directory)
updated_id = Path(updated_path).parts[-1]
return updated_id


@click.command()
Expand All @@ -79,4 +83,5 @@ def get_landsat(bucket, path, output_directory):
type=click.Path(),
)
def main(bucket, path, output_directory):
get_landsat(bucket, path, output_directory)
id = get_landsat(bucket, path, output_directory)
click.echo(id)
10 changes: 7 additions & 3 deletions tests/test_download_landsat.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

BUCKET = "usgs-landsat1"
BASE_KEY = "collection02/level-1/standard/oli-tirs/2021/155/018"
RT_KEY = f"{BASE_KEY}/LC08_L1TP_155018_20210603_20210603_02_RT"
T1_KEY = f"{BASE_KEY}/LC08_L1TP_155018_20210603_20210608_02_T1"
RT_ROOT = "LC08_L1TP_155018_20210603_20210603_02_RT"
RT_KEY = f"{BASE_KEY}/{RT_ROOT}"
T1_ROOT = "LC08_L1TP_155018_20210603_20210608_02_T1"
T1_KEY = f"{BASE_KEY}/{T1_ROOT}"


@pytest.fixture(scope="module")
Expand Down Expand Up @@ -60,8 +62,9 @@ def test_download_updated_tier(s3, tmp_path):
fo = io.BytesIO(b"file object in RAM")
filename = "t1.json"
s3.upload_fileobj(fo, BUCKET, f"{T1_KEY}/{filename}")
get_landsat(BUCKET, RT_KEY, str(tmp_path))
actual = get_landsat(BUCKET, RT_KEY, str(tmp_path))
assert os.path.isfile(tmp_path.joinpath(filename))
assert actual == T1_ROOT


def test_download_landsat_cli(s3, tmp_path):
Expand All @@ -72,3 +75,4 @@ def test_download_landsat_cli(s3, tmp_path):
runner = CliRunner(echo_stdin=True)
result = runner.invoke(main, [BUCKET, RT_KEY, str(tmp_path)])
assert result.exit_code == 0
assert result.output == f"{RT_ROOT}\n"

0 comments on commit b9b3de2

Please sign in to comment.