Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

move vis metadata build process to features.json

Jason Kent66ca5814e9dd
diff --git a/config/default/common/features.json b/config/default/common/features.json
index 329e5a8e0..10d76953f 100644
--- a/config/default/common/features.json
+++ b/config/default/common/features.json
@@ -8,6 +8,9 @@
"tour": true,
"feedback": true,
"previewSnapshots": true,
+ "vismetadata": {
+ "url": "https://uat.gibs.earthdata.nasa.gov/layer-metadata/v1.0/"
+ },
"googleTagManager": {
"id": "GTM-WNP7MLF"
},
diff --git a/tasks/python3/getVisMetadata.py b/tasks/python3/getVisMetadata.py
index 23889d97e..c555657bc 100755
--- a/tasks/python3/getVisMetadata.py
+++ b/tasks/python3/getVisMetadata.py
@@ -11,18 +11,27 @@ http = urllib3.PoolManager(
ca_certs=certifi.where()
)
prog = os.path.basename(__file__)
-parser = OptionParser(usage="Usage: %s <input_file> <output_file>" % prog)
-(options, args) = parser.parse_args()
-input_file = args[0]
-output_file = args[1]
+root_dir = 'config/default/common/'
+
+# Use config/active dir if present
+if os.path.isdir('config/active'):
+ root_dir = 'config/active/common/'
+
+CONFIG_ENV = os.environ.get('CONFIG_ENV')
+
+# If a config enviroment was passed, use the coresponding dir
+if CONFIG_ENV is not None:
+ root_dir = 'config/active/' + CONFIG_ENV + '/'
+
+features_file = root_dir + 'features.json'
+input_file = root_dir + 'config/wv.json/layerOrder.json'
+output_file = 'build/options-build/config/wv.json/visMetadata.json'
-# TODO pull from features config?
-gibs_url = 'https://uat.gibs.earthdata.nasa.gov/layer-metadata/v1.0/'
use_keys = ['conceptIds']
layer_metadata = {}
-def get_metadata(layer_id):
- response = http.request('GET', gibs_url + layer_id + '.json')
+def get_metadata(layer_id, base_url):
+ response = http.request('GET', base_url + layer_id + '.json')
if (response.status != 200):
print('%s WARNING: No metadata config found for [%s]' % (prog, layer_id))
return
@@ -34,8 +43,7 @@ def get_metadata(layer_id):
if key not in use_keys:
layer_metadata[layer_id].pop(key, None)
-#MAIN
-if __name__ == "__main__":
+def main(url):
with open(input_file, 'rt') as layer_order:
layer_ids = json.load(layer_order).get('layerOrder')
print('%s: Pulling vis metadata for %s layers... ' % (prog, len(layer_ids)))
@@ -43,7 +51,7 @@ if __name__ == "__main__":
futures = []
with ThreadPoolExecutor() as executor:
for layer in layer_ids:
- futures.append(executor.submit(get_metadata, layer))
+ futures.append(executor.submit(get_metadata, layer, url))
for f in futures:
try:
# Need to call result() on each future to catch any raised exceptions
@@ -53,4 +61,15 @@ if __name__ == "__main__":
with open(output_file, "w") as fp:
# Format of this object will determine how this data is combined into wv.json
- json.dump({ 'layers': layer_metadata}, fp, indent=2, sort_keys=True)
\ No newline at end of file
+ json.dump({ 'layers': layer_metadata}, fp, indent=2, sort_keys=True)
+
+#MAIN
+if __name__ == "__main__":
+ with open(features_file, 'rt') as features:
+ metadata_config = json.load(features).get('features').get('vismetadata')
+ if metadata_config is not None:
+ url = metadata_config.get('url')
+ main(url)
+ else:
+ print('%s: Visualization metadata not configured. Exiting.' % (prog))
+