Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

refine getCollectionData, getVisMetadata scripts

Jason Kentb02fd4245db0
diff --git a/tasks/python3/getCollectionData.py b/tasks/python3/getCollectionData.py
index 50198d6a7..9b319f2e9 100755
--- a/tasks/python3/getCollectionData.py
+++ b/tasks/python3/getCollectionData.py
@@ -7,27 +7,23 @@ from util import dict_merge
import os
import json
import sys
-import urllib3
-import certifi
-http = urllib3.PoolManager(
- cert_reqs='CERT_REQUIRED',
- ca_certs=certifi.where()
- )
+import requests
+
prog = os.path.basename(__file__)
-cmr_data = {}
+parser = OptionParser(usage="Usage: %s <input_file>" % prog)
+(options, args) = parser.parse_args()
+input_file = args[0]
+output_file = args[0]
cmr_collection_url = 'http://cmr.earthdata.nasa.gov/search/collections.json?concept_id='
-# Commenting out most keys for now since we aren't using this data yet
+# NOTE: Only using these properties at this time
cmr_keys_map = {
'title': 'title',
'version_id': 'version',
'data_center': 'dataCenter',
}
-
-parser = OptionParser(usage="Usage: %s <input_file>" % prog)
-(options, args) = parser.parse_args()
-input_file = args[0]
-output_file = args[0]
+cmr_data = {}
+cmr_fails = {}
def process_entries(entry, keep_keys):
new_entry = {}
@@ -37,16 +33,14 @@ def process_entries(entry, keep_keys):
def get_cmr_data(concept_id_dict):
concept_id = concept_id_dict["value"]
- if cmr_data.get(concept_id) is not None:
- return
- response = http.request('GET', cmr_collection_url + concept_id)
- data = json.loads(response.data.decode('utf-8'))
- entry = data.get('feed', {}).get('entry')
- if len(entry) == 1:
- cmr_entry_dict = process_entries(entry[0], cmr_keys_map)
- concept_id_dict = dict_merge(concept_id_dict, cmr_entry_dict)
- elif len(entry) > 1:
- print("%s: WARNING: multiple entries found for %s ", (prog, concept_id))
+ if cmr_data.get(concept_id) is None:
+ response = requests.get(cmr_collection_url + concept_id)
+ entry = response.json().get('feed', {}).get('entry')
+ if len(entry) == 1:
+ cmr_data[concept_id] = process_entries(entry[0], cmr_keys_map)
+ elif len(entry) > 1:
+ print("%s: WARNING: multiple entries found for %s ", (prog, concept_id))
+ concept_id_dict = dict_merge(concept_id_dict, cmr_data[concept_id])
def process_requests(wv_product_dict):
futures = []
@@ -55,26 +49,16 @@ def process_requests(wv_product_dict):
for concept_id_dict in layer_dict.get('conceptIds', []):
if type(concept_id_dict) is not str:
futures.append(executor.submit(get_cmr_data, concept_id_dict))
-
for f in futures:
try:
f.result()
except Exception as e:
- print("%s: ERROR: %s" % (prog,e))
- print("%s: Finished processing requests." % (prog))
-
- # collection_data = cmr_data #dict_merge(cmr_data, cmr_umm_data)
- # no_data_count = 0
- # for value in collection_data.values():
- # if len(value.keys()) < 1:
- # # TODO eventually should probably delete empty dict entries.
- # # For now, may be useful to see which products are not returning metadata
- # no_data_count += 1
-
- # success_count = len(collection_data) - no_data_count
- # print("%s: %s collections returned metadata." % (prog, success_count))
- # print("%s: %s collections did not reutrn any metadata." % (prog, no_data_count))
- # return collection_data
+ failed_id = str(e)
+ if cmr_fails.get(failed_id, None) is None:
+ cmr_fails[failed_id] = True
+ print("%s: ERROR: No response for collection: [%s]" % (prog, failed_id))
+ print("%s: %s collections returned metadata." % (prog, len(cmr_data)))
+ print("%s: %s collections did not reutrn any metadata." % (prog, len(cmr_fails)))
#MAIN
with open(input_file, 'rt') as concept_id_map:
diff --git a/tasks/python3/getVisMetadata.py b/tasks/python3/getVisMetadata.py
index b777ac31e..aee7eeae4 100755
--- a/tasks/python3/getVisMetadata.py
+++ b/tasks/python3/getVisMetadata.py
@@ -4,17 +4,11 @@ from concurrent.futures import ThreadPoolExecutor
from optparse import OptionParser
import os
import json
-import urllib3
-import certifi
+import requests
prog = os.path.basename(__file__)
parser = OptionParser(usage="Usage: %s <config> <output_dir>" % prog)
(options, args) = parser.parse_args()
-
-http = urllib3.PoolManager(
- cert_reqs='CERT_REQUIRED',
- ca_certs=certifi.where()
- )
prog = os.path.basename(__file__)
features_file = args[0]
@@ -26,11 +20,11 @@ use_keys = ['conceptIds']
layer_metadata = {}
def get_metadata(layer_id, base_url):
- response = http.request('GET', base_url + layer_id + '.json')
- if (response.status != 200):
+ response = requests.get(base_url + layer_id + '.json')
+ if (response.status_code != 200):
print('%s WARNING: No metadata config found for [%s]' % (prog, layer_id))
return
- layer_metadata[layer_id] = json.loads(response.data.decode('utf-8'))
+ layer_metadata[layer_id] = response.json()
# Remove any props we don't expect to use
metadata_keys = dict(layer_metadata[layer_id]).keys()