Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

WV-2478, WV-2477: Dynamic granule layer start/end date handling, style fixes (#4020)

Jason Kent187ba6d3e86b
diff --git a/tasks/python3/extractConfigFromWMTS.py b/tasks/python3/extractConfigFromWMTS.py
index 2200214b0..574915ddb 100755
--- a/tasks/python3/extractConfigFromWMTS.py
+++ b/tasks/python3/extractConfigFromWMTS.py
@@ -78,14 +78,14 @@ def process_layer(gc_layer, wv_layers, entry):
try:
wv_layer = process_temporal(wv_layer, dimension["Value"])
- # TODO we need a better way to identify granule layers
- if ('Granule' in ident):
- temporalForProjection = {}
- temporalForProjection[entry["projection"]] = {
- "startDate": wv_layer["startDate"],
- "endDate": wv_layer["endDate"],
- "dateRanges": wv_layer["dateRanges"],
- }
+ # # TODO we need a better way to identify granule layers
+ # if ('Granule' in ident):
+ # temporalForProjection = {}
+ # temporalForProjection[entry["projection"]] = {
+ # "startDate": wv_layer["startDate"],
+ # "endDate": wv_layer["endDate"],
+ # "dateRanges": wv_layer["dateRanges"],
+ # }
except Exception as e:
print(traceback.format_exc())
diff --git a/web/js/components/timeline/timeline-coverage/coverage-item-list.js b/web/js/components/timeline/timeline-coverage/coverage-item-list.js
index e3c4924a8..22776c91b 100644
--- a/web/js/components/timeline/timeline-coverage/coverage-item-list.js
+++ b/web/js/components/timeline/timeline-coverage/coverage-item-list.js
@@ -97,7 +97,7 @@ class CoverageItemList extends Component {
background: layerItemBackground,
color: textColor,
float: 'left',
- width: inactiveLayers ? '205px' : '175px',
+ width: inactiveLayers || formattedEndDate ? '205px' : '175px',
}}
>
<MonospaceDate style={getStyle(formattedStartDate)} date={formattedStartDate || ' Start '} />
diff --git a/web/js/map/granule/granule-layer-builder.js b/web/js/map/granule/granule-layer-builder.js
index dabbef0a2..fd7626a17 100644
--- a/web/js/map/granule/granule-layer-builder.js
+++ b/web/js/map/granule/granule-layer-builder.js
@@ -64,26 +64,37 @@ export default function granuleLayerBuilder(cache, store, createLayerWMTS) {
};
/**
- * Add granule cmr data to granule cmr object with date as key
+ * Collect granule metadata objects from a CMR response that have GIBS imagery
+ *
* @param {data} CMR data
* @param {id} layer id
*/
- const addGranuleCMRDateData = (data, shortName, dateRanges) => {
+ const addGranuleCMRDateData = (def, data, shortName, dateRanges) => {
const { proj: { selected: { crs } } } = store.getState();
CMRDataStore[crs][shortName] = CMRDataStore[crs][shortName] || [];
const granuleData = CMRDataStore[crs][shortName];
+ // Any granule metadata object that gets added here is assumed to have corresponding
+ // imagery in GIBS at the same time stamp. Therefore when determining whether or not
+ // to include a granule from CMR we see if either is true:
+ // - (imageryInDateRange) the date for the granule falls within a date range defined by GIBS for this layer
+ // - (imageryInTrailingRange) the date falls after the end date of the last date range AND before the layer's end date,
+ // or in the case of an ongoing layer with no endDate, now
+
+ const lastDateRange = dateRanges[dateRanges.length - 1];
+ const finalEndDate = def.endDate || new Date();
data.forEach((entry) => {
const date = toISOStringSeconds(entry.time_start);
- const hasImagery = find(dateRanges, ({ startDate, endDate }) => isWithinDateRange(date, startDate, endDate));
+ const imageryInDateRange = find(dateRanges, (r) => isWithinDateRange(date, r.startDate, r.endDate));
+ const imageryInTrailingRange = isWithinDateRange(date, lastDateRange.endDate, finalEndDate);
const existsForTime = find(granuleData, (g) => g.date === date);
- if (!hasImagery || existsForTime) {
+ if (!(imageryInDateRange || imageryInTrailingRange) || existsForTime) {
return;
}
const transformedGranule = transformGranuleData(entry, date, crs);
granuleData.push(transformedGranule);
});
- return granuleData.sort((a, b) => {
+ granuleData.sort((a, b) => {
const dateA = new Date(a.date).valueOf();
const dateB = new Date(b.date).valueOf();
return dateB - dateA;
@@ -111,40 +122,35 @@ export default function granuleLayerBuilder(cache, store, createLayerWMTS) {
const state = store.getState();
const { proj: { selected: { crs } } } = state;
const getGranulesUrl = getGranulesUrlSelector(state);
- const params = getParamsForGranuleRequest(def, date, state);
+ const params = getParamsForGranuleRequest(def, date, crs);
const { shortName } = params;
let data = [];
-
const existingGranules = CMRDataStore[crs][shortName] || [];
const datesQueried = datesHaveBeenQueried(params.startDate, date, existingGranules);
if (existingGranules.length && datesQueried) {
return existingGranules;
}
-
- 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();
+ try {
+ showLoading();
+ const requestUrl = getGranulesUrl(params);
+ const response = await fetch(requestUrl, CMR_AJAX_OPTIONS);
+ data = await response.json();
+ data = data.feed.entry;
+ if (data.length) {
+ addGranuleCMRDateData(def, 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);
}
- };
-
- await makeQuery();
+ } catch (e) {
+ console.error(e);
+ throttleDispathCMRErrorDialog(title);
+ return CMRDataStore[crs][shortName];
+ } finally {
+ hideLoading();
+ }
return CMRDataStore[crs][shortName];
};
diff --git a/web/js/map/granule/granule-layer-builder.test.js b/web/js/map/granule/granule-layer-builder.test.js
index 786cc24a6..5a4c065dc 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=VJ102IMG&day_night_flag=DAY&temporal=2019-09-22T08%3A54%3A00.000Z%2C2019-09-24T12%3A54%3A00.000Z&pageSize=500';
+const queryString = '?bounding_box=-180%2C-65%2C180%2C65&shortName=VJ102IMG&day_night_flag=DAY&temporal=2019-09-23T20%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,16 @@ let createGranuleLayer;
let store;
const expectedDates = [
- '2019-09-23T07:00:00Z',
- '2019-09-23T07:06:00Z',
- '2019-09-23T07:12:00Z',
- '2019-09-23T07:18:00Z',
- '2019-09-23T07:24:00Z',
- '2019-09-23T08:42:00Z',
- '2019-09-23T08:48:00Z',
- '2019-09-23T08:54:00Z',
- '2019-09-23T09:00:00Z',
- '2019-09-23T09:06:00Z',
+ '2019-09-23T23:12:00Z',
+ '2019-09-23T23:18:00Z',
+ '2019-09-23T23:24:00Z',
+ '2019-09-23T23:30:00Z',
+ '2019-09-23T23:54:00Z',
+ '2019-09-24T00:00:00Z',
+ '2019-09-24T00:06:00Z',
+ '2019-09-24T00:12:00Z',
+ '2019-09-24T00:18:00Z',
+ '2019-09-24T00:48:00Z',
];
describe('granule layer builder', () => {
diff --git a/web/js/map/granule/util.js b/web/js/map/granule/util.js
index b6481d67e..e17bdd526 100644
--- a/web/js/map/granule/util.js
+++ b/web/js/map/granule/util.js
@@ -84,12 +84,13 @@ export const getIndexForSortedInsert = (array, date) => {
* @param {string} endDate - date string
* @returns {boolean}
*/
-export const isWithinDateRange = (date, startDate, endDate) => (
- startDate && endDate
+export const isWithinDateRange = (date, startDate, end) => {
+ const endDate = end || new Date();
+ return startDate && endDate
? new Date(date).getTime() <= new Date(endDate).getTime()
- && new Date(date).getTime() >= new Date(startDate).getTime()
- : false
-);
+ && new Date(date).getTime() >= new Date(startDate).getTime()
+ : false;
+};
/**
* Determine if a granule polygon falls within the specified bounds of
diff --git a/web/js/modules/layers/actions.js b/web/js/modules/layers/actions.js
index d08a743cd..97f0e8c1f 100644
--- a/web/js/modules/layers/actions.js
+++ b/web/js/modules/layers/actions.js
@@ -1,6 +1,5 @@
import {
findIndex as lodashFindIndex,
- get as lodashGet,
} from 'lodash';
import googleTagManager from 'googleTagManager';
import update from 'immutability-helper';
@@ -31,7 +30,6 @@ import {
UPDATE_GRANULE_LAYER_GEOMETRY,
RESET_GRANULE_LAYER_OPTIONS,
CHANGE_GRANULE_SATELLITE_INSTRUMENT_GROUP,
- UPDATE_ON_PROJ_CHANGE,
} from './constants';
import { updateRecentLayers } from '../product-picker/util';
import { getOverlayGroups, getLayersFromGroups } from './util';
@@ -142,33 +140,6 @@ export function addLayer(id) {
};
}
-/**
- * Layers may have different start, end, and date ranges based on projection.
- * Here we update them if necessary when the projection changes.
- *
- * @param {*} proj
- * @returns
- */
-export function updateDatesOnProjChange(proj) {
- return (dispatch, getState) => {
- const state = getState();
- const getUpdatedLayers = (activeString) => {
- const activeLayers = getActiveLayersSelector(state, activeString);
- return activeLayers.map((l) => {
- l.startDate = lodashGet(l, `projections[${proj}].startDate`) || l.startDate;
- l.endDate = lodashGet(l, `projections[${proj}].endDate`) || l.endDate;
- l.dateRanges = lodashGet(l, `projections[${proj}].dateRanges`) || l.dateRanges;
- return l;
- });
- };
- dispatch({
- type: UPDATE_ON_PROJ_CHANGE,
- layersA: getUpdatedLayers('active'),
- layersB: getUpdatedLayers('activeB'),
- });
- };
-}
-
export function reorderLayers(reorderedLayers) {
return (dispatch, getState) => {
const { compare } = getState();
@@ -274,6 +245,7 @@ export function toggleGroupCollapsed(groupName, collapsed) {
});
};
}
+
export function setOpacity(id, opacity) {
return (dispatch, getState) => {
const { compare } = getState();
diff --git a/web/js/modules/layers/actions.test.js b/web/js/modules/layers/actions.test.js
index b76f2013c..65cb57d11 100644
--- a/web/js/modules/layers/actions.test.js
+++ b/web/js/modules/layers/actions.test.js
@@ -3,7 +3,7 @@ import thunk from 'redux-thunk';
import fixtures from '../../fixtures';
import { addLayer, getLayers } from './selectors';
import {
- removeLayer, removeGroup, toggleOverlayGroups, updateDatesOnProjChange,
+ removeLayer, removeGroup, toggleOverlayGroups,
} from './actions';
import * as LAYER_CONSTANTS from './constants';
@@ -111,19 +111,4 @@ describe('Layer actions', () => {
};
expect(actionResponse).toEqual(expectedPayload);
});
-
- test('UPDATE_ON_PROJ_CHANGE updates layer dates based on projection', () => {
- layers = addMockLayer('granule-cr', layers, 'geographic');
- store = mockStore(getState(layers));
- store.dispatch(updateDatesOnProjChange('arctic'));
- const actionResponse = store.getActions()[0];
- const { startDate, endDate, dateRanges: [firstRange, secondRange] } = actionResponse.layersA[0];
-
- expect(startDate).toEqual('2019-07-21T00:36:00Z');
- expect(endDate).toEqual('2019-09-24T22:30:00Z');
- expect(firstRange.startDate).toEqual('2019-07-21T00:36:00Z');
- expect(firstRange.endDate).toEqual('2019-07-21T00:54:00Z');
- expect(secondRange.startDate).toEqual('2019-07-21T02:18:00Z');
- expect(secondRange.endDate).toEqual('2019-07-21T02:36:00Z');
- });
});
diff --git a/web/js/modules/layers/constants.js b/web/js/modules/layers/constants.js
index d86518bc0..ccd5be6c2 100644
--- a/web/js/modules/layers/constants.js
+++ b/web/js/modules/layers/constants.js
@@ -16,7 +16,6 @@ export const UPDATE_GRANULE_LAYER_OPTIONS = 'LAYERS/UPDATE_GRANULE_LAYER_OPTIONS
export const UPDATE_GRANULE_LAYER_GEOMETRY = 'LAYERS/UPDATE_GRANULE_LAYER_GEOMETRY';
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 = 10;
export const MIN_GRANULES = 1;
diff --git a/web/js/modules/layers/reducers.js b/web/js/modules/layers/reducers.js
index 9b4bb231b..c8946c95d 100644
--- a/web/js/modules/layers/reducers.js
+++ b/web/js/modules/layers/reducers.js
@@ -20,7 +20,6 @@ import {
CHANGE_GRANULE_SATELLITE_INSTRUMENT_GROUP,
REORDER_OVERLAY_GROUPS,
REMOVE_GROUP,
- UPDATE_ON_PROJ_CHANGE,
} from './constants';
import {
SET_CUSTOM as SET_CUSTOM_PALETTE,
@@ -103,20 +102,6 @@ export function layerReducer(state = initialState, action) {
},
});
- case UPDATE_ON_PROJ_CHANGE:
- return update(state, {
- active: {
- $merge: {
- layers: action.layersA,
- },
- },
- activeB: {
- $merge: {
- layers: action.layersB,
- },
- },
- });
-
case REMOVE_LAYER:
case REMOVE_GROUP:
return update(state, {
diff --git a/web/js/modules/layers/selectors.js b/web/js/modules/layers/selectors.js
index cdf02739b..21fe789fb 100644
--- a/web/js/modules/layers/selectors.js
+++ b/web/js/modules/layers/selectors.js
@@ -293,10 +293,6 @@ export function addLayer(id, spec = {}, layersParam, layerConfig, overlayLength,
def.disabled = spec.disabled || undefined;
def.count = spec.count || undefined;
- def.startDate = lodashGet(def, `projections[${projection}].startDate`) || def.startDate;
- def.endDate = lodashGet(def, `projections[${projection}].endDate`) || def.endDate;
- def.dateRanges = lodashGet(def, `projections[${projection}].dateRanges`) || def.dateRanges;
-
if (!lodashIsUndefined(spec.visible)) {
def.visible = spec.visible;
} else if (!lodashIsUndefined(spec.hidden)) {
diff --git a/web/js/modules/layers/util.js b/web/js/modules/layers/util.js
index 3d42a9508..67df2b263 100644
--- a/web/js/modules/layers/util.js
+++ b/web/js/modules/layers/util.js
@@ -1365,10 +1365,9 @@ export const hasNonClickableVectorLayer = (activeLayers, mapRes, projId, isMobil
* @param {*} layers
*/
export function adjustStartDates(layers) {
- const adjustDate = (days) => moment.utc()
- .subtract(days, 'days')
- .startOf('day')
- .format('YYYY-MM-DD');
+ const adjustDate = (days) => `${moment.utc()
+ .subtract(days * 24, 'hours')
+ .format('YYYY-MM-DDThh:mm:ss')}Z`;
const applyDateAdjustment = (layer) => {
const { availability, dateRanges } = layer;
@@ -1380,6 +1379,7 @@ export function adjustStartDates(layers) {
if (Array.isArray(dateRanges) && dateRanges.length) {
const [firstDateRange] = dateRanges;
firstDateRange.startDate = adjustDate(rollingWindow);
+ layer.startDate = adjustDate(rollingWindow);
} else {
console.warn(`GetCapabilities is missing the time value for ${layer.id}`);
}
diff --git a/web/js/modules/projection/actions.js b/web/js/modules/projection/actions.js
index 0884afc7a..d566110d8 100644
--- a/web/js/modules/projection/actions.js
+++ b/web/js/modules/projection/actions.js
@@ -1,6 +1,5 @@
import { CHANGE_PROJECTION } from './constants';
import { onProjectionSwitch } from '../product-picker/actions';
-import { updateDatesOnProjChange } from '../layers/actions';
import { stop } from '../animation/actions';
export default function changeProjection(id) {
@@ -11,7 +10,6 @@ export default function changeProjection(id) {
if (!proj) {
throw new Error(`Invalid projection: ${id}`);
}
- dispatch(updateDatesOnProjChange(id));
dispatch(onProjectionSwitch(id));
if (isPlaying) {
dispatch(stop());
diff --git a/web/scss/features/sidebar.scss b/web/scss/features/sidebar.scss
index d036a9b52..bb0014185 100644
--- a/web/scss/features/sidebar.scss
+++ b/web/scss/features/sidebar.scss
@@ -540,7 +540,7 @@ footer .compare-toggle-button {
}
.layer-info-modal {
- width: 500px;
+ width: 510px;
.modal-body {
overflow-y: scroll;