Interactive interface for browsing global, full-resolution satellite imagery
Added support for downloading collections based on currently selected date
Ryan Boller37891d4c157a
diff --git a/web/js/data/wv.data.handler.js b/web/js/data/wv.data.handler.jsindex 43a995c33..c1f725a72 100644--- a/web/js/data/wv.data.handler.js+++ b/web/js/data/wv.data.handler.js@@ -21,6 +21,7 @@ wv.data.handler.getByName = function(name) {var map = {"AquaSwathMultiDay": wv.data.handler.aquaSwathMultiDay,"CollectionList": wv.data.handler.collectionList,+ "CollectionMix": wv.data.handler.collectionMix,"List": wv.data.handler.list,"DailyGranuleList": wv.data.handler.dailyGranuleList,"DailyAMSRE": wv.data.handler.dailyAMSRE,@@ -231,6 +232,67 @@ wv.data.handler.collectionList = function(config, model, spec) {return self;};+wv.data.handler.collectionMix = function(config, model, spec) {++ var self = wv.data.handler.base(config, model);+ var nrtHandler;+ var scienceHandler;++ var init = function() {+ var productConfig = config.products[model.selectedProduct];++ var nrtHandlerName = productConfig.nrt.handler;+ var nrtHandlerFactory =+ wv.data.handler.getByName(nrtHandlerName);+ nrtHandler = nrtHandlerFactory(config, model, spec);++ var scienceHandlerName = productConfig.science.handler;+ var scienceHandlerFactory =+ wv.data.handler.getByName(scienceHandlerName);+ scienceHandler = scienceHandlerFactory(config, model, spec);+ };++ self._submit = function() {++ var nrtQueryOptions = {+ time: model.time,+ startTimeDelta: nrtHandler.startTimeDelta,+ endTimeDelta: nrtHandler.endTimeDelta,+ data: config.products[model.selectedProduct].query.nrt+ };+ var nrt = self.cmr.submit(nrtQueryOptions);++ var scienceQueryOptions = {+ time: model.time,+ data: config.products[model.selectedProduct].query.science+ };+ var science = self.cmr.submit(scienceQueryOptions);++ return wv.util.ajaxJoin([+ { item: "nrt", promise: nrt },+ { item: "science", promise: science }+ ]);+ };++ self._processResults = function(data) {+ var useNRT = false;+ if ( data.nrt.length > 0 && data.science.length > 0 ) {+ useNRT = ( model.prefer === "nrt" );+ } else {+ useNRT = ( data.nrt.length > 0 );+ }++ if ( useNRT ) {+ return nrtHandler._processResults(data.nrt);+ } else {+ return scienceHandler._processResults(data.science);+ }+ };++ init();+ return self;+};+wv.data.handler.list = function(config, model, spec) {var self = wv.data.handler.base(config, model);@@ -559,4 +621,3 @@ wv.data.handler.halfOrbit = function(config, model, spec) {init();return self;};-diff --git a/web/service/data/cmr.cgi b/web/service/data/cmr.cgiindex ab8efe708..204f8c519 100755--- a/web/service/data/cmr.cgi+++ b/web/service/data/cmr.cgi@@ -19,12 +19,9 @@ import shutilimport sysfrom urllib2 import Request, urlopen, HTTPError-granule_endpoint = "".join(+cmr_endpoint = "".join(["https://cmr.earthdata.nasa.gov/search/","concepts/search.json?"])-collection_endpoint = "".join(- ["https://cmr.earthdata.nasa.gov/search/",- "collections.json?"])class RequestError(Exception):"""@@ -135,7 +132,7 @@ def aql_date(t):def create_query_string(fields):- return "short_name=" + fields["shortName"].value+ return "short_name=" + fields["shortName"].valuedef create_xml(fields):@@ -192,6 +189,60 @@ def create_xml(fields):return "\n".join(xml)+def create_xml_for_collection(fields):+ """+ Creates an XML document given the provided CGI fields for collections++ Parameters:+ - fields: CGI fields to use a parameters for the CMR query++ Returns:+ - AQL XML document for the CMR query request as a string.+ """++ # It isn't necessary to have the official prolog and DOCTYPE+ xml = ["<?xml version=\"1.0\" encoding=\"UTF-8\"?>"]++ xml += ["<query>", "<for value=\"collections\"/>"]++ xml += ["<dataCenterId>"]+ if "dataCenterId" in fields:+ xml += aql_list(fields.getlist("dataCenterId"))+ else:+ xml += ["<all/>"]+ xml += ["</dataCenterId>"]++ xml += ["<where>"]++ xml += ["<collectionCondition>", "<shortName>"]+ xml += aql_list(fields.getlist("shortName"))+ xml += ["</shortName>", "</collectionCondition>"]++ if "startTime" in fields or "endTime" in fields:+ xml += ["<collectionCondition>", "<temporal>"]++ if "startTime" in fields:+ try:+ start_time = datetime.strptime(fields["startTime"].value, "%Y%m%d%H%M%S%f")+ xml += ["<startDate>", aql_date(start_time), "</startDate>"]+ except ValueError:+ raise RequestError("Invalid startTime: " + fields["startTime"].value)+ if "endTime" in fields:+ try:+ end_time = datetime.strptime(fields["endTime"].value, "%Y%m%d%H%M%S%f")+ xml += ["<stopDate>", aql_date(end_time), "</stopDate>"]+ except ValueError:+ raise RequestError("Invalid endTime: " + fields["endTime"].value)++ if "startTime" in fields or "endTime" in fields:+ xml += ["</temporal>", "</collectionCondition>"]++ xml += ["</where>"]+ xml += ["</query>"]++ return "\n".join(xml)++def query_cmr(url, options, xml):"""Submit an AQL document to CMR and proxy the results to standard out.@@ -257,19 +308,20 @@ def process_request(options):raise RequestError("Missing parameter: %s" % required_field)xml = None- if "collection" not in fields:- xml = create_xml(fields)- if options.xml:- print xml- query_url = granule_endpoint+ if "collection" in fields:+ xml = create_xml_for_collection(fields)else:- query_url = collection_endpoint + create_query_string(fields)+ xml = create_xml(fields)+ if options.xml:+ print xml+if options.url:- print query_url+ print cmr_endpoint+if not options.no_query:- query_cmr(query_url, options, xml)+ query_cmr(cmr_endpoint, options, xml)def parse_options():