Interactive interface for browsing global, full-resolution satellite imagery
only request metadata for each collection once, store collection metadata in its own property within wv.json instead of on each layer
Jason Kent35330c5114d5
diff --git a/tasks/python3/getCollectionData.py b/tasks/python3/getCollectionData.pyindex d974ae1ad..2f5cd4d32 100755--- a/tasks/python3/getCollectionData.py+++ b/tasks/python3/getCollectionData.py@@ -22,22 +22,22 @@ cmr_umm_collection_url = 'http://cmr.earthdata.nasa.gov/search/collections.umm_j# Commenting out most keys for now since we aren't using this data yetcmr_keys_map = {'id': 'conceptId',- # 'title': 'title',+ 'title': 'title','processing_level_id': 'processingLevelId','archive_center': 'archiveCenter','data_center': 'dataCenter',- # 'organizations': 'organizations',- # 'score': 'score'+ 'organizations': 'organizations',+ 'score': 'score'}cmr_umm_keys_map = {- # 'ScienceKeywords': 'scienceKeywords',+ 'ScienceKeywords': 'scienceKeywords','AncillaryKeywords': 'ancillaryKeywords',# 'TemporalExtents': 'temporalExtents',- # 'ProcessingLevel': 'processingLevel',+ 'ProcessingLevel': 'processingLevel','Version': 'version',- # 'Projects': 'projects',- # 'Platforms': 'platforms',- # 'DataCenters': 'dataCenters'+ 'Projects': 'projects',+ 'Platforms': 'platforms',+ 'DataCenters': 'dataCenters'}parser = OptionParser(usage="Usage: %s <input_file> <output_file>" % prog)@@ -47,50 +47,53 @@ output_file = args[1]def process_entries(entry, keep_keys):- new_entry = {}- for origKey, newKey in keep_keys.items():- new_entry[newKey] = entry.get(origKey)- return new_entry+ return entry+ # TODO filter out properties we keep+ # new_entry = {}+ # for origKey, newKey in keep_keys.items():+ # new_entry[newKey] = entry.get(origKey)+ # return new_entrydef get_cmr_data(wv_id, concept_id):+ if cmr_data.get(concept_id) is not None:+ returnresponse = 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) is 1:cmr_entry_dict = process_entries(entry[0], cmr_keys_map)- cmr_data[wv_id].update(cmr_entry_dict)+ cmr_data[concept_id] = cmr_entry_dictelif len(entry) > 1:print("%s: WARNING: multiple entries found for %s:%s ", (prog, wv_id, concept_id))def get_cmr_umm_data(wv_id, concept_id):+ if cmr_umm_data.get(concept_id) is not None:+ returnresponse = http.request('GET', cmr_umm_collection_url + concept_id)data = json.loads(response.data.decode('utf-8'))items = data.get('items', [])if len(items) is 1:entry = items[0].get('umm', {})cmr_entry_dict = process_entries(entry, cmr_umm_keys_map)- cmr_umm_data[wv_id].update(cmr_entry_dict)+ cmr_umm_data[concept_id] = cmr_entry_dictelif len(items) > 1:print("%s: WARNING: multiple entries found for %s:%s ", (prog, wv_id, concept_id))def process_requests(wv_product_dict):- for key in wv_product_dict:- cmr_data[key] = {}- cmr_umm_data[key] = {}-futures = []with ThreadPoolExecutor() as executor:- for wv_id, c_id in wv_product_dict.items():+ for wv_id, val in wv_product_dict.items():+ c_id = val['conceptId']futures.append(executor.submit(get_cmr_data, wv_id, c_id))futures.append(executor.submit(get_cmr_umm_data, wv_id, c_id))for f in futures:try:f.result()except Exception as e:- print(e)+ print("%s: ERROR: %s" % (prog,e))collection_data = dict_merge(cmr_data, cmr_umm_data)no_data_count = 0@@ -109,10 +112,10 @@ def process_requests(wv_product_dict):#MAINwith open(input_file, 'rt') as concept_id_map:wv_product_dict = json.load(concept_id_map)- print('%s: Fetching collection data for %s items...' % (prog, len(wv_product_dict)))+ print('%s: Fetching collection data for %s layers...' % (prog, len(wv_product_dict)))collection_data = process_requests(wv_product_dict)with open(output_file, "w") as fp:# Format of this object will determine how this data is combined into wv.json- json.dump({ 'layers': collection_data }, fp)\ No newline at end of file+ json.dump({ 'collections': collection_data }, fp, indent=2, sort_keys=True)\ No newline at end of file