Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

WV-2463, WV-2460, WV-2400, WV-2462: Granule layer fixes (#4003)

Jason Kent7414cec3c665
diff --git a/web/js/components/layer/settings/granule-count-slider.js b/web/js/components/layer/settings/granule-count-slider.js
index 7cd4ba847..d58e348cc 100644
--- a/web/js/components/layer/settings/granule-count-slider.js
+++ b/web/js/components/layer/settings/granule-count-slider.js
@@ -2,7 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import Slider from 'rc-slider';
import lodashDebounce from 'lodash/debounce';
-import { DEFAULT_NUM_GRANULES } from '../../../modules/layers/constants';
+import { DEFAULT_NUM_GRANULES, MIN_GRANULES, MAX_GRANULES } from '../../../modules/layers/constants';
class GranuleCountSlider extends React.Component {
constructor(props) {
@@ -30,8 +30,8 @@ class GranuleCountSlider extends React.Component {
<div className="layer-granule-count-select settings-component">
<h2 className="wv-header">Granule Count</h2>
<Slider
- min={1}
- max={50}
+ min={MIN_GRANULES}
+ max={MAX_GRANULES}
defaultValue={count}
onChange={(val) => {
this.setState({ value: val });
diff --git a/web/js/fixtures.js b/web/js/fixtures.js
index dd82da3b1..1fdf0a9fe 100644
--- a/web/js/fixtures.js
+++ b/web/js/fixtures.js
@@ -357,6 +357,36 @@ fixtures.config = function() {
endDate: '2019-09-24T23:54:00Z',
source: 'GIBS:geographic:nrt',
matrixSet: '250m',
+ conceptIds: [
+ {
+ shortName: 'VJ102IMG_NRT',
+ title: 'VIIRS/JPSS1 Imagery Resolution 6 Min L1B Swath 375m NRT',
+ type: 'NRT',
+ value: 'C2208779826-LANCEMODIS',
+ version: '2.1',
+ },
+ {
+ shortName: 'VJ103IMG_NRT',
+ title: 'VIIRS/JPSS1 Imagery Resolution Terrain Corrected Geolocation 6 Min L1 Swath 375m NRT',
+ type: 'NRT',
+ value: 'C2208793489-LANCEMODIS',
+ version: '2.1',
+ },
+ {
+ shortName: 'VJ102MOD_NRT',
+ title: 'VIIRS/JPSS1 Moderate Resolution 6 Min L1B Swath 750m NRT',
+ type: 'NRT',
+ value: 'C2208778455-LANCEMODIS',
+ version: '2.1',
+ },
+ {
+ shortName: 'VJ102MOD_NRT',
+ title: 'VIIRS/JPSS1 Moderate Resolution 6-Min L1B Swath 750m NRT',
+ type: 'NRT',
+ value: 'C1604614285-LANCEMODIS',
+ version: '2',
+ },
+ ],
dateRanges: [
{
startDate: '2019-09-23T00:12:00Z',
diff --git a/web/js/map/granule/granule-layer-builder.js b/web/js/map/granule/granule-layer-builder.js
index e4ef1eca5..dabbef0a2 100644
--- a/web/js/map/granule/granule-layer-builder.js
+++ b/web/js/map/granule/granule-layer-builder.js
@@ -14,7 +14,8 @@ import { openBasicContent } from '../../modules/modal/actions';
import { getCacheOptions } from '../../modules/layers/util';
import { getGranulesUrl as getGranulesUrlSelector } from '../../modules/smart-handoff/selectors';
import {
- getCMRQueryDates,
+ getParamsForGranuleRequest,
+ isWithinBounds,
isWithinDateRange,
transformGranuleData,
datelineShiftGranules,
@@ -23,10 +24,14 @@ import {
import util from '../../util/util';
const { toISOStringSeconds } = util;
-const dayNightFilter = 'DAY'; // 'DAY', 'NIGHT', 'BOTH'
export default function granuleLayerBuilder(cache, store, createLayerWMTS) {
- const CMRDataStore = {};
+ const CMRDataStore = {
+ [CRS.WEB_MERCATOR]: {},
+ [CRS.GEOGRAPHIC]: {},
+ [CRS.ANTARCTIC]: {},
+ [CRS.ARCTIC]: {},
+ };
const getGranuleUrl = getGranulesUrlSelector(store.getState());
const baseGranuleUrl = getGranuleUrl();
const CMR_AJAX_OPTIONS = {
@@ -63,31 +68,34 @@ export default function granuleLayerBuilder(cache, store, createLayerWMTS) {
* @param {data} CMR data
* @param {id} layer id
*/
- const addGranuleCMRDateData = (data, conceptId, dateRanges) => {
+ const addGranuleCMRDateData = (data, shortName, dateRanges) => {
const { proj: { selected: { crs } } } = store.getState();
- CMRDataStore[conceptId] = CMRDataStore[conceptId] || [];
+ CMRDataStore[crs][shortName] = CMRDataStore[crs][shortName] || [];
+ const granuleData = CMRDataStore[crs][shortName];
+
data.forEach((entry) => {
const date = toISOStringSeconds(entry.time_start);
- const hasImagery = find(dateRanges, ({ startDate, endDate }) => isWithinDateRange(new Date(date), startDate, endDate));
- const existsForTime = find(CMRDataStore[conceptId], (g) => g.date === date);
+ const hasImagery = find(dateRanges, ({ startDate, endDate }) => isWithinDateRange(date, startDate, endDate));
+ const existsForTime = find(granuleData, (g) => g.date === date);
if (!hasImagery || existsForTime) {
return;
}
const transformedGranule = transformGranuleData(entry, date, crs);
- CMRDataStore[conceptId].push(transformedGranule);
+ granuleData.push(transformedGranule);
});
- return CMRDataStore[conceptId].sort((a, b) => {
+ return granuleData.sort((a, b) => {
const dateA = new Date(a.date).valueOf();
const dateB = new Date(b.date).valueOf();
return dateB - dateA;
});
};
- const datesHaveBeenQueried = (startQueryDate, endQueryDate, existingGranules) => {
+ const datesHaveBeenQueried = (start, end, existingGranules) => {
+ if (!existingGranules.length) return;
const latestDate = new Date(existingGranules[0].date);
const earliestDate = new Date(existingGranules[existingGranules.length - 1].date);
- const startIsCovered = isWithinDateRange(startQueryDate, earliestDate, latestDate);
- const endIsCovered = isWithinDateRange(endQueryDate, earliestDate, latestDate);
+ const startIsCovered = isWithinDateRange(start, earliestDate, latestDate);
+ const endIsCovered = isWithinDateRange(end, earliestDate, latestDate);
return startIsCovered && endIsCovered;
};
@@ -100,50 +108,45 @@ export default function granuleLayerBuilder(cache, store, createLayerWMTS) {
const {
endDate, startDate, title, visible, dateRanges,
} = def;
- const { startQueryDate, endQueryDate } = getCMRQueryDates(date);
- const getGranulesUrl = getGranulesUrlSelector(store.getState());
-
- // TODO: USE GRANULE LAYER conceptId
- const shortName = 'VJ102MOD';
- const conceptId = shortName;
+ const state = store.getState();
+ const { proj: { selected: { crs } } } = state;
+ const getGranulesUrl = getGranulesUrlSelector(state);
+ const params = getParamsForGranuleRequest(def, date, state);
+ const { shortName } = params;
let data = [];
- const existingGranules = CMRDataStore[conceptId] || [];
+ const existingGranules = CMRDataStore[crs][shortName] || [];
+ const datesQueried = datesHaveBeenQueried(params.startDate, date, existingGranules);
- if (existingGranules.length && datesHaveBeenQueried(startQueryDate, endQueryDate, existingGranules)) {
+ if (existingGranules.length && datesQueried) {
return existingGranules;
}
- showLoading();
- try {
- const params = {
- // conceptId,
- shortName,
- startDate: startQueryDate.toISOString(),
- endDate: endQueryDate.toISOString(),
- dayNight: dayNightFilter,
- pageSize: 1000,
- };
- const response = await fetch(getGranulesUrl(params), CMR_AJAX_OPTIONS);
- data = await response.json();
- data = data.feed.entry;
-
- if (data.length === 0) {
- const dateWithinRange = isWithinDateRange(date, startDate, endDate);
- // only show modal error if layer not set to hidden and outside of selected date range
- if (visible && dateWithinRange) {
- throttleDispathCMRErrorDialog(title);
+ const makeQuery = async () => {
+ try {
+ showLoading();
+ const response = await fetch(getGranulesUrl(params), CMR_AJAX_OPTIONS);
+ data = await response.json();
+ data = data.feed.entry;
+ if (data.length) {
+ addGranuleCMRDateData(data, shortName, dateRanges);
+ } else {
+ const dateWithinRange = isWithinDateRange(date, startDate, endDate);
+ // only show modal error if layer not set to hidden and outside of selected date range
+ if (visible && dateWithinRange) throttleDispathCMRErrorDialog(title);
}
+ } catch (e) {
+ console.error(e);
+ throttleDispathCMRErrorDialog(title);
return data;
+ } finally {
+ hideLoading();
}
- } catch (e) {
- console.error(e);
- throttleDispathCMRErrorDialog(title);
- return data;
- } finally {
- hideLoading();
- }
- return addGranuleCMRDateData(data, conceptId, dateRanges);
+ };
+
+ await makeQuery();
+
+ return CMRDataStore[crs][shortName];
};
/**
@@ -198,7 +201,7 @@ export default function granuleLayerBuilder(cache, store, createLayerWMTS) {
const granuleLayer = new OlLayerGroup();
granuleLayer.wv = { ...attributes };
- const dateInRange = isWithinDateRange(date, new Date(startDate), new Date(endDate));
+ const dateInRange = isWithinDateRange(date, startDate, endDate);
if (!dateInRange) {
return granuleLayer;
}
@@ -240,7 +243,7 @@ export default function granuleLayerBuilder(cache, store, createLayerWMTS) {
// get granule dates waiting for CMR query and filtering (if necessary)
const availableGranules = await getQueriedGranuleDates(def, date, group);
- const visibleGranules = filterGranules(availableGranules, count, date);
+ const visibleGranules = getVisibleGranules(availableGranules, count, date);
const transformedGranules = transformGranulesForProj(visibleGranules, crs);
return {
@@ -251,23 +254,33 @@ export default function granuleLayerBuilder(cache, store, createLayerWMTS) {
};
/**
- * Get the last n granule dates
- * @param {Array} granuleDates - granule date/polygon metadata
- * @param {number} granuleCount - number of granules to add to collection
- * @returns {array} collection of granule objects with filtered granuleDates
+ * Get granuleCount number of granules that have visible imagery based on
+ * predetermined longitude bounds.
+ *
+ * @param {Array} availableGranules - available granules to be filtered
+ * @param {number} granuleCount - number of granules to filter down to
+ * @param {Date} leadingEdgeDate - timeline date
+ * @returns {array}
*/
- const filterGranules = (availableGranules, granuleCount, nextDate) => {
+ const getVisibleGranules = (availableGranules, granuleCount, leadingEdgeDate) => {
+ const { proj: { selected: { crs } } } = store.getState();
const granules = [];
- if (!availableGranules.length) return granules;
+ const availableCount = availableGranules.length;
+ if (!availableCount) return granules;
+ const count = granuleCount > availableCount ? availableCount : granuleCount;
- for (let i = 0; granules.length < granuleCount; i += 1) {
+ for (let i = 0; granules.length < count; i += 1) {
const item = availableGranules[i];
+ if (!item) break;
const { date } = item;
- const granuleDate = new Date(date);
- if (granuleDate <= nextDate) {
+ if (new Date(date) <= leadingEdgeDate && isWithinBounds(crs, item)) {
granules.unshift(item);
}
}
+
+ if (granules.length < granuleCount) {
+ console.warn('Could not find enough matching granules', `${granules.length}/${granuleCount}`);
+ }
return granules;
};
diff --git a/web/js/map/granule/granule-layer-builder.test.js b/web/js/map/granule/granule-layer-builder.test.js
index 358c65348..786cc24a6 100644
--- a/web/js/map/granule/granule-layer-builder.test.js
+++ b/web/js/map/granule/granule-layer-builder.test.js
@@ -9,7 +9,7 @@ import { LOADING_GRANULES } from '../../modules/loading/actions';
import { ADD_GRANULE_LAYER_DATES } from '../../modules/layers/constants';
const mockBaseCmrApi = 'mock.cmr.api/';
-const queryString = '?shortName=VJ102MOD&day_night_flag=DAY&temporal=2019-09-24T00%3A54%3A00.000Z%2C2019-09-24T12%3A54%3A00.000Z&pageSize=1000 ';
+const queryString = '?shortName=VJ102IMG&day_night_flag=DAY&temporal=2019-09-22T08%3A54%3A00.000Z%2C2019-09-24T12%3A54%3A00.000Z&pageSize=500';
const cmrGranules = require('../../../mock/cmr_granules.json');
fetchMock.mock(`${mockBaseCmrApi}granules.json${queryString}`, cmrGranules)
@@ -24,16 +24,6 @@ let createGranuleLayer;
let store;
const expectedDates = [
- '2019-09-23T02:18:00Z',
- '2019-09-23T03:42:00Z',
- '2019-09-23T03:48:00Z',
- '2019-09-23T03:54:00Z',
- '2019-09-23T04:00:00Z',
- '2019-09-23T05:18:00Z',
- '2019-09-23T05:24:00Z',
- '2019-09-23T05:30:00Z',
- '2019-09-23T05:36:00Z',
- '2019-09-23T05:42:00Z',
'2019-09-23T07:00:00Z',
'2019-09-23T07:06:00Z',
'2019-09-23T07:12:00Z',
diff --git a/web/js/map/granule/util.js b/web/js/map/granule/util.js
index e41b65a5b..b6481d67e 100644
--- a/web/js/map/granule/util.js
+++ b/web/js/map/granule/util.js
@@ -84,10 +84,32 @@ export const getIndexForSortedInsert = (array, date) => {
* @param {string} endDate - date string
* @returns {boolean}
*/
-export const isWithinDateRange = (date, startDate, endDate) => (startDate && endDate
- ? date.getTime() <= new Date(endDate).getTime() && date.getTime() >= new Date(startDate).getTime()
- : false);
+export const isWithinDateRange = (date, startDate, endDate) => (
+ startDate && endDate
+ ? new Date(date).getTime() <= new Date(endDate).getTime()
+ && new Date(date).getTime() >= new Date(startDate).getTime()
+ : false
+);
+/**
+ * Determine if a granule polygon falls within the specified bounds of
+ * imagery for a given projection
+ *
+ * @param {*} crs
+ * @param {*} granule
+ * @returns
+ */
+export const isWithinBounds = (crs, granule) => {
+ if (crs === CRS.GEOGRAPHIC || crs === CRS.WEB_MERCATOR) {
+ return granule.polygon.every(([lat, lon]) => lon > -65 && lon < 65);
+ }
+ if (crs === CRS.ANTARCTIC) {
+ return granule.polygon.every(([lat, lon]) => lon < -40);
+ }
+ if (crs === CRS.ARCTIC) {
+ return granule.polygon.every(([lat, lon]) => lon > 40);
+ }
+};
export const getGranuleFootprints = (layer) => {
const {
@@ -107,23 +129,65 @@ export const getGranuleFootprints = (layer) => {
};
/**
- * Get CMR query dates for building query string and child processes
- *
- * @method getCMRQueryDates
- * @static
+ * Get start/end dates for CMR granule query. We need a broader range
+ * for polar granules since only a few granules from each swath are
+ * visible at the poles
+ * .
+ * @param {string} crs
* @param {object} selectedDate - date object
* @returns {object}
* @param {object} startQueryDate - date object
* @param {object} endQueryDate - date object
*/
-export const getCMRQueryDates = (selectedDate) => {
+export const getCMRQueryDates = (crs, selectedDate) => {
const date = new Date(selectedDate);
- const startQueryDate = util.dateAdd(date, 'hour', -8);
- const endQueryDate = util.dateAdd(date, 'hour', 4);
+ if (crs === CRS.GEOGRAPHIC || crs === CRS.WEB_MERCATOR) {
+ return {
+ startQueryDate: util.dateAdd(date, 'hour', -12),
+ endQueryDate: util.dateAdd(date, 'hour', 4),
+ };
+ }
+ // Polar projections
+ return {
+ startQueryDate: util.dateAdd(date, 'hour', -48),
+ endQueryDate: util.dateAdd(date, 'hour', 4),
+ };
+};
+
+/**
+ * Get the URL parameters for a CMR request for granule browse
+ * @param {*} def - layer definition
+ * @param {*} date - "current" date from which to base the query
+ * @param {*} crs
+ * @returns
+ */
+export const getParamsForGranuleRequest = (def, date, crs) => {
+ const dayNightFilter = 'DAY';
+ const bboxForProj = {
+ [CRS.WEB_MERCATOR]: [-180, -65, 180, 65],
+ [CRS.GEOGRAPHIC]: [-180, -65, 180, 65],
+ [CRS.ANTARCTIC]: [-180, -90, 180, -65],
+ [CRS.ARCTIC]: [-180, 65, 180, 90],
+ };
+ const { startQueryDate, endQueryDate } = getCMRQueryDates(crs, date);
+
+ const getShortName = () => {
+ try {
+ let { shortName } = def.conceptIds[0];
+ [shortName] = shortName.split('_');
+ return shortName;
+ } catch (e) {
+ console.error(`Could not get shortName for a collection associated with layer ${def.id}`);
+ }
+ };
return {
- startQueryDate,
- endQueryDate,
+ shortName: getShortName(),
+ startDate: startQueryDate.toISOString(),
+ endDate: endQueryDate.toISOString(),
+ dayNight: dayNightFilter,
+ bbox: bboxForProj[crs],
+ pageSize: 500,
};
};
diff --git a/web/js/map/granule/util.test.js b/web/js/map/granule/util.test.js
index 75f8c0124..050424baf 100644
--- a/web/js/map/granule/util.test.js
+++ b/web/js/map/granule/util.test.js
@@ -2,6 +2,7 @@
import {
datelineShiftGranules, getCMRQueryDates, transformGranuleData, areCoordinatesAndPolygonExtentValid,
} from './util';
+import { CRS } from '../../modules/map/constants';
import util from '../../util/util';
const mockGranules = require('../../../mock/granules.json');
@@ -37,16 +38,14 @@ const singleTransformedGranule = {
describe('shifting dateline granules', () => {
it('no shift when datline is crossed with same day', async () => {
const selectedDate = new Date('2019-09-24T00:24:00.000Z');
- const crs = 'EPSG:4326';
- const granules = datelineShiftGranules(mockGranules.three, selectedDate, crs);
+ const granules = datelineShiftGranules(mockGranules.three, selectedDate, CRS.GEOGRAPHIC);
expect(granules).toEqual(mockGranules.three);
});
it('shifts when granules cross days', async () => {
const selectedDate = new Date('2019-09-24T00:12:00.000Z');
- const crs = 'EPSG:4326';
- const shiftedGranules = datelineShiftGranules(mockGranules.two, selectedDate, crs);
+ const shiftedGranules = datelineShiftGranules(mockGranules.two, selectedDate, CRS.GEOGRAPHIC);
expect(shiftedGranules).toEqual(mockGranules.twoShifted);
expect(shiftedGranules.every(({ shifted }) => shifted)).toEqual(true);
@@ -55,11 +54,11 @@ describe('shifting dateline granules', () => {
describe('getting CMR query date range', () => {
it('starts 8 hours before, 4 hours after, ', () => {
- const selectedDate = new Date('2019-09-24T00:20:00.000Z');
- const expectedStart = new Date('2019-09-23T16:20:00.000Z');
- const expectedEnd = new Date('2019-09-24T04:20:00.000Z');
+ const selectedDate = new Date('2019-09-24T00:00:00.000Z');
+ const expectedStart = new Date('2019-09-23T12:00:00.000Z');
+ const expectedEnd = new Date('2019-09-24T04:00:00.000Z');
- const { startQueryDate, endQueryDate } = getCMRQueryDates(selectedDate);
+ const { startQueryDate, endQueryDate } = getCMRQueryDates(CRS.GEOGRAPHIC, selectedDate);
expect(startQueryDate).toEqual(expectedStart);
expect(endQueryDate).toEqual(expectedEnd);
});
@@ -69,8 +68,7 @@ describe('transform cmr granule data', () => {
it('converts cmr metadata into expected granule format', () => {
const singleEntry = cmrGranules.feed.entry[0];
const date = util.toISOStringSeconds(singleEntry.time_start);
- const crs = 'EPSG:4326';
- const transformedEntry = transformGranuleData(singleEntry, date, crs);
+ const transformedEntry = transformGranuleData(singleEntry, date, CRS.GEOGRAPHIC);
expect(transformedEntry.dayNight).toEqual('NIGHT');
expect(transformedEntry.date).toEqual('2019-09-22T23:54:00Z');
diff --git a/web/js/modules/date/util.js b/web/js/modules/date/util.js
index f2ac68e1c..e0534fb1b 100644
--- a/web/js/modules/date/util.js
+++ b/web/js/modules/date/util.js
@@ -356,7 +356,7 @@ export const outOfStepChange = (state, newDate) => {
export const coverageDateFormatter = (dateType, date, period) => {
if (!date) return;
let dateString;
- const parsedDate = parseDate(date);
+ const parsedDate = new Date(date);
switch (period) {
case 'subdaily':
dateString = formatDisplayDate(parsedDate, true);
diff --git a/web/js/modules/layers/constants.js b/web/js/modules/layers/constants.js
index 74875c36d..d86518bc0 100644
--- a/web/js/modules/layers/constants.js
+++ b/web/js/modules/layers/constants.js
@@ -18,4 +18,6 @@ export const RESET_GRANULE_LAYER_OPTIONS = 'LAYERS/RESET_GRANULE_LAYER_OPTIONS';
export const CHANGE_GRANULE_SATELLITE_INSTRUMENT_GROUP = 'LAYERS/CHANGE_GRANULE_SATELLITE_INSTRUMENT_GROUP';
export const UPDATE_ON_PROJ_CHANGE = 'LAYERS/UPDATE_ON_PROJ_CHANGE';
-export const DEFAULT_NUM_GRANULES = 20;
+export const DEFAULT_NUM_GRANULES = 10;
+export const MIN_GRANULES = 1;
+export const MAX_GRANULES = 30;