Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Build replaced with colormaps instead of SLD

Mike McGanndbf29125adb0
diff --git a/bin/SLDtoHTML.py b/bin/SLDtoHTML.py
deleted file mode 100755
index 444788f90..000000000
--- a/bin/SLDtoHTML.py
+++ /dev/null
@@ -1,174 +0,0 @@
-#!/usr/bin/env python
-
-'''
-Created on Nov 15, 2013
-
-@author: mcechini
-'''
-
-import colorsys
-from xml.dom import minidom
-from xml.dom import Node
-import sys, getopt
-
-class ColorMapEntry():
- quantity = None
- label = ""
- opacity = None
- color = ""
-
- def __hash__(self):
- return hash(self.quantity)
-
- def __cmp__(self, other):
- return self.quantity.cmp(other.quantity)
-
- def __eq__(self, other):
- return self.quantity.eq(other.quantity)
-
-
-class NamedLayer():
- name = ""
- entries = []
-
- def __hash__(self):
- return hash(self.name)
-
- def __cmp__(self, other):
- return self.name.cmp(other.name)
-
- def __eq__(self, other):
- return self.name.eq(other.name)
-
-## Global Variables ##
-layerList = []
-
-## Functions ##
-def getText(nodelist):
- rc = []
- for node in nodelist:
- if node.nodeType == node.TEXT_NODE:
- rc.append(node.data)
- return ''.join(rc)
-
-
-## START Parse SLD ##
-def parseSLD(sourceXml) :
-
- xmldoc = minidom.parse(sourceXml)
- opacity = None
-
- #for childNode in xmldoc.documentElement.childNodes :
- for nlNode in xmldoc.documentElement.getElementsByTagName("NamedLayer") :
-
- namedLayer = NamedLayer()
- namedLayer.entries = []
-
- for nlChildNode in nlNode.childNodes :
- if nlChildNode.nodeType == Node.ELEMENT_NODE :
- if nlChildNode.nodeName == "Name" or nlChildNode.nodeName == "se:Name" :
- namedLayer.name = getText(nlChildNode.childNodes)
- if nlChildNode.nodeName == "UserStyle" :
- opacity = None
- rasterSyms = nlChildNode.getElementsByTagName("RasterSymbolizer")
- if not rasterSyms:
- rasterSyms = nlChildNode.getElementsByTagName("se:RasterSymbolizer")
- for rasterSym in rasterSyms :
- for rsymChildNode in rasterSym.childNodes :
- if rsymChildNode.nodeType == Node.ELEMENT_NODE :
- if rsymChildNode.nodeName == "Opacity" :
- opacity = float(getText(rsymChildNode.childNodes))
- if rsymChildNode.nodeName == "ColorMap" or rsymChildNode.nodeName == "se:ColorMap":
- for entryNode in rsymChildNode.getElementsByTagName("ColorMapEntry") :
- attrDict = dict(entryNode.attributes.items())
-
- cmEntry = ColorMapEntry()
-
- if 'opacity' in attrDict :
- cmEntry.opacity = float(attrDict['opacity'])
- elif opacity != None :
- cmEntry.opacity = opacity
-
- if 'quantity' in attrDict :
- cmEntry.quantity = float(attrDict['quantity'])
-
- cmEntry.label = attrDict.get('label', '')
- cmEntry.color = attrDict['color']
-
-
- namedLayer.entries.append(cmEntry)
-
- layerList.append(namedLayer)
-
-
-## END Parse SLD ##
-
-def is_bright(color):
- """
- http://24ways.org/2010/calculating-color-contrast
- """
- r = int(color[1:3], 16)
- g = int(color[3:5], 16)
- b = int(color[5:7], 16)
- yiq = ((r * 299) + (g * 587) + (b * 144)) / 1000
- return yiq > 128
-
-## START Generate HTML ##
-def generateHTML(sldFile) :
-
- for layer in layerList :
- print("<!doctype html>")
- print("<html>")
- print("<head>")
- print('<link rel="stylesheet" type="text/css" href="resources/sld.css">')
- print("</head>")
- print("<body>")
-
- print("<h1>" + layer.name + "</h1>")
-
- print("<p>Download SLD file <a href=\"" + sldFile + "\">here</a><br><br>")
-
- print("<table>")
-
- print(" <tr>")
- print(" <th>Color</th>")
- print(" <th class='opacity'>Opacity</th>")
- print(" <th class='data-value'>Label</th>")
- print(" <th class='data-value'>Quantity</th>")
- print(" </tr>")
-
- for entry in layer.entries :
- print(" <tr>")
- print(" <td class='color' bgcolor=" + entry.color + ">" +
- "<font color=\"" + ("black" if is_bright(entry.color) else "white") + "\">" +
- entry.color + "</font></td>")
- print(" <td class='opacity'>" + (str(entry.opacity) if entry.opacity != None else "") + "</td>")
- print(" <td class='data-value'>" + entry.label.encode('ascii', 'xmlcharrefreplace') + "</td>")
- print(" <td class='data-value'>" + (str(entry.quantity) if entry.quantity != None else "") + "</td>")
- print(" </tr>")
-
- print("</table>")
- print("</body>")
- print("</html>")
-
-def main(argv):
-
- sldFile = ""
-
- try:
- opts, args = getopt.getopt(argv,"hi:s:",["sld="])
- except getopt.GetoptError:
- print ("MercatorDriver.py -s <sld>")
- sys.exit(2)
- for opt, arg in opts:
- if opt == '-h':
- print ("MercatorDriver.py -s <sld>")
- sys.exit()
- elif opt in ("-s", "--sld"):
- sldFile = arg
-
- parseSLD(sldFile)
- generateHTML(sldFile)
-
-if __name__ == "__main__":
- main(sys.argv[1:])
diff --git a/bin/fetch-gibs b/bin/fetch-gibs
deleted file mode 100755
index 73bfec3d4..000000000
--- a/bin/fetch-gibs
+++ /dev/null
@@ -1,27 +0,0 @@
-#!/bin/bash
-#
-# NASA Worldview
-#
-# This code was originally developed at NASA/Goddard Space Flight Center for
-# the Earth Science Data and Information System (ESDIS) project.
-#
-# Copyright (C) 2013 - 2014 United States Government as represented by the
-# Administrator of the National Aeronautics and Space Administration.
-# All Rights Reserved.
-#
-
-BASEDIR=$(dirname "$0")
-[ "$DESTDIR" ] || DESTDIR="$BASEDIR"/../build/gc
-[ "$GIBS_HOST" ] || GIBS_HOST="map1"
-GIBS_URL="http://${GIBS_HOST}.vis.earthdata.nasa.gov"
-
-mkdir -p $DESTDIR
-echo $GIBS_URL >&2
-curl -s -o $DESTDIR/gibs-geographic.xml \
- "$GIBS_URL"/wmts-geo/wmts.cgi?request=GetCapabilities
-curl -s -o $DESTDIR/gibs-arctic.xml \
- "$GIBS_URL"/wmts-arctic/wmts.cgi?request=GetCapabilities
-curl -s -o $DESTDIR/gibs-antarctic.xml \
- "$GIBS_URL"/wmts-antarctic/wmts.cgi?request=GetCapabilities
-curl -s -o $DESTDIR/gibs-webmerc.xml \
- "$GIBS_URL"/wmts-webmerc/wmts.cgi?request=GetCapabilities
diff --git a/bin/gibs2wv b/bin/gibs2wv
deleted file mode 100755
index 1648a249f..000000000
--- a/bin/gibs2wv
+++ /dev/null
@@ -1,112 +0,0 @@
-#!/usr/bin/env python
-#
-# NASA Worldview
-#
-# This code was originally developed at NASA/Goddard Space Flight Center for
-# the Earth Science Data and Information System (ESDIS) project.
-#
-# Copyright (C) 2013 - 2014 United States Government as represented by the
-# Administrator of the National Aeronautics and Space Administration.
-# All Rights Reserved.
-#
-
-from datetime import datetime, date, timedelta
-import json
-from optparse import OptionParser
-import os
-import sys
-import xmltodict
-
-SKIP_LAYERS = [
- "Sea_Surface_Temp_Microwave",
- "Sea_Surface_Temp_Blended",
- "arctic_graticule_3413_reverb",
- "blue_marble_arctic",
- "OMI_SO2_Planetary_Boundary_Layer",
-]
-
-prog = os.path.basename(__file__)
-base_dir = os.path.join(os.path.dirname(__file__), "..")
-version = "1.0.0"
-help_description = """\
-Extracts configuration information from a GetCapabilities file.
-"""
-
-parser = OptionParser(usage="Usage: %s [options] file [file...]" % prog,
- version="%s version %s" % (prog, version),
- epilog=help_description)
-(options, args) = parser.parse_args()
-
-wv = {
- "layers": {}
-}
-
-for filename in args:
- with open(filename) as fp:
- xml = fp.read()
- gc = xmltodict.parse(xml)
-
- gc_contents = gc["Capabilities"]["Contents"]
- wv_layers = wv["layers"]
- for gc_layer in gc_contents["Layer"]:
-
- id = gc_layer["ows:Identifier"]
- if id in SKIP_LAYERS:
- sys.stderr.write("Skipping layer: {0}\n".format(id))
- continue
- if id not in wv_layers:
- wv_layers[id] = {}
- wv_layer = wv_layers[id]
-
- wv_layer["id"] = id
- wv_layer["type"] = "wmts"
- wv_layer["format"] = gc_layer["Format"]
-
- # Extract start and end dates
- if "Dimension" in gc_layer:
- dimension = gc_layer["Dimension"]
- if dimension["ows:Identifier"] == "time":
- try:
- wv_layer["period"] = "daily"
- values = dimension["Value"].split("/")
-
- # Layer is still actively being produced if the end date
- # greater than yesterday
- end_date = datetime.strptime(values[1], "%Y-%m-%d")
- yesterday = datetime.now() - timedelta(days=1)
- wv_layer["startDate"] = values[0]
- if end_date < yesterday:
- wv_layer["endDate"] = values[1]
- except ValueError:
- raise Exception("Invalid time: {0}".format(values))
-
- # Extract matrix set
- matrixSet = gc_layer["TileMatrixSetLink"]["TileMatrixSet"]
- if not "projections" in wv_layer:
- wv_layer["projections"] = {}
- if matrixSet.startswith("EPSG4326"):
- wv_layer["projections"]["geographic"] = {
- "source": "GIBS:geographic",
- "matrixSet": "GIBS:" + matrixSet
- }
- if matrixSet.startswith("EPSG3413"):
- wv_layer["projections"]["arctic"] = {
- "source": "GIBS:arctic",
- "matrixSet": "GIBS:" + matrixSet
- }
- if matrixSet.startswith("EPSG3031"):
- wv_layer["projections"]["antarctic"] = {
- "source": "GIBS:antarctic",
- "matrixSet": "GIBS:" + matrixSet
- }
- if matrixSet.startswith("GoogleMaps"):
- wv_layer["projections"]["webmerc"] = {
- "source": "GIBS:webmerc",
- "matrixSet": matrixSet
- }
-
-json_options = {}
-json_options["indent"] = 4
-json_options["separators"] = (',', ': ')
-
-print json.dumps(wv, **json_options)
diff --git a/bin/make-conf b/bin/make-conf
deleted file mode 100755
index 1fdc1aaa9..000000000
--- a/bin/make-conf
+++ /dev/null
@@ -1,43 +0,0 @@
-#!/bin/bash
-#
-# NASA Worldview
-#
-# This code was originally developed at NASA/Goddard Space Flight Center for
-# the Earth Science Data and Information System (ESDIS) project.
-#
-# Copyright (C) 2013 - 2014 United States Government as represented by the
-# Administrator of the National Aeronautics and Space Administration.
-# All Rights Reserved.
-#
-
-set -e
-
-BASE_DIR=$(dirname "$0")
-BUILD_DIR="$BASE_DIR"/../build/conf
-DEBUG_DIR="$BASE_DIR"/../build/worldview-debug/web/conf
-
-rm -rf $BUILD_DIR ; mkdir -p $BUILD_DIR
-rm -rf $DEBUG_DIR ; mkdir -p $DEBUG_DIR
-
-cp -r $BASE_DIR/../conf/* $BUILD_DIR
-
-[ "$GIBS_HOST" ] || GIBS_HOST="map1"
-sed -i -e s/@GIBS_HOST@/${GIBS_HOST}/g "$BUILD_DIR"/web/main/sources.json
-rm -f "$BUILD_DIR"/web/main/sources.json-e
-
-"$BASE_DIR"/gibs2wv "$BUILD_DIR"/../gc/*.xml \
- > "$BUILD_DIR"/web/main/gc.json
-if [ -e "$BUILD_DIR"/web/brand ] ; then
- cp -r "$BUILD_DIR"/web/brand "$BUILD_DIR"/web/main
-fi
-"$BASE_DIR"/conf-cat --input-dir "$BUILD_DIR"/web/main \
- > "$DEBUG_DIR"/wv.json
-"$BASE_DIR"/conf-cat --input-dir "$BUILD_DIR"/web/palettes/custom \
- > "$DEBUG_DIR"/palettes.json
-cp -r "$BUILD_DIR"/web/palettes/rendered \
- "$DEBUG_DIR"/palettes
-"$BASE_DIR"/sld2wv --output-dir "$DEBUG_DIR"/palettes \
- "$BUILD_DIR"/sld/*.xml
-
-
-cp -r "$DEBUG_DIR" "$BASE_DIR"/../src
diff --git a/bin/sld2wv b/bin/sld2wv
deleted file mode 100755
index 32670b96c..000000000
--- a/bin/sld2wv
+++ /dev/null
@@ -1,72 +0,0 @@
-#!/usr/bin/env python
-#
-# NASA Worldview
-#
-# This code was originally developed at NASA/Goddard Space Flight Center for
-# the Earth Science Data and Information System (ESDIS) project.
-#
-# Copyright (C) 2013 - 2014 United States Government as represented by the
-# Administrator of the National Aeronautics and Space Administration.
-# All Rights Reserved.
-#
-
-import json
-from optparse import OptionParser
-import os
-import xmltodict
-
-prog = os.path.basename(__file__)
-base_dir = os.path.join(os.path.dirname(__file__), "..")
-version = "1.0.0"
-help_description = """\
-Convert an SLD document to a JSON palette suitable for Worldview.
-"""
-
-parser = OptionParser(usage="Usage: %s [options] sld_file output_dir" % prog,
- version="%s version %s" % (prog, version),
- epilog=help_description)
-parser.add_option("-o", "--output-dir", default=".",
- help="Use this for output instead of the current directory")
-(options, args) = parser.parse_args()
-if len(args) < 0:
- parser.error("Missing required arguments")
-output_dir = options.output_dir
-
-def to_list(v):
- if not isinstance(v, list):
- v = [v]
- return v
-
-for input_file in args:
- #print input_file
- with open(input_file) as fp:
- xml = fp.read()
- sld = xmltodict.parse(xml)
-
- layers = to_list(sld["StyledLayerDescriptor"]["NamedLayer"])
- for layer in layers:
- name = layer["Name"]
- rule = layer["UserStyle"]["FeatureTypeStyle"]["Rule"]
- symbolizers = to_list(rule["RasterSymbolizer"])
- colors = []
- values = []
- for sym in symbolizers:
- if "Opacity" in sym and float(sym["Opacity"]) == 0:
- break
- if len(colors) > 0:
- raise "Multiple symbolizers"
- for entry in to_list(sym["ColorMap"]["ColorMapEntry"]):
- opacity = 1
- if "@opacity" in entry:
- opacity = float(entry["@opacity"])
- if opacity == 0:
- continue
- colors += [entry["@color"][1:7]]
- values += [entry.get("@label", "")]
- palette = {
- "id": name,
- "colors": colors,
- "values": values
- }
- with open(os.path.join(output_dir, name + ".json"), "w") as fp:
- json.dump(palette, fp)
diff --git a/bin/sld_index.py b/bin/sld_index.py
deleted file mode 100755
index bbc2e5cf9..000000000
--- a/bin/sld_index.py
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/env python
-
-import os
-
-print """
-<!doctype html>
-<html>
-<head>
-<link rel="stylesheet" type="text/css" href="resources/sld.css">
-</head>
-</body>
-<body>
-<h1>GIBS Styled Layer Descriptors</h1>
-"""
-print "<ul>"
-for file in os.listdir("."):
- if file.endswith(".xml"):
- base = os.path.splitext(file)[0]
- print "<li><a href='%s.html'>%s</a></li>" % (base, base)
-print """
-</ul>
-</body>
-</html>
-"""
diff --git a/bin/wv-options-build b/bin/wv-options-build
index cf6b6c0c2..47d59c967 100755
--- a/bin/wv-options-build
+++ b/bin/wv-options-build
@@ -43,11 +43,21 @@ if [ -e "$BUILD_DIR/config.json" ] ; then
"$BIN_DIR/wv-options-wmts" "$BUILD_DIR/config.json" "$BUILD_DIR/fetch" \
"$BUILD_DIR/config/wv.json/_wmts"
fi
+if [ -e "$BUILD_DIR/colormaps" ] ; then
+ mkdir -p "$BUILD_DIR"/config/palettes
+ find "$BUILD_DIR"/colormaps -type f -exec "$BIN_DIR/wv-options-colormap" \
+ {} "$BUILD_DIR/config/palettes" \;
+fi
configs=$(ls "$BUILD_DIR/config")
for config in $configs; do
- if [ -d "$BUILD_DIR/config/$config" ] ; then
- "$BIN_DIR/wv-options-merge" "$BUILD_DIR/config/$config" \
- "$DEST_DIR/config/$config"
- fi
+ case $config in
+ *.json)
+ "$BIN_DIR/wv-options-merge" "$BUILD_DIR/config/$config" \
+ "$DEST_DIR/config/$config"
+ ;;
+ *)
+ cp -r "$BUILD_DIR/config/$config" "$DEST_DIR/config/$config"
+ ;;
+ esac
done
diff --git a/bin/wv-options-colormap b/bin/wv-options-colormap
new file mode 100755
index 000000000..b426dd860
--- /dev/null
+++ b/bin/wv-options-colormap
@@ -0,0 +1,67 @@
+#!/usr/bin/env python
+#
+# NASA Worldview
+#
+# This code was originally developed at NASA/Goddard Space Flight Center for
+# the Earth Science Data and Information System (ESDIS) project.
+#
+# Copyright (C) 2013 - 2014 United States Government as represented by the
+# Administrator of the National Aeronautics and Space Administration.
+# All Rights Reserved.
+#
+
+from optparse import OptionParser
+import os
+import sys
+import json
+import xmltodict
+
+prog = os.path.basename(__file__)
+base_dir = os.path.join(os.path.dirname(__file__), "..")
+version = "1.0.0"
+help_description = """\
+Converts colormaps to JSON files
+"""
+
+parser = OptionParser(usage="Usage: %s <input_file> <output_dir>" % prog,
+ version="%s version %s" % (prog, version),
+ epilog=help_description)
+
+(options, args) = parser.parse_args()
+if len(args) != 2:
+ parser.error("Invalid number of arguments")
+
+input_file = args[0]
+output_dir = args[1]
+
+with open(input_file) as fp:
+ xml = fp.read()
+colormap = xmltodict.parse(xml)
+
+colors = []
+labels = []
+values = []
+for entry in colormap["ColorMap"]["ColorMapEntry"]:
+ r,g,b = entry["@rgb"].split(",")
+ a = 0 if entry["@transparent"] == "true" else 255
+ color = "{0:02x}{1:02x}{2:02x}{3:02x}".format(int(r), int(g), int(b), a)
+ value = entry["@value"] if "@value" in entry else ""
+ colors += [color]
+ labels += [entry["@label"]]
+ values += [value]
+
+id = os.path.splitext(os.path.basename(input_file))[0]
+data = {
+ "colors": colors,
+ "labels": labels,
+ "values": values,
+ "id": id
+}
+
+json_options = {}
+json_options["indent"] = 4
+json_options["separators"] = (',', ': ')
+
+output_file = os.path.join(output_dir, id + ".json")
+with open(output_file, "w") as fp:
+ json.dump(data, fp, **json_options)