Skip to content

Commit

Permalink
optimize imports
Browse files Browse the repository at this point in the history
  • Loading branch information
jacquelynsmale committed Nov 21, 2023
1 parent 6726ee7 commit b5c92f4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion image_services/opera/make_opera_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from typing import List

import arcpy
from arcgis.gis.server import Server
import boto3
from arcgis.gis.server import Server
from lxml import etree
from osgeo import gdal, osr
from tenacity import Retrying, before_sleep_log, stop_after_attempt, wait_fixed
Expand Down
26 changes: 13 additions & 13 deletions image_services/opera/update_opera_uris.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
import argparse
import csv
import json
import logging
import os
import requests
import boto3
from pathlib import Path
import logging
import json

import boto3
import requests

S3_CLIENT = boto3.client('s3')
log = logging.getLogger(__name__)


def query_cmr(params):
def query_cmr(polarization):
session = requests.Session()
search_url = 'https://cmr.earthdata.nasa.gov/search/granules.umm_json'

params = {
'short_name': 'OPERA_L2_RTC-S1_V1',
'attribute[]': f'string,POLARIZATION,{polarization}',
'page_size': 2000,
}
headers = {}
vsis3_uris = []
while True:
response = session.get(search_url, params=params, headers=headers)
response.raise_for_status()
for granule in response.json()['items']:
for url in granule['umm']['RelatedUrls']:
if url['URL'].startswith('s3://') and url['URL'].endswith('VV.tif'):
if url['URL'].startswith('s3://') and url['URL'].endswith(f'{polarization}.tif'):
vsis3_uris.append(url['URL'].replace('s3://', '/vsis3/'))
break
if 'CMR-Search-After' not in response.headers:
Expand Down Expand Up @@ -56,14 +62,8 @@ def main():
_, _, bucket, _, _ = config['overview_path'].split('/')
csv_file = Path(f'{os.getcwd()}/opera_vsis3_{polarization}.csv')

params = {
'short_name': 'OPERA_L2_RTC-S1_V1',
'attribute[]': f'string,POLARIZATION,{polarization}',
'page_size': 2000,
}

log.info(f'Querying CMR for OPERA {polarization} products')
vsis3_uris = query_cmr(params)
vsis3_uris = query_cmr(polarization)

with open(csv_file, 'w', newline='') as f:
writer = csv.writer(f)
Expand Down

0 comments on commit b5c92f4

Please sign in to comment.