question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue downloading LandSat 8 Collection 2

See original GitHub issue

Hello, I encountered an issue downloading some LandSat 8 Collection 2 images with landsatxplore API. The output / error written is :

    raise EarthExplorerError(error_msg)
landsatxplore.errors.EarthExplorerError: Download is not available

I checked on usgs website (earth explorer) that the tile I am looking for is available. Thank you for your help

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

7reactions
fkroebercommented, Jul 9, 2021

I believe this error is due to the wrongly composed url used to query the data from the USGS API. Specifically, I found the data_product_ids specified in landsat/earthexplorer.py to cause the error. To me it seems as they have changed recently and being updated by @yannforget in a corresponding commit https://github.com/yannforget/landsatxplore/commit/de530c1e8b89162960ad07bec9445c4541c9b9a7. But to query older products, the previously used data_product_ids are still necessary. By reimplementing them into earthexplorer.py I was able to download collection 2 data:

At the beginning of earthexplorer.py…

DATA_PRODUCTS = {
    "landsat_tm_c1": "5e83d08fd9932768",
    "landsat_etm_c1": "5e83a507d6aaa3db",
    "landsat_8_c1": "5e83d0b84df8d8c2",
    "landsat_tm_c2_l1": "5e83d0a0f94d7d8d",
    "landsat_etm_c2_l1": "5e83d0d0d2aaa488",
    "landsat_ot_c2_l1": "5e81f14ff4f9941c",
    "landsat_tm_c2_l2": "5e83d11933473426",
    "landsat_etm_c2_l2": "5e83d12aada2e3c5",
    "landsat_ot_c2_l2": "5e83d14f30ea90a9",
    "sentinel_2a": "5e83a42c6eba8084",
}

DATA_PRODUCTS_II = {
    "landsat_tm_c1": "5e83d08fd9932768",
    "landsat_etm_c1": "5e83a507d6aaa3db",
    "landsat_8_c1": "5e83d0b84df8d8c2",
    "landsat_tm_c2_l1": "5e83d0a0f94d7d8d",
    "landsat_etm_c2_l1": "5e83d0d0d2aaa488",
    "landsat_ot_c2_l1": "5e81f14ff4f9941c",
    "landsat_tm_c2_l2": "5e83d11933473426",
    "landsat_etm_c2_l2": "5e83d12aed0efa58",
    "landsat_ot_c2_l2": "5e83d14fec7cae84",
    "sentinel_2a": "5e83a42c6eba8084",
}

… and at the end of the script…

  if not dataset:
      dataset = guess_dataset(identifier)
  if is_display_id(identifier):
      entity_id = self.api.get_entity_id(identifier, dataset)
  else:
      entity_id = identifier
  try:
      url = EE_DOWNLOAD_URL.format(
          data_product_id=DATA_PRODUCTS[dataset], entity_id=entity_id
      )
      filename = self._download(url, output_dir, timeout=timeout, skip=skip)
  except:
      url = EE_DOWNLOAD_URL.format(
          data_product_id=DATA_PRODUCTS_II[dataset], entity_id=entity_id
      )
      filename = self._download(url, output_dir, timeout=timeout, skip=skip)

This may also solve #42

Of course, once again the data_product_ids are hardcoded this way and the construction with a try-except-clause is pretty ugly and just a fast workaround. In the medium term it seems preferable to avoid hard-coding and query the data_product_id for each scene via the USGS API (also in case they change it a again some time). I guess the “dataset-metadata” or “dataset-get-customization” methods can be used for this purpose https://m2m.cr.usgs.gov/api/docs/reference/. I haven’t found time to try and implement it yet, but feel free to pick it up from here.

4reactions
hiewliwencommented, Aug 13, 2021

@fkroeber I made a couple of changes to the data_product_ids as they were not the original codes.

DATA_PRODUCTS_II = {
    "landsat_tm_c1": "5e83d08fd9932768",
    "landsat_etm_c1": "5e83a507d6aaa3db",
    "landsat_8_c1": "5e83d0b84df8d8c2",
    "landsat_tm_c2_l1": "5e83d0a0f94d7d8d",
    "landsat_etm_c2_l1": "5e83d0d08fec8a66",
    "landsat_ot_c2_l1": "5e81f14f92acf9ef",
    "landsat_tm_c2_l2": "5e83d11933473426",
    "landsat_etm_c2_l2": "5e83d12aed0efa58",
    "landsat_ot_c2_l2": "5e83d14fec7cae84",
    "sentinel_2a": "5e83a42c6eba8084",
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Landsat Collection 2 Known Issues | U.S. Geological Survey
In February 2021, the USGS identified an issue with the Landsat 4-7 Collection 2 Quality Assessment (QA) Pixel "Clear" bit (bit 6) under...
Read more >
Downloading Landsat Collection 2 Level-1 Product Bundle ...
I am getting troubled on what to download from the Landsat Collection 2 Level-1 Product Bundle instructions as shown below: Download Options
Read more >
Where to Get Data - Landsat Science - NASA
USGS has made exporting your display and downloading full scenes easy, but the real power of the LandsatLook Viewer is the capability to...
Read more >
Landsat 9 Collection 2 Level-2 Imagery Downloads
Simply put, in order to convert Landsat 8 or 9 imagery to surface reflectance for imagery dates from January 1, 2022, and later,...
Read more >
landsatxplore - PyPI
Search and download Landsat scenes from EarthExplorer. ... Landsat 8 Collection 2 Level 1, landsat_ot_c2_l1. Landsat 8 Collection 2 Level 2 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found