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

Fixed dataset id and download options #110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
41 changes: 19 additions & 22 deletions landsatxplore/earthexplorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@

# IDs of GeoTIFF data product for each dataset
DATA_PRODUCTS = {
# Level 1 datasets
"landsat_tm_c2_l1": ["5e81f14f92acf9ef", "5e83d0a0f94d7d8d", "63231219fdd8c4e5"],
"landsat_etm_c2_l1":[ "5e83d0d0d2aaa488", "5e83d0d08fec8a66"],
"landsat_tm_c1": ["5e83d08fd9932768"],
"landsat_etm_c1": ["5e83a507d6aaa3db"],
"landsat_8_c1": ["5e83d0b84df8d8c2"],
"landsat_tm_c2_l1": ["5e83d0a0f94d7d8d"],
"landsat_etm_c2_l1": ["5e83d0d0d2aaa488", "5e83d0d08fec8a66"],
"landsat_ot_c2_l1": ["632211e26883b1f7", "5e81f14ff4f9941c", "5e81f14f92acf9ef"],
# Level 2 datasets
"landsat_tm_c2_l2": ["5e83d11933473426", "5e83d11933473426", "632312ba6c0988ef"],
"landsat_etm_c2_l2": ["5e83d12aada2e3c5", "5e83d12aed0efa58", "632311068b0935a8"],
"landsat_ot_c2_l2": ["5e83d14f30ea90a9", "5e83d14fec7cae84", "632210d4770592cf"]
"landsat_ot_c2_l2": ["5e83d14f30ea90a9", "5e83d14fec7cae84", "632210d4770592cf"],
"sentinel_2a": ["5e83a42c6eba8084"],
}

def _get_token(body):
Expand Down Expand Up @@ -156,7 +158,6 @@ def download(
dataset=None,
timeout=300,
skip=False,
overwrite=False,
):
"""Download a Landsat scene.

Expand Down Expand Up @@ -185,23 +186,19 @@ def download(
entity_id = self.api.get_entity_id(identifier, dataset)
else:
entity_id = identifier
# Cycle through the available dataset ids until one works
dataset_id_list = DATA_PRODUCTS[dataset]
id_num = len(dataset_id_list)
for id_count, dataset_id in enumerate(dataset_id_list):

# get all possible middle url
all_possible_data_product_id = DATA_PRODUCTS[dataset]

# forloop trying all possible middle url
for possible_data_product_id in all_possible_data_product_id:
try:
url = EE_DOWNLOAD_URL.format(
data_product_id=dataset_id, entity_id=entity_id
data_product_id=possible_data_product_id, entity_id=entity_id
)
filename = self._download(
url, output_dir, timeout=timeout, skip=skip, overwrite=overwrite
)
break
except EarthExplorerError:
if id_count+1 < id_num:
print('Download failed with dataset id {:d} of {:d}. Re-trying with the next one.'.format(id_count+1, id_num))
pass
else:
print('None of the archived ids succeeded! Update necessary!')
raise EarthExplorerError()

filename = self._download(url, output_dir, timeout=timeout, skip=skip)
except Exception as e:
print(f"Download failed with error stats {e}")
# change to return success for check
return filename