Interactive interface for browsing global, full-resolution satellite imagery
add named regular expressions. update docs
Mike McGann3b7280367b16
diff --git a/doc/data_download.md b/doc/data_download.mdindex 20e30cffa..477df40a4 100644--- a/doc/data_download.md+++ b/doc/data_download.md@@ -258,6 +258,20 @@ configuration parameters.Parse out the version field into a numeric value that can used for comparisonoperations.+### TagVersionRegex++Use a regular expression to parse out a version into a numeric value that can+used for comparison operations. Parameters:++* `field`: The name of the field that contains the version+* `namedRegex`: Use `MODISProducerGranuleID` to parse out the version from a+MODIS producer granule ID in the form of+`MOD04_L2.A2016137.2105.061.2017326151115.hdf`+* `regex`: If `namedRegex` is not used, a regular expression used to extract+the version+* `parseVersion`: Use `MODIS` to multiply version numbers below 10 by 10. This+changes MODIS version numbers from 5, 51, 6, 61 to 50, 51, 60, 61.+### TimeFilterKeep granules that meet the following values passed into the `spec`diff --git a/web/js/data/results.js b/web/js/data/results.jsindex 497050e6d..0a878fcc7 100644--- a/web/js/data/results.js+++ b/web/js/data/results.js@@ -707,8 +707,12 @@ export function dataResultsTagVersion() {return self;};+const versionRegex = {+ 'MODISProducerGranuleID': '[^\\.]+\\.[^\\.]+\\.[^\\.]+\\.([^\\.]+)\\.'+};+const versionParsers = {- 'ParseMODISVersion': (strVersion) => {+ 'MODIS': (strVersion) => {let version = Number.parseFloat(strVersion);if (version < 10) {version *= 10;@@ -723,13 +727,28 @@ export function dataResultsTagVersionRegex(spec) {self.name = 'TagVersionRegex';self.process = function (meta, granule) {+ // Continue if not usedif (!spec) {return granule;}- const match = granule[spec.field].match(spec.regex);- let version;+ let regex = versionRegex[spec.namedRegex];+ if (!regex) {+ regex = spec.regex;+ }+ if (!regex) {+ console.warn('no regex', granule);+ return granule;+ }+ const value = granule[spec.field];+ if (!value) {+ console.warn(`no value for ${spec.field}`, granule);+ return granule;+ }+ const match = value.match(regex);if (match) {+ let version = null;let strVersion = match[1];+ // If a parsing function is not named, just convert from floatif (spec.parseVersion) {const parser = versionParsers[spec.parseVersion];if (!parser) {@@ -740,7 +759,10 @@ export function dataResultsTagVersionRegex(spec) {} else {version = Number.parseFloat(strVersion);}- if (Number.isNaN(version)) {++ if (version === null) {+ console.warn('version not assigned', strVersion, granule);+ } else if (Number.isNaN(version)) {console.warn('version is not a number', strVersion, granule);} else {granule.version = version;