Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Modify build options to respect other envs, improve error handling, expand projDict (#6992)

Tom Cariello01bc4075cb9a
diff --git a/doc/config/layers.md b/doc/config/layers.md
index 3f99014c6..993ccb5c6 100644
--- a/doc/config/layers.md
+++ b/doc/config/layers.md
@@ -189,7 +189,7 @@ Note:
Granule layers rely on Common Metadata Repository (CMR) metadata to collect footprint polygon metadata for visible granules.
-The following parameters need to be present in the CMR responsefor the granule layer:
+The following parameters need to be present in the CMR response for the granule layer:
```js
"feed.entry" [
{
diff --git a/tasks/build-options/extractConfigFromWMTS.js b/tasks/build-options/extractConfigFromWMTS.js
index 792150409..778d75777 100644
--- a/tasks/build-options/extractConfigFromWMTS.js
+++ b/tasks/build-options/extractConfigFromWMTS.js
@@ -34,6 +34,12 @@ const options = yargs(hideBin(process.argv))
type: 'string',
description: 'mode'
})
+ .option('features', {
+ demandOption: true,
+ alias: 'f',
+ type: 'string',
+ description: 'features.json file'
+ })
.option('cacheMode', {
demandOption: false,
alias: 'cm',
@@ -43,7 +49,7 @@ const options = yargs(hideBin(process.argv))
.epilog('Extracts configuration information from a WMTS GetCapabilities file, converts the XML to JSON')
const { argv } = options
-if (!argv.config && !argv.inputDir && !argv.outputDir) {
+if (!argv.config && !argv.inputDir && !argv.outputDir && !argv.features) {
throw new Error('Invalid number of arguments')
}
@@ -53,6 +59,16 @@ const inputDir = argv.inputDir
const outputDir = argv.outputDir
const mode = argv.mode
const cacheMode = argv.cacheMode
+const featuresFile = argv.features
+
+let featuresData = fs.readFileSync(featuresFile)
+let features = JSON.parse(featuresData)
+if (fs.existsSync(featuresFile)) {
+ featuresData = fs.readFileSync(featuresFile)
+ features = JSON.parse(featuresData)
+} else {
+ throw new Error(`Error: ${featuresFile} feature file does not exist`)
+}
if (!Object.prototype.hasOwnProperty.call(config, 'wv-options-wmts')) {
throw new Error(`${prog}: Error: "wv-options-wmts" not in config file`)
@@ -330,7 +346,7 @@ async function processLayer (gcLayer, wvLayers, entry) {
const dimension = gcLayer.Dimension
if (dimension && dimension['ows:Identifier']?._text === 'Time') {
try {
- await processTemporalLayer(wvLayer, dimension.Value, entry.source, cacheMode)
+ await processTemporalLayer(wvLayer, dimension.Value, entry.source, cacheMode, features)
} catch (e) {
console.error(`${prog}: ERROR: [${ident}] Temporal processing failed: ${e}`)
}
diff --git a/tasks/build-options/getVisMetadata.js b/tasks/build-options/getVisMetadata.js
index 7dc863935..13bf414c8 100644
--- a/tasks/build-options/getVisMetadata.js
+++ b/tasks/build-options/getVisMetadata.js
@@ -235,13 +235,19 @@ async function getMetadata (layerId, baseUrl, count) {
}
async function handleException (error, layerId, url, count) {
+ if (error.response && error.response.status === 404) {
+ console.warn(`\n ${prog} WARN: Layer ${layerId} not found (404) at ${url}${layerId}.json`)
+ return Promise.reject(new Error(`Layer ${layerId} returned 404`))
+ }
+
if (!count) count = 0
count++
if (count <= 5) {
return getMetadata(layerId, url, count)
} else {
console.warn(`\n ${prog} WARN: Unable to fetch ${layerId} ${error}`)
- return Promise.reject(new Error(`Failed to fetch layer ${layerId}: ${error}`))
+ const msg = error.msg || error
+ return Promise.reject(new Error(`Failed to fetch layer ${layerId}: ${msg}`))
}
}
diff --git a/tasks/build-options/processTemporalLayer.js b/tasks/build-options/processTemporalLayer.js
index 5cf13fc7e..131048570 100644
--- a/tasks/build-options/processTemporalLayer.js
+++ b/tasks/build-options/processTemporalLayer.js
@@ -6,10 +6,24 @@ const projDict = {
'GIBS:geographic': 'epsg4326',
'GIBS:arctic': 'epsg3413',
'GIBS:antarctic': 'epsg3031',
+ 'gibs:epsg3031:best': 'epsg3031',
'GITC:geographic': 'epsg4326',
'GITC:arctic': 'epsg3413',
'GITC:antarctic': 'epsg3031',
- 'GITC:webmercator': 'epsg3857'
+ 'GITC:webmercator': 'epsg3857',
+ 'gibs:epsg3857:nrt': 'epsg3857',
+ 'gibs-epsg4326-best': 'epsg4326',
+ 'gibs-epsg4326-nrt': 'epsg4326',
+ 'gibs-epsg4326-std': 'epsg4326',
+ 'gibs-epsg3413-best': 'epsg3413',
+ 'gibs-epsg3413-nrt': 'epsg3413',
+ 'gibs-epsg3413-std': 'epsg3413',
+ 'gibs-epsg3031-best': 'epsg3031',
+ 'gibs-epsg3031-nrt': 'epsg3031',
+ 'gibs-epsg3031-std': 'epsg3031',
+ 'gibs-epsg3857-best': 'epsg3857',
+ 'gibs-epsg3857-nrt': 'epsg3857',
+ 'gibs-epsg3857-std': 'epsg3857',
}
function toList (val) {
@@ -136,9 +150,15 @@ async function createDateRanges (url, wvLayer, cacheMode) {
return [dateRangeStart, dateRangeEnd, rangeInterval]
}
-async function processTemporalLayer (wvLayer, value, source = 'GIBS:geographic', cacheMode) {
+async function processTemporalLayer (wvLayer, value, source = 'GIBS:geographic', cacheMode, features) {
+ const projectionPath = projDict[source]
+ if (!projectionPath) {
+ console.warn(`Unknown or unmapped source: ${source} for layer ${wvLayer.id}`)
+ return wvLayer
+ }
try {
- const describeDomainsAllUrl = `https://gibs.earthdata.nasa.gov/wmts/${projDict[source]}/best/1.0.0/${wvLayer.id}/default/250m/all/all.xml`
+ const describeDomainsBaseUrl = features?.features?.describeDomains?.url || 'https://gibs.earthdata.nasa.gov';
+ const describeDomainsAllUrl = `${describeDomainsBaseUrl}/wmts/${projDict[source]}/best/1.0.0/${wvLayer.id}/default/250m/all/all.xml`
let [dateRangeStart, dateRangeEnd, rangeInterval] = await createDateRanges(describeDomainsAllUrl, wvLayer, cacheMode)
// Fall back to original ranges if the 'all' endpoint fetch failed
if (!dateRangeStart) {
diff --git a/tasks/build-options/validateOptions.js b/tasks/build-options/validateOptions.js
index 99d84bbd3..0774ef846 100644
--- a/tasks/build-options/validateOptions.js
+++ b/tasks/build-options/validateOptions.js
@@ -20,6 +20,12 @@ const options = yargs(hideBin(process.argv))
type: 'string',
description: 'config directory'
})
+ .option('features', {
+ demandOption: true,
+ alias: 'f',
+ type: 'string',
+ description: 'features.json file'
+ })
.option('cacheMode', {
demandOption: false,
alias: 'cm',
@@ -29,13 +35,23 @@ const options = yargs(hideBin(process.argv))
.epilog('Validates and corrects the configuration files.')
const { argv } = options
-if (!argv.optionsFile && !argv.configDir) {
+if (!argv.optionsFile && !argv.configDir && !argv.features) {
throw new Error('Invalid number of arguments')
}
const optionsFile = argv.optionsFile
const configDir = argv.configDir
const cacheMode = argv.cacheMode
+const featuresFile = argv.features
+
+let featuresData = fs.readFileSync(featuresFile)
+let features = JSON.parse(featuresData)
+if (fs.existsSync(featuresFile)) {
+ featuresData = fs.readFileSync(featuresFile)
+ features = JSON.parse(featuresData)
+} else {
+ throw new Error(`Error: ${featuresFile} feature file does not exist`)
+}
let errorCount = 0
let warningCount = 0
@@ -117,7 +133,7 @@ async function main () {
}
if ('temporal' in layer) {
warn(`[${layerId}] GC Layer temporal values overwritten by Options`)
- layer = await processTemporalLayer(layer, layer.temporal, undefined, cacheMode)
+ layer = await processTemporalLayer(layer, layer.temporal, undefined, cacheMode, features)
}
if (layer.futureTime) {
if ('endDate' in layer) delete layer.endDate
diff --git a/tasks/buildOptions.sh b/tasks/buildOptions.sh
index ec7b8e949..846d400df 100755
--- a/tasks/buildOptions.sh
+++ b/tasks/buildOptions.sh
@@ -122,6 +122,7 @@ else
--inputDir "$BUILD_DIR/gc" \
--outputDir "$BUILD_DIR/_wmts" \
--mode "$MODE" \
+ --features "$BUILD_DIR/features.json" \
--cacheMode "$CACHE_MODE"`
fi
@@ -226,6 +227,7 @@ else
--optionsFile "$BUILD_DIR/config.json" \
--configDir "$DEST_DIR/config" \
--mode "$MODE" \
+ --features "$BUILD_DIR/features.json" \
--cacheMode "$CACHE_MODE"`
# Fetch preview images from WV Snapshots for any layers which they are missing