Skip to content

Instantly share code, notes, and snippets.

@asjohnston-asf
Last active February 6, 2025 18:01
Show Gist options
  • Save asjohnston-asf/744401bd573a7aa722a97ca4c6bc074c to your computer and use it in GitHub Desktop.
Save asjohnston-asf/744401bd573a7aa722a97ca4c6bc074c to your computer and use it in GitHub Desktop.
Find download URLs for OPERA DISP products in ASF non-production archive by product version and frame id
import requests
def get_download_url(product: dict, protocol: str) -> str:
if protocol not in ['https', 's3']:
raise ValueError(f'Unknown protocol {protocol}; must be https or s3')
for url in product['umm']['RelatedUrls']:
if url['Type'].startswith('GET DATA') and url['URL'].startswith(protocol):
return url['URL']
raise ValueError(f'No download URL found for granule {product['umm']['GranuleUR']}')
def get_products(frame_id: int, product_version: str) -> list[dict]:
# https://cmr.earthdata.nasa.gov/search/site/docs/search/api.html
url = 'https://cmr.uat.earthdata.nasa.gov/search/granules.umm_json'
params = {
'short_name': 'OPERA_L3_DISP-S1_V1',
'attribute[]': [
f'float,PRODUCT_VERSION,{product_version}',
f'int,FRAME_NUMBER,{frame_id}',
],
'page_size': 2000,
}
headers = {}
products = []
while True:
response = requests.get(url, params=params, headers=headers)
response.raise_for_status()
products.extend(response.json()['items'])
if 'CMR-Search-After' not in response.headers:
break
headers['CMR-Search-After'] = response.headers['CMR-Search-After']
return products
for product in get_products(frame_id=18904, product_version='0.9'):
print(get_download_url(product, protocol='https'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment