Interactive interface for browsing global, full-resolution satellite imagery
get additional collection data at build time
Jason Kent7b6f154cc4b9
diff --git a/tasks/buildOptions.sh b/tasks/buildOptions.shindex 343f3500a..2162b0f56 100755--- a/tasks/buildOptions.sh+++ b/tasks/buildOptions.sh@@ -117,13 +117,6 @@ if [ -e "$BUILD_DIR/colormaps" ] ; then"$BUILD_DIR/config/palettes"fi-# Run getCollectionData.py to fetch collection metadata-# Disabled for now-# if [ -e "$BUILD_DIR/config/wv.json/conceptIds.json" ] ; then-# "$PYTHON_SCRIPTS_DIR/getCollectionData.py" "$BUILD_DIR/config/wv.json/conceptIds.json" \-# "$BUILD_DIR/config/wv.json/collections.json"-# fi-# Throw error if no categoryGroupOrder.json file presentif [ ! -e "$BUILD_DIR/config/wv.json/categoryGroupOrder.json" ] ; thenecho "categoryGroupOrder.json not found. Generating..."@@ -135,6 +128,11 @@ fi"$PYTHON_SCRIPTS_DIR/getVisMetadata.py" "$BUILD_DIR/features.json" \"$BUILD_DIR/config/wv.json/layerOrder.json" "$BUILD_DIR/config/wv.json/layer-metadata.json"+ # Run getCollectionData.py to fetch collection metadata+if [ -e "$BUILD_DIR/config/wv.json/layer-metadata.json" ] ; then+ "$PYTHON_SCRIPTS_DIR/getCollectionData.py" "$BUILD_DIR/config/wv.json/layer-metadata.json"+fi+# Run mergeConfig.py on all directories in /configconfigs=$(ls "$BUILD_DIR/config")for config in $configs; dodiff --git a/tasks/python3/getCollectionData.py b/tasks/python3/getCollectionData.pyindex 5df4e1e8c..50198d6a7 100755--- a/tasks/python3/getCollectionData.py+++ b/tasks/python3/getCollectionData.py@@ -15,116 +15,72 @@ http = urllib3.PoolManager()prog = os.path.basename(__file__)cmr_data = {}-cmr_umm_data = {}cmr_collection_url = 'http://cmr.earthdata.nasa.gov/search/collections.json?concept_id='-cmr_umm_collection_url = 'http://cmr.earthdata.nasa.gov/search/collections.umm_json?concept_id='# Commenting out most keys for now since we aren't using this data yetcmr_keys_map = {'title': 'title',- 'processing_level_id': 'processingLevelId',+ 'version_id': 'version','data_center': 'dataCenter',- 'collection_data_type': 'collectionDataType'}-cmr_umm_keys_map = {- # 'ScienceKeywords': 'scienceKeywords',- # 'AncillaryKeywords': 'ancillaryKeywords',- 'Version': 'version',- 'Projects': 'projects',- 'Platforms': 'platforms'- }-parser = OptionParser(usage="Usage: %s <input_file> <output_file>" % prog)+parser = OptionParser(usage="Usage: %s <input_file>" % prog)(options, args) = parser.parse_args()input_file = args[0]-output_file = args[1]---def processProjects (orig_value):- projects = []- for value in orig_value:- projects.append(value['ShortName'])- return projects--def processPlatforms (orig_value):- platforms = []- for value in orig_value:- platforms.append(value['ShortName'])- return platforms+output_file = args[0]def process_entries(entry, keep_keys):new_entry = {}for orig_key, new_key in keep_keys.items():- if (orig_key is 'Platforms'):- new_entry[new_key] = processPlatforms(entry.get(orig_key, []))- elif (orig_key is 'Projects'):- new_entry[new_key] = processProjects(entry.get(orig_key, []))- else:- new_entry[new_key] = entry.get(orig_key)+ new_entry[new_key] = entry.get(orig_key)return new_entry--def get_cmr_data(wv_id, concept_id):+def get_cmr_data(concept_id_dict):+ concept_id = concept_id_dict["value"]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:+ if len(entry) == 1:cmr_entry_dict = process_entries(entry[0], cmr_keys_map)- cmr_data[concept_id] = cmr_entry_dict+ concept_id_dict = dict_merge(concept_id_dict, cmr_entry_dict)elif 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:- return- response = 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[concept_id] = cmr_entry_dict- elif len(items) > 1:- print("%s: WARNING: multiple entries found for %s:%s ", (prog, wv_id, concept_id))-+ print("%s: WARNING: multiple entries found for %s ", (prog, concept_id))def process_requests(wv_product_dict):futures = []with ThreadPoolExecutor() as executor:- for wv_id, val in wv_product_dict.items():- c_id = val['conceptIds']- futures.append(executor.submit(get_cmr_data, wv_id, c_id))- futures.append(executor.submit(get_cmr_umm_data, wv_id, c_id))+ for layer_dict in wv_product_dict.values():+ 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 = 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+ # 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#MAINwith open(input_file, 'rt') as concept_id_map:wv_product_dict = json.load(concept_id_map).get('layers')print('%s: Fetching collection data for %s layers...' % (prog, len(wv_product_dict)))--collection_data = process_requests(wv_product_dict)+ 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({ 'collections': collection_data }, fp, indent=2, sort_keys=True)\ No newline at end of file+ json.dump({ 'layers': wv_product_dict }, fp, indent=2, sort_keys=True)\ No newline at end of file