Skip to content

Commit

Permalink
WV-3045 WVS granule layer snapshots (#5162)
Browse files Browse the repository at this point in the history
* allow granule layers to snapshot

* add granule_dates parameter

* update test

* limit to 15 granules

* conditionally push granule_dates param
  • Loading branch information
PatchesMaps authored May 14, 2024
1 parent ed70a78 commit 121f4dc
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
"associatedLayers": ["VIIRS_NOAA20_CorrectedReflectance_BandsM11-I2-I1"],
"availability": {
"rollingWindow": 30
},
"disableSnapshot": true
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
"associatedLayers": ["VIIRS_NOAA20_CorrectedReflectance_BandsM3-I3-M11"],
"availability": {
"rollingWindow": 30
},
"disableSnapshot": true
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
"associatedLayers": ["VIIRS_NOAA20_CorrectedReflectance_TrueColor"],
"availability": {
"rollingWindow": 30
},
"disableSnapshot": true
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
"associatedLayers": ["VIIRS_SNPP_CorrectedReflectance_BandsM11-I2-I1"],
"availability": {
"rollingWindow": 30
},
"disableSnapshot": true
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
"associatedLayers": ["VIIRS_SNPP_CorrectedReflectance_BandsM3-I3-M11"],
"availability": {
"rollingWindow": 30
},
"disableSnapshot": true
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
"associatedLayers": ["VIIRS_SNPP_CorrectedReflectance_TrueColor"],
"availability": {
"rollingWindow": 30
},
"disableSnapshot": true
}
}
}
}
4 changes: 3 additions & 1 deletion web/js/components/image-download/image-download-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ function ImageDownloadPanel(props) {
const time = new Date(date.getTime());

const layerList = getLayers();
const granuleDatesMap = new Map(map.getLayers().getArray().map((layer) => [layer.wv.id, layer.wv.granuleDates]));
const layerDefs = layerList.map((def) => ({ ...def, granuleDates: granuleDatesMap.get(def.id) }));
const dlURL = getDownloadUrl(
url,
projection,
layerList,
layerDefs,
lonlats,
{ width, height },
time,
Expand Down
16 changes: 16 additions & 0 deletions web/js/modules/image-download/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { CRS } from '../map/constants';

const GEO_ESTIMATION_CONSTANT = 256.0;
const POLAR_ESTIMATION_CONSTANT = 0.002197265625;
const GRANULE_LIMIT = 15;

/**
* Get a date time snapped to the interval of the layer with the shortest interval.
Expand Down Expand Up @@ -281,6 +282,18 @@ export function getDownloadUrl(url, proj, layerDefs, bbox, dimensions, dateTime,
const imgFormat = fileType || 'image/jpeg';
const { height, width } = dimensions;
const snappedDateTime = getLatestIntervalTime(layerDefs, dateTime);
let numGranules = 0;
const granuleDates = layerDefs.reduce((acc, def, i) => {
let granuleDatesString = acc;
if (!def.granuleDates) return granuleDatesString;
granuleDatesString = `${acc}${i};`; // ensure that each granule layer gets an index
if (numGranules >= GRANULE_LIMIT) return granuleDatesString; // limit number of granules
const numToAdd = GRANULE_LIMIT - numGranules;
const truncatedDates = def.granuleDates.slice(0, numToAdd);
numGranules += truncatedDates.length;
const processedDates = truncatedDates.map((date) => date.split(':').filter((d) => d !== '00Z').join(':'));
return `${granuleDatesString}${processedDates.join(',')},`;
}, '');
const params = [
'REQUEST=GetSnapshot',
`TIME=${util.toISOStringSeconds(snappedDateTime)}`,
Expand All @@ -292,6 +305,9 @@ export function getDownloadUrl(url, proj, layerDefs, bbox, dimensions, dateTime,
`WIDTH=${width}`,
`HEIGHT=${height}`,
];
if (granuleDates.length > 0) {
params.push(`granule_dates=${granuleDates}`);
}
if (opacities.length > 0) {
params.push(`OPACITIES=${opacities.join(',')}`);
}
Expand Down

0 comments on commit 121f4dc

Please sign in to comment.