Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

WV-3297 Replace CMR with DescribeDomains for DataAvailability (#5482)

Patrick Moulden32fae68e6eb6
diff --git a/config/default/common/config/wv.json/layers/tempo/TEMPO_L2_Cloud_Cloud_Fraction_Total_Granule.json b/config/default/common/config/wv.json/layers/tempo/TEMPO_L2_Cloud_Cloud_Fraction_Total_Granule.json
index 628556ff1..8aa472cca 100644
--- a/config/default/common/config/wv.json/layers/tempo/TEMPO_L2_Cloud_Cloud_Fraction_Total_Granule.json
+++ b/config/default/common/config/wv.json/layers/tempo/TEMPO_L2_Cloud_Cloud_Fraction_Total_Granule.json
@@ -11,7 +11,7 @@
"type": "granule",
"period": "subdaily",
"count": 1,
- "cmrAvailability": true,
+ "dataAvailability": "dd",
"startDate": "2024-05-13T10:41:03Z",
"disableSnapshot": true
}
diff --git a/config/default/common/config/wv.json/layers/tempo/TEMPO_L2_Cloud_Cloud_Pressure_Total_Granule.json b/config/default/common/config/wv.json/layers/tempo/TEMPO_L2_Cloud_Cloud_Pressure_Total_Granule.json
index 8abc8fed4..8579f5d45 100644
--- a/config/default/common/config/wv.json/layers/tempo/TEMPO_L2_Cloud_Cloud_Pressure_Total_Granule.json
+++ b/config/default/common/config/wv.json/layers/tempo/TEMPO_L2_Cloud_Cloud_Pressure_Total_Granule.json
@@ -11,7 +11,7 @@
"type": "granule",
"period": "subdaily",
"count": 1,
- "cmrAvailability": true,
+ "dataAvailability": "dd",
"startDate": "2024-05-13T10:41:03Z",
"disableSnapshot": true
diff --git a/config/default/common/config/wv.json/layers/tempo/TEMPO_L2_Formaldehyde_Vertical_Column_Granule.json b/config/default/common/config/wv.json/layers/tempo/TEMPO_L2_Formaldehyde_Vertical_Column_Granule.json
index 351a69d85..ae91fa273 100644
--- a/config/default/common/config/wv.json/layers/tempo/TEMPO_L2_Formaldehyde_Vertical_Column_Granule.json
+++ b/config/default/common/config/wv.json/layers/tempo/TEMPO_L2_Formaldehyde_Vertical_Column_Granule.json
@@ -11,7 +11,7 @@
"type": "granule",
"period": "subdaily",
"count": 1,
- "cmrAvailability": true,
+ "dataAvailability": "dd",
"startDate": "2024-05-13T10:41:03Z",
"disableSnapshot": true
diff --git a/config/default/common/config/wv.json/layers/tempo/TEMPO_L2_NO2_Vertical_Column_Stratosphere_Granule.json b/config/default/common/config/wv.json/layers/tempo/TEMPO_L2_NO2_Vertical_Column_Stratosphere_Granule.json
index 8df3d42c2..35bc063b7 100644
--- a/config/default/common/config/wv.json/layers/tempo/TEMPO_L2_NO2_Vertical_Column_Stratosphere_Granule.json
+++ b/config/default/common/config/wv.json/layers/tempo/TEMPO_L2_NO2_Vertical_Column_Stratosphere_Granule.json
@@ -11,7 +11,7 @@
"type": "granule",
"period": "subdaily",
"count": 1,
- "cmrAvailability": true,
+ "dataAvailability": "dd",
"startDate": "2024-05-13T10:41:03Z",
"disableSnapshot": true
diff --git a/config/default/common/config/wv.json/layers/tempo/TEMPO_L2_NO2_Vertical_Column_Troposphere_Granule.json b/config/default/common/config/wv.json/layers/tempo/TEMPO_L2_NO2_Vertical_Column_Troposphere_Granule.json
index 7fbaf4edc..bd2ccf74b 100644
--- a/config/default/common/config/wv.json/layers/tempo/TEMPO_L2_NO2_Vertical_Column_Troposphere_Granule.json
+++ b/config/default/common/config/wv.json/layers/tempo/TEMPO_L2_NO2_Vertical_Column_Troposphere_Granule.json
@@ -11,7 +11,7 @@
"type": "granule",
"period": "subdaily",
"count": 1,
- "cmrAvailability": true,
+ "dataAvailability": "dd",
"startDate": "2024-05-13T10:41:03Z",
"disableSnapshot": true
diff --git a/config/default/common/config/wv.json/layers/tempo/TEMPO_L2_Ozone_Cloud_Fraction_Granule.json b/config/default/common/config/wv.json/layers/tempo/TEMPO_L2_Ozone_Cloud_Fraction_Granule.json
index 4df6cb24d..aea95bf1e 100644
--- a/config/default/common/config/wv.json/layers/tempo/TEMPO_L2_Ozone_Cloud_Fraction_Granule.json
+++ b/config/default/common/config/wv.json/layers/tempo/TEMPO_L2_Ozone_Cloud_Fraction_Granule.json
@@ -11,7 +11,7 @@
"type": "granule",
"period": "subdaily",
"count": 1,
- "cmrAvailability": true,
+ "dataAvailability": "dd",
"startDate": "2024-05-13T10:41:03Z",
"disableSnapshot": true
diff --git a/config/default/common/config/wv.json/layers/tempo/TEMPO_L2_Ozone_Column_Amount_Granule.json b/config/default/common/config/wv.json/layers/tempo/TEMPO_L2_Ozone_Column_Amount_Granule.json
index 42b847d43..622252174 100644
--- a/config/default/common/config/wv.json/layers/tempo/TEMPO_L2_Ozone_Column_Amount_Granule.json
+++ b/config/default/common/config/wv.json/layers/tempo/TEMPO_L2_Ozone_Column_Amount_Granule.json
@@ -11,7 +11,7 @@
"type": "granule",
"period": "subdaily",
"count": 1,
- "cmrAvailability": true,
+ "dataAvailability": "dd",
"startDate": "2024-05-13T10:41:03Z",
"disableSnapshot": true
diff --git a/config/default/common/config/wv.json/layers/tempo/TEMPO_L2_Ozone_UV_Aerosol_Index_Granule.json b/config/default/common/config/wv.json/layers/tempo/TEMPO_L2_Ozone_UV_Aerosol_Index_Granule.json
index 968fad9fc..d896aa248 100644
--- a/config/default/common/config/wv.json/layers/tempo/TEMPO_L2_Ozone_UV_Aerosol_Index_Granule.json
+++ b/config/default/common/config/wv.json/layers/tempo/TEMPO_L2_Ozone_UV_Aerosol_Index_Granule.json
@@ -11,7 +11,7 @@
"type": "granule",
"period": "subdaily",
"count": 1,
- "cmrAvailability": true,
+ "dataAvailability": "dd",
"startDate": "2024-05-13T10:41:03Z",
"disableSnapshot": true
diff --git a/config/default/common/config/wv.json/layers/tempo/TEMPO_L3_Cloud_Cloud_Fraction_Total.json b/config/default/common/config/wv.json/layers/tempo/TEMPO_L3_Cloud_Cloud_Fraction_Total.json
index 2c7624f56..817fbe1a8 100644
--- a/config/default/common/config/wv.json/layers/tempo/TEMPO_L3_Cloud_Cloud_Fraction_Total.json
+++ b/config/default/common/config/wv.json/layers/tempo/TEMPO_L3_Cloud_Cloud_Fraction_Total.json
@@ -8,7 +8,7 @@
"tags": "",
"group": "overlays",
"layergroup": "Cloud Fraction",
- "cmrAvailability": true,
+ "dataAvailability": "dd",
"startDate": "2024-05-13T10:30:00Z",
"disableSnapshot": true
}
diff --git a/config/default/common/config/wv.json/layers/tempo/TEMPO_L3_Cloud_Cloud_Pressure_Total.json b/config/default/common/config/wv.json/layers/tempo/TEMPO_L3_Cloud_Cloud_Pressure_Total.json
index 1a0d07363..da9adb860 100644
--- a/config/default/common/config/wv.json/layers/tempo/TEMPO_L3_Cloud_Cloud_Pressure_Total.json
+++ b/config/default/common/config/wv.json/layers/tempo/TEMPO_L3_Cloud_Cloud_Pressure_Total.json
@@ -8,7 +8,7 @@
"tags": "",
"group": "overlays",
"layergroup": "Cloud Pressure",
- "cmrAvailability": true,
+ "dataAvailability": "dd",
"startDate": "2024-05-13T10:30:00Z",
"disableSnapshot": true
diff --git a/config/default/common/config/wv.json/layers/tempo/TEMPO_L3_Formaldehyde_Vertical_Column.json b/config/default/common/config/wv.json/layers/tempo/TEMPO_L3_Formaldehyde_Vertical_Column.json
index 6275dc659..db0cb0262 100644
--- a/config/default/common/config/wv.json/layers/tempo/TEMPO_L3_Formaldehyde_Vertical_Column.json
+++ b/config/default/common/config/wv.json/layers/tempo/TEMPO_L3_Formaldehyde_Vertical_Column.json
@@ -8,7 +8,7 @@
"tags": "",
"group": "overlays",
"layergroup": "Formaldehyde",
- "cmrAvailability": true,
+ "dataAvailability": "dd",
"startDate": "2024-05-13T10:30:00Z",
"disableSnapshot": true
diff --git a/config/default/common/config/wv.json/layers/tempo/TEMPO_L3_NO2_Vertical_Column_Stratosphere.json b/config/default/common/config/wv.json/layers/tempo/TEMPO_L3_NO2_Vertical_Column_Stratosphere.json
index e8ce81727..7bbd70921 100644
--- a/config/default/common/config/wv.json/layers/tempo/TEMPO_L3_NO2_Vertical_Column_Stratosphere.json
+++ b/config/default/common/config/wv.json/layers/tempo/TEMPO_L3_NO2_Vertical_Column_Stratosphere.json
@@ -8,7 +8,7 @@
"tags": "",
"group": "overlays",
"layergroup": "Nitrogen Dioxide",
- "cmrAvailability": true,
+ "dataAvailability": "dd",
"startDate": "2024-05-13T10:30:00Z",
"disableSnapshot": true
diff --git a/config/default/common/config/wv.json/layers/tempo/TEMPO_L3_NO2_Vertical_Column_Troposphere.json b/config/default/common/config/wv.json/layers/tempo/TEMPO_L3_NO2_Vertical_Column_Troposphere.json
index 7226d45c0..e9c02fd04 100644
--- a/config/default/common/config/wv.json/layers/tempo/TEMPO_L3_NO2_Vertical_Column_Troposphere.json
+++ b/config/default/common/config/wv.json/layers/tempo/TEMPO_L3_NO2_Vertical_Column_Troposphere.json
@@ -8,7 +8,7 @@
"tags": "",
"group": "overlays",
"layergroup": "Nitrogen Dioxide",
- "cmrAvailability": true,
+ "dataAvailability": "dd",
"startDate": "2024-05-13T10:30:00Z",
"disableSnapshot": true
diff --git a/config/default/common/config/wv.json/layers/tempo/TEMPO_L3_Ozone_Cloud_Fraction.json b/config/default/common/config/wv.json/layers/tempo/TEMPO_L3_Ozone_Cloud_Fraction.json
index 6c76585de..8fa481a1e 100644
--- a/config/default/common/config/wv.json/layers/tempo/TEMPO_L3_Ozone_Cloud_Fraction.json
+++ b/config/default/common/config/wv.json/layers/tempo/TEMPO_L3_Ozone_Cloud_Fraction.json
@@ -8,7 +8,7 @@
"tags": "",
"group": "overlays",
"layergroup": "Ozone",
- "cmrAvailability": true,
+ "dataAvailability": "dd",
"startDate": "2024-05-13T10:30:00Z",
"disableSnapshot": true
diff --git a/config/default/common/config/wv.json/layers/tempo/TEMPO_L3_Ozone_Column_Amount.json b/config/default/common/config/wv.json/layers/tempo/TEMPO_L3_Ozone_Column_Amount.json
index 0e7d9eb8d..8c1d85cea 100644
--- a/config/default/common/config/wv.json/layers/tempo/TEMPO_L3_Ozone_Column_Amount.json
+++ b/config/default/common/config/wv.json/layers/tempo/TEMPO_L3_Ozone_Column_Amount.json
@@ -8,7 +8,7 @@
"tags": "",
"group": "overlays",
"layergroup": "Ozone",
- "cmrAvailability": true,
+ "dataAvailability": "dd",
"startDate": "2024-05-13T10:30:00Z",
"disableSnapshot": true
diff --git a/config/default/common/config/wv.json/layers/tempo/TEMPO_L3_Ozone_UV_Aerosol_Index.json b/config/default/common/config/wv.json/layers/tempo/TEMPO_L3_Ozone_UV_Aerosol_Index.json
index 066ca16c5..5df8232b4 100644
--- a/config/default/common/config/wv.json/layers/tempo/TEMPO_L3_Ozone_UV_Aerosol_Index.json
+++ b/config/default/common/config/wv.json/layers/tempo/TEMPO_L3_Ozone_UV_Aerosol_Index.json
@@ -8,7 +8,7 @@
"tags": "",
"group": "overlays",
"layergroup": "Aerosol Index",
- "cmrAvailability": true,
+ "dataAvailability": "dd",
"startDate": "2024-05-13T10:30:00Z",
"disableSnapshot": true
diff --git a/config/default/common/config/wv.json/layers/viirs/noaa20/VIIRS_NOAA20_CorrectedReflectance_BandsM11-I2-I1_Granule.json b/config/default/common/config/wv.json/layers/viirs/noaa20/VIIRS_NOAA20_CorrectedReflectance_BandsM11-I2-I1_Granule.json
index 8e42feaf4..c5e854b3b 100644
--- a/config/default/common/config/wv.json/layers/viirs/noaa20/VIIRS_NOAA20_CorrectedReflectance_BandsM11-I2-I1_Granule.json
+++ b/config/default/common/config/wv.json/layers/viirs/noaa20/VIIRS_NOAA20_CorrectedReflectance_BandsM11-I2-I1_Granule.json
@@ -7,7 +7,7 @@
"group": "overlays",
"layergroup": "Granules",
"type": "granule",
- "cmrAvailability": true,
+ "dataAvailability": "dd",
"period": "subdaily",
"associatedLayers": ["VIIRS_NOAA20_CorrectedReflectance_BandsM11-I2-I1"],
"availability": {
diff --git a/config/default/common/config/wv.json/layers/viirs/noaa20/VIIRS_NOAA20_CorrectedReflectance_BandsM3-I3-M11_Granule.json b/config/default/common/config/wv.json/layers/viirs/noaa20/VIIRS_NOAA20_CorrectedReflectance_BandsM3-I3-M11_Granule.json
index b72b32c48..a20427eed 100644
--- a/config/default/common/config/wv.json/layers/viirs/noaa20/VIIRS_NOAA20_CorrectedReflectance_BandsM3-I3-M11_Granule.json
+++ b/config/default/common/config/wv.json/layers/viirs/noaa20/VIIRS_NOAA20_CorrectedReflectance_BandsM3-I3-M11_Granule.json
@@ -7,7 +7,7 @@
"group": "overlays",
"layergroup": "Granules",
"type": "granule",
- "cmrAvailability": true,
+ "dataAvailability": "dd",
"period": "subdaily",
"associatedLayers": ["VIIRS_NOAA20_CorrectedReflectance_BandsM3-I3-M11"],
"availability": {
diff --git a/config/default/common/config/wv.json/layers/viirs/noaa20/VIIRS_NOAA20_CorrectedReflectance_TrueColor_Granule.json b/config/default/common/config/wv.json/layers/viirs/noaa20/VIIRS_NOAA20_CorrectedReflectance_TrueColor_Granule.json
index 573329650..2849f6404 100644
--- a/config/default/common/config/wv.json/layers/viirs/noaa20/VIIRS_NOAA20_CorrectedReflectance_TrueColor_Granule.json
+++ b/config/default/common/config/wv.json/layers/viirs/noaa20/VIIRS_NOAA20_CorrectedReflectance_TrueColor_Granule.json
@@ -7,7 +7,7 @@
"group": "overlays",
"layergroup": "Granules",
"type": "granule",
- "cmrAvailability": true,
+ "dataAvailability": "dd",
"period": "subdaily",
"associatedLayers": ["VIIRS_NOAA20_CorrectedReflectance_TrueColor"],
"availability": {
diff --git a/config/default/common/config/wv.json/layers/viirs/snpp/VIIRS_SNPP_CorrectedReflectance_BandsM11-I2-I1_Granule.json b/config/default/common/config/wv.json/layers/viirs/snpp/VIIRS_SNPP_CorrectedReflectance_BandsM11-I2-I1_Granule.json
index c5134461c..1f319a8e0 100644
--- a/config/default/common/config/wv.json/layers/viirs/snpp/VIIRS_SNPP_CorrectedReflectance_BandsM11-I2-I1_Granule.json
+++ b/config/default/common/config/wv.json/layers/viirs/snpp/VIIRS_SNPP_CorrectedReflectance_BandsM11-I2-I1_Granule.json
@@ -7,7 +7,7 @@
"group": "overlays",
"layergroup": "Granules",
"type": "granule",
- "cmrAvailability": true,
+ "dataAvailability": "dd",
"period": "subdaily",
"associatedLayers": ["VIIRS_SNPP_CorrectedReflectance_BandsM11-I2-I1"],
"availability": {
diff --git a/config/default/common/config/wv.json/layers/viirs/snpp/VIIRS_SNPP_CorrectedReflectance_BandsM3-I3-M11_Granule.json b/config/default/common/config/wv.json/layers/viirs/snpp/VIIRS_SNPP_CorrectedReflectance_BandsM3-I3-M11_Granule.json
index e983470c9..6d501f348 100644
--- a/config/default/common/config/wv.json/layers/viirs/snpp/VIIRS_SNPP_CorrectedReflectance_BandsM3-I3-M11_Granule.json
+++ b/config/default/common/config/wv.json/layers/viirs/snpp/VIIRS_SNPP_CorrectedReflectance_BandsM3-I3-M11_Granule.json
@@ -7,7 +7,7 @@
"group": "overlays",
"layergroup": "Granules",
"type": "granule",
- "cmrAvailability": true,
+ "dataAvailability": "dd",
"period": "subdaily",
"associatedLayers": ["VIIRS_SNPP_CorrectedReflectance_BandsM3-I3-M11"],
"availability": {
diff --git a/config/default/common/config/wv.json/layers/viirs/snpp/VIIRS_SNPP_CorrectedReflectance_TrueColor_Granule.json b/config/default/common/config/wv.json/layers/viirs/snpp/VIIRS_SNPP_CorrectedReflectance_TrueColor_Granule.json
index 6641da00d..08e74b3be 100644
--- a/config/default/common/config/wv.json/layers/viirs/snpp/VIIRS_SNPP_CorrectedReflectance_TrueColor_Granule.json
+++ b/config/default/common/config/wv.json/layers/viirs/snpp/VIIRS_SNPP_CorrectedReflectance_TrueColor_Granule.json
@@ -7,7 +7,7 @@
"group": "overlays",
"layergroup": "Granules",
"type": "granule",
- "cmrAvailability": true,
+ "dataAvailability": "dd",
"period": "subdaily",
"associatedLayers": ["VIIRS_SNPP_CorrectedReflectance_TrueColor"],
"availability": {
diff --git a/doc/config/layers.md b/doc/config/layers.md
index 4aec70587..88bedaa2d 100644
--- a/doc/config/layers.md
+++ b/doc/config/layers.md
@@ -113,6 +113,7 @@ Example:
* **temporal**: Used to override the layer temporal availability declared in the capabilities document. Note: Changing the temporal availability can cause missing layer coverage within the interface for layers tiles that aren't available from the source at the revised temporal range. This option can be added as a string with the new availability range. For example, `"1981-10-13/2019-10-11/P1M"`.
* **count**: Used to override the default number of granules displayed on the map and in the granule count slider component for granule layers.
* **cmrAvailability**: Boolean - Whether or not to use the CMR API for data availability.
+* **dataAvailability**: String - `cmr` or `dd`. Get the layer's data availability from either the CMR API or GIBS DescribeDomains request.
## Full Example
@@ -136,7 +137,7 @@ Example:
"id": "AIRS_RH400_A"
},
"temporal": "1981-10-13/2019-10-11/P1M",
- "cmrAvailability": false
+ "dataAvailability": "dd"
}
}
}
@@ -164,7 +165,7 @@ Granule layers will require specific configuration options within the `config/wv
],
"ongoing": true,
"type": "granule",
- "cmrAvailability": true,
+ "dataAvailability": "dd",
"period": "subdaily",
"count": 1
}
diff --git a/web/js/map/layerbuilder.js b/web/js/map/layerbuilder.js
index e55a9d9f7..65973a216 100644
--- a/web/js/map/layerbuilder.js
+++ b/web/js/map/layerbuilder.js
@@ -1110,6 +1110,52 @@ export default function mapLayerBuilder(config, cache, store) {
return layer;
};
+ const addTimeRanges = (def) => {
+ const state = store.getState();
+ const proj = state.proj.selected;
+ const {
+ cmrAvailability,
+ dataAvailability,
+ id,
+ } = def;
+ // if opted in to CMR availability, get granule date ranges if needed
+ if ((cmrAvailability || dataAvailability === 'cmr') && !def.granuleDateRanges) {
+ const worker = new Worker('js/workers/cmr.worker.js');
+ worker.onmessage = (event) => {
+ worker.terminate();
+ store.dispatch(addGranuleDateRanges(def, event.data));
+ };
+ worker.onerror = () => {
+ worker.terminate();
+ };
+ worker.postMessage({ operation: 'getLayerGranuleRanges', args: [def] });
+ }
+ // if opted in to DescribeDomains availability, get granule date ranges if needed
+ if (dataAvailability === 'dd' && !def.granuleDateRanges) {
+ const worker = new Worker('js/workers/dd.worker.js');
+ worker.onmessage = (event) => {
+ if (Array.isArray(event.data)) { // our final format is an array
+ worker.terminate(); // terminate the worker
+ return store.dispatch(addGranuleDateRanges(def, event.data)); // dispatch the action
+ }
+ // DOMParser is not available in workers so we parse the xml on the main thread before sending it back to the worker
+ const parser = new DOMParser();
+ const xmlDoc = parser.parseFromString(event.data, 'text/xml');
+ const domains = xmlDoc.querySelector('Domain').textContent;
+ worker.postMessage({ operation: 'mergeDomains', args: [domains, 60_000] });
+ };
+ worker.onerror = () => {
+ worker.terminate();
+ };
+ const params = {
+ startDate: new Date(def.startDate).toISOString(),
+ endDate: def.endDate ? new Date(def.endDate).toISOString() : new Date().toISOString(),
+ id,
+ proj: proj.crs,
+ };
+ worker.postMessage({ operation: 'requestDescribeDomains', args: [params] });
+ }
+ };
/**
* Create a new OpenLayers Layer
@@ -1126,7 +1172,6 @@ export default function mapLayerBuilder(config, cache, store) {
const proj = state.proj.selected;
const {
breakPointLayer,
- cmrAvailability,
id,
opacity,
period,
@@ -1139,18 +1184,8 @@ export default function mapLayerBuilder(config, cache, store) {
let { date } = dateOptions;
let layer = cache.getItem(key);
const isGranule = type === 'granule';
- // if opted in to CMR availability, get granule date ranges if needed
- if (cmrAvailability && !def.granuleDateRanges) {
- const worker = new Worker('js/workers/cmr.worker.js');
- worker.onmessage = (event) => {
- worker.terminate();
- store.dispatch(addGranuleDateRanges(def, event.data));
- };
- worker.onerror = () => {
- worker.terminate();
- };
- worker.postMessage({ funcName: 'getLayerGranuleRanges', args: [def] });
- }
+
+ addTimeRanges(def);
if (!layer || isGranule || def.type === 'titiler') {
if (!date) date = options.date || getSelectedDate(state);
diff --git a/web/js/workers/cmr.worker.js b/web/js/workers/cmr.worker.js
index b0b60ddad..4e40544f4 100644
--- a/web/js/workers/cmr.worker.js
+++ b/web/js/workers/cmr.worker.js
@@ -113,6 +113,6 @@ const functions = {
onmessage = async (event) => {
const { data } = event;
- const result = await functions[data.funcName]?.(...data.args);
+ const result = await functions[data.operation]?.(...data.args);
postMessage(result);
};
diff --git a/web/js/workers/dd.worker.js b/web/js/workers/dd.worker.js
new file mode 100644
index 000000000..3ffc5cff1
--- /dev/null
+++ b/web/js/workers/dd.worker.js
@@ -0,0 +1,134 @@
+const projDict = {
+ 'EPSG:4326': 'epsg4326',
+ 'EPSG:3413': 'epsg3413',
+ 'EPSG:3031': 'epsg3031',
+};
+
+/**
+ * @method requestDescribeDomains
+ * @param {object} params
+ * @returns {string} describeDomainsText
+ * @description
+ * Request DescribeDomains from GIBS
+ */
+async function requestDescribeDomains(params) {
+ const {
+ id,
+ startDate,
+ endDate,
+ proj,
+ } = params;
+
+ const describeDomainsUrl = `https://gibs.earthdata.nasa.gov/wmts/${projDict[proj]}/best/1.0.0/${id}/default/250m/all/${startDate.split('T')[0]}--${endDate.split('T')[0]}.xml`;
+ const describeDomainsResponse = await fetch(describeDomainsUrl);
+ const describeDomainsText = await describeDomainsResponse.text();
+ return describeDomainsText;
+}
+
+/**
+ * @method makeTime
+ * @param {string} date
+ * @returns {number} time
+ * @description
+ * Convert date to time
+*/
+function makeTime(date) {
+ return new Date(date).getTime();
+}
+
+/**
+ * @method makeDateString
+ * @param {number} time
+ * @returns {string} dateString
+ * @description
+ * Convert time to date string
+*/
+function makeDateString(time) {
+ return new Date(time).toISOString();
+}
+
+/**
+ * @method periodToTime
+ * @param {string} period
+ * @returns {number} time
+ * @description
+ * Convert period to time
+*/
+function periodToTime(period) {
+ const oneMinute = 60_000;
+ const oneHour = 3_600_000;
+ const oneDay = 86_400_000;
+ const lookup = {
+ M: oneMinute,
+ H: oneHour,
+ D: oneDay,
+ };
+ const match = period.match(/[0-9]+/i);
+ const number = Number(match[0]);
+ const unit = period.at(-1);
+ const time = number * lookup[unit];
+
+ if (Number.isNaN(time)) return 360_000;
+
+ return time;
+}
+
+/**
+ * @method mergeDomains
+ * @param {array} domains
+ * @param {number} timeBuffer
+ * @returns {array} mergedDateRanges
+ * @description
+ * Merge overlapping date ranges
+*/
+function mergeDomains(domains, timeBuffer) {
+ const dateRanges = domains.split(',').map((range) => range.split('/'));
+
+ const mergedDateRanges = dateRanges.reduce((acc, [start, end, period]) => {
+ // convert start and end to time values
+ const startTime = makeTime(start);
+ let endTime = makeTime(end);
+
+ // if start and end are the same, add period
+ if (startTime === endTime) {
+ endTime += periodToTime(period);
+ }
+
+ if (!acc.length) return [[makeDateString(startTime), makeDateString(endTime)]]; // add the first range to the accumulator
+
+ // round start time down and end time up by a set time to account for small range gaps
+ const bufferedStartTime = startTime - timeBuffer;
+ const bufferedEndTime = endTime + timeBuffer;
+
+ const lastRangeEndTime = makeTime(acc.at(-1)[1]);
+ const lastRangeStartTime = makeTime(acc.at(-1)[0]);
+
+ if ((bufferedStartTime >= lastRangeStartTime && bufferedStartTime <= lastRangeEndTime) && (bufferedEndTime >= lastRangeStartTime && bufferedEndTime <= lastRangeEndTime)) { // within current range, ignore
+ return acc;
+ }
+
+ if (bufferedStartTime > lastRangeEndTime) { // discontinuous, add new range
+ return [...acc, [makeDateString(startTime), makeDateString(endTime)]];
+ }
+
+ if (bufferedStartTime <= lastRangeEndTime && bufferedEndTime > lastRangeEndTime) { // intersects current range, merge
+ return acc.with(-1, [acc.at(-1)[0], makeDateString(endTime)]);
+ }
+
+ return acc;
+ }, []);
+
+ return mergedDateRanges;
+}
+
+
+const functions = {
+ requestDescribeDomains,
+ mergeDomains,
+};
+
+onmessage = async (event) => {
+ const { data } = event;
+ const result = await functions[data.operation]?.(...data.args);
+ postMessage(result);
+};