@aguacerowx/javascript-sdk 0.0.24 → 0.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AguaceroCore.js +794 -207
- package/dist/default-colormaps.js +32 -0
- package/dist/dictionaries.js +73 -0
- package/dist/getBundleId.js +9 -20
- package/dist/getBundleId.native.js +18 -0
- package/dist/gridDecodePipeline.js +37 -0
- package/dist/gridDecodeWorker.js +31 -0
- package/dist/index.js +172 -1
- package/dist/nexradTiltCoalesce.js +95 -0
- package/dist/nexradTilts.js +129 -0
- package/dist/nexrad_level3_catalog.js +56 -0
- package/dist/nexrad_support.js +269 -0
- package/dist/satellite_support.js +395 -0
- package/package.json +37 -2
- package/src/AguaceroCore.js +15 -6
- package/src/index.js +7 -1
- package/src/nws/NwsWatchesWarningsOverlay.js +977 -0
- package/src/nws/nwsAlertsFetchSpec.js +93 -0
- package/src/nws/nwsAlertsSupport.js +1337 -0
- package/src/nws/nwsEventColorsDefaults.js +133 -0
- package/src/nws/nwsSdkConstants.js +368 -0
- package/src/nws/nwsWarningCustomizationKey.gen.js +493 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.NEXRAD_LEVEL3_MOTION_PRODUCT = exports.NEXRAD_LEVEL3_ELEV = void 0;
|
|
7
|
+
exports.getNexradLevel3EntryByRadarKey = getNexradLevel3EntryByRadarKey;
|
|
8
|
+
/** Subset of aguacero-frontend NEXRAD_LEVEL3_MENU for API product resolution. */
|
|
9
|
+
|
|
10
|
+
const NEXRAD_LEVEL3_ELEV = exports.NEXRAD_LEVEL3_ELEV = '0.50';
|
|
11
|
+
const NEXRAD_LEVEL3_MOTION_PRODUCT = exports.NEXRAD_LEVEL3_MOTION_PRODUCT = 'N0S';
|
|
12
|
+
const MENU = [{
|
|
13
|
+
radarKey: 'VEL',
|
|
14
|
+
product: 'N0G',
|
|
15
|
+
fldKey: 'nexrad_vel'
|
|
16
|
+
}, {
|
|
17
|
+
radarKey: 'KDP',
|
|
18
|
+
product: 'N0K',
|
|
19
|
+
fldKey: 'nexrad_l3_n0k'
|
|
20
|
+
}, {
|
|
21
|
+
radarKey: 'N0H',
|
|
22
|
+
product: 'N0H',
|
|
23
|
+
fldKey: 'nexrad_l3_n0h'
|
|
24
|
+
}, {
|
|
25
|
+
radarKey: 'HHC',
|
|
26
|
+
product: 'HHC',
|
|
27
|
+
fldKey: 'nexrad_l3_hhc'
|
|
28
|
+
}, {
|
|
29
|
+
radarKey: 'EET',
|
|
30
|
+
product: 'EET',
|
|
31
|
+
fldKey: 'nexrad_l3_eet'
|
|
32
|
+
}, {
|
|
33
|
+
radarKey: 'DVL',
|
|
34
|
+
product: 'DVL',
|
|
35
|
+
fldKey: 'nexrad_l3_dvl'
|
|
36
|
+
}, {
|
|
37
|
+
radarKey: 'DAA',
|
|
38
|
+
product: 'DAA',
|
|
39
|
+
fldKey: 'nexrad_l3_daa'
|
|
40
|
+
}, {
|
|
41
|
+
radarKey: 'DU3',
|
|
42
|
+
product: 'DU3',
|
|
43
|
+
fldKey: 'nexrad_l3_du3'
|
|
44
|
+
}, {
|
|
45
|
+
radarKey: 'DTA',
|
|
46
|
+
product: 'DTA',
|
|
47
|
+
fldKey: 'nexrad_l3_dta'
|
|
48
|
+
}];
|
|
49
|
+
const byRadarKey = new Map();
|
|
50
|
+
for (const e of MENU) {
|
|
51
|
+
byRadarKey.set(e.radarKey, e);
|
|
52
|
+
}
|
|
53
|
+
byRadarKey.set('NVL', byRadarKey.get('DVL'));
|
|
54
|
+
function getNexradLevel3EntryByRadarKey(radarKey) {
|
|
55
|
+
return byRadarKey.get(radarKey);
|
|
56
|
+
}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.NEXRAD_SWEEP_LAMBDA_URL = exports.NEXRAD_LEVEL3_BASE_URL = void 0;
|
|
7
|
+
exports.fetchLevel3ProductTimesForStation = fetchLevel3ProductTimesForStation;
|
|
8
|
+
exports.fetchNexradTimesListing = fetchNexradTimesListing;
|
|
9
|
+
exports.getAvailableNexradTilts = getAvailableNexradTilts;
|
|
10
|
+
exports.getRawNexradTiltsForCoalesce = getRawNexradTiltsForCoalesce;
|
|
11
|
+
exports.inferNexradDataSourceForProduct = inferNexradDataSourceForProduct;
|
|
12
|
+
exports.nexradBinGroupIdForKey = nexradBinGroupIdForKey;
|
|
13
|
+
exports.nexradColormapFldKey = nexradColormapFldKey;
|
|
14
|
+
exports.variableToNexradGroup = variableToNexradGroup;
|
|
15
|
+
var _nexradTilts = require("./nexradTilts.js");
|
|
16
|
+
var _nexradTiltCoalesce = require("./nexradTiltCoalesce.js");
|
|
17
|
+
var _nexrad_level3_catalog = require("./nexrad_level3_catalog.js");
|
|
18
|
+
/**
|
|
19
|
+
* NEXRAD Level-II / Level-III time listings (aligned with aguacero-frontend nexradTimes.ts).
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Whether listings and archive fetches for this product use Level-II sweep lambda vs Level-III S3 products.
|
|
24
|
+
* AguaceroCore derives this from the product key only (not user-configurable).
|
|
25
|
+
* @param {string} [nexradProduct] - Radar variable key (e.g. REF, KDP, VEL).
|
|
26
|
+
* @returns {'level2'|'level3'}
|
|
27
|
+
*/
|
|
28
|
+
function inferNexradDataSourceForProduct(nexradProduct) {
|
|
29
|
+
const p = (nexradProduct || 'REF').toUpperCase();
|
|
30
|
+
return (0, _nexrad_level3_catalog.getNexradLevel3EntryByRadarKey)(p) ? 'level3' : 'level2';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Colormap / DICTIONARIES.fld key for customColormaps (matches frontend userDefaultColormap). */
|
|
34
|
+
function nexradColormapFldKey(nexradDataSource, nexradProduct) {
|
|
35
|
+
const p = (nexradProduct || 'REF').toUpperCase();
|
|
36
|
+
if (nexradDataSource === 'level3') {
|
|
37
|
+
const entry = (0, _nexrad_level3_catalog.getNexradLevel3EntryByRadarKey)(p);
|
|
38
|
+
return (entry === null || entry === void 0 ? void 0 : entry.fldKey) ?? `nexrad_l3_${p.toLowerCase()}`;
|
|
39
|
+
}
|
|
40
|
+
const map = {
|
|
41
|
+
REF: 'nexrad_ref',
|
|
42
|
+
PHI: 'nexrad_phi',
|
|
43
|
+
ZDR: 'nexrad_zdr',
|
|
44
|
+
RHO: 'nexrad_rho',
|
|
45
|
+
KDP: 'nexrad_kdp',
|
|
46
|
+
VEL: 'nexrad_vel',
|
|
47
|
+
SW: 'nexrad_sw'
|
|
48
|
+
};
|
|
49
|
+
return map[p] ?? `nexrad_${p.toLowerCase()}`;
|
|
50
|
+
}
|
|
51
|
+
const NEXRAD_SWEEP_LAMBDA_URL = exports.NEXRAD_SWEEP_LAMBDA_URL = 'https://ddknicwcw2wyov7v5bzxmbqu440tzntf.lambda-url.us-east-2.on.aws/';
|
|
52
|
+
const NEXRAD_LEVEL3_BASE_URL = exports.NEXRAD_LEVEL3_BASE_URL = 'https://unidata-nexrad-level3.s3.amazonaws.com';
|
|
53
|
+
const NEXRAD_GROUP_G1 = ['REF', 'PHI', 'ZDR', 'RHO'];
|
|
54
|
+
const NEXRAD_GROUP_G2 = ['VEL', 'SW'];
|
|
55
|
+
function variableToNexradGroup(variable) {
|
|
56
|
+
const v = (variable || 'REF').toUpperCase();
|
|
57
|
+
if (NEXRAD_GROUP_G2.includes(v)) return 'g2';
|
|
58
|
+
return 'g1';
|
|
59
|
+
}
|
|
60
|
+
function nexradBinGroupIdForKey(cacheGroup) {
|
|
61
|
+
return cacheGroup === 'g1' ? 1 : 2;
|
|
62
|
+
}
|
|
63
|
+
function getLevel3StationPrefix(stationId) {
|
|
64
|
+
const upper = (stationId || '').toUpperCase();
|
|
65
|
+
if (upper.startsWith('K') && upper.length === 4) return upper.slice(1);
|
|
66
|
+
return upper.slice(-3);
|
|
67
|
+
}
|
|
68
|
+
function parseS3KeyTimeToUnix(key) {
|
|
69
|
+
const m = key.match(/_(\d{4})_(\d{2})_(\d{2})_(\d{2})_(\d{2})_(\d{2})$/);
|
|
70
|
+
if (!m) return null;
|
|
71
|
+
const [, y, mo, d, h, mi, s] = m;
|
|
72
|
+
const unix = Date.UTC(Number(y), Number(mo) - 1, Number(d), Number(h), Number(mi), Number(s)) / 1000;
|
|
73
|
+
return Number.isFinite(unix) ? unix : null;
|
|
74
|
+
}
|
|
75
|
+
async function fetchLevel3ProductTimesForStation(stationId, productCode, listWindowHours) {
|
|
76
|
+
const stationPrefix = getLevel3StationPrefix(stationId);
|
|
77
|
+
const nowMs = Date.now();
|
|
78
|
+
const nowSec = Math.floor(nowMs / 1000);
|
|
79
|
+
const hourSec = 3600;
|
|
80
|
+
const windowSec = Math.max(hourSec, Math.ceil(listWindowHours) * hourSec);
|
|
81
|
+
const dayPrefixForOffset = dayOff => {
|
|
82
|
+
const dt = new Date(nowMs - dayOff * 86400000);
|
|
83
|
+
const y = dt.getUTCFullYear();
|
|
84
|
+
const mo = String(dt.getUTCMonth() + 1).padStart(2, '0');
|
|
85
|
+
const day = String(dt.getUTCDate()).padStart(2, '0');
|
|
86
|
+
return `${stationPrefix}_${productCode}_${y}_${mo}_${day}_`;
|
|
87
|
+
};
|
|
88
|
+
const dayPrefixes = [dayPrefixForOffset(0), dayPrefixForOffset(1)];
|
|
89
|
+
const byUnix = new Map();
|
|
90
|
+
const listKeysForPrefix = async prefix => {
|
|
91
|
+
let continuationToken = null;
|
|
92
|
+
for (let page = 0; page < 8; page++) {
|
|
93
|
+
const params = new URLSearchParams({
|
|
94
|
+
'list-type': '2',
|
|
95
|
+
prefix,
|
|
96
|
+
'max-keys': '1000'
|
|
97
|
+
});
|
|
98
|
+
if (continuationToken) params.set('continuation-token', continuationToken);
|
|
99
|
+
const res = await fetch(`${NEXRAD_LEVEL3_BASE_URL}/?${params.toString()}`);
|
|
100
|
+
if (!res.ok) throw new Error(`Level3 list HTTP ${res.status}`);
|
|
101
|
+
const xml = await res.text();
|
|
102
|
+
const keyMatches = [...xml.matchAll(/<Key>([^<]+)<\/Key>/g)];
|
|
103
|
+
keyMatches.forEach(match => {
|
|
104
|
+
const objectKey = match[1];
|
|
105
|
+
const unix = parseS3KeyTimeToUnix(objectKey);
|
|
106
|
+
if (unix == null) return;
|
|
107
|
+
byUnix.set(unix, objectKey);
|
|
108
|
+
});
|
|
109
|
+
const tokenMatch = xml.match(/<NextContinuationToken>([^<]+)<\/NextContinuationToken>/);
|
|
110
|
+
continuationToken = (tokenMatch === null || tokenMatch === void 0 ? void 0 : tokenMatch[1]) || null;
|
|
111
|
+
if (!continuationToken) break;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
for (const prefix of dayPrefixes) {
|
|
115
|
+
await listKeysForPrefix(prefix);
|
|
116
|
+
}
|
|
117
|
+
const sorted = [...byUnix.keys()].sort((a, b) => a - b);
|
|
118
|
+
const windowStart = nowSec - windowSec;
|
|
119
|
+
let inWindow = sorted.filter(t => t >= windowStart);
|
|
120
|
+
if (inWindow.length === 0 && sorted.length > 0) {
|
|
121
|
+
inWindow = sorted.filter(t => t >= nowSec - Math.max(6 * hourSec, windowSec));
|
|
122
|
+
}
|
|
123
|
+
if (inWindow.length === 0 && sorted.length > 0) {
|
|
124
|
+
inWindow = sorted.slice(-48);
|
|
125
|
+
}
|
|
126
|
+
const timeToKeyMap = {};
|
|
127
|
+
inWindow.forEach(t => {
|
|
128
|
+
const k = byUnix.get(t);
|
|
129
|
+
if (k) timeToKeyMap[String(t)] = k;
|
|
130
|
+
});
|
|
131
|
+
return {
|
|
132
|
+
unixTimes: inWindow,
|
|
133
|
+
timeToKeyMap
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* @param {object} opts
|
|
139
|
+
* @param {string} opts.stationId
|
|
140
|
+
* @param {string} [opts.variable]
|
|
141
|
+
* @param {string} [opts.elev]
|
|
142
|
+
* @param {'level2'|'level3'} [opts.source]
|
|
143
|
+
* @param {boolean} [opts.level3StormRelative]
|
|
144
|
+
* @param {number} opts.listingWindowHours
|
|
145
|
+
*/
|
|
146
|
+
async function fetchNexradTimesListing(opts) {
|
|
147
|
+
var _getNexradLevel3Entry;
|
|
148
|
+
const {
|
|
149
|
+
stationId,
|
|
150
|
+
variable = 'REF',
|
|
151
|
+
elev,
|
|
152
|
+
source = 'level2',
|
|
153
|
+
level3StormRelative,
|
|
154
|
+
listingWindowHours
|
|
155
|
+
} = opts;
|
|
156
|
+
if (!stationId) {
|
|
157
|
+
return {
|
|
158
|
+
unixTimes: [],
|
|
159
|
+
timeToKeyMap: {},
|
|
160
|
+
level3MotionUnixTimes: [],
|
|
161
|
+
level3MotionTimeToKeyMap: {}
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
const dataSource = source === 'level3' ? 'level3' : 'level2';
|
|
165
|
+
let tiltNum = Number(elev);
|
|
166
|
+
if (!Number.isFinite(tiltNum)) tiltNum = (0, _nexradTilts.getDefaultRadarTilt)(stationId);
|
|
167
|
+
const elevNormUse = dataSource === 'level3' ? _nexrad_level3_catalog.NEXRAD_LEVEL3_ELEV : (0, _nexradTilts.formatTiltForApi)((0, _nexradTilts.clampNexradTiltForVariable)(stationId, variable, tiltNum));
|
|
168
|
+
const group = dataSource === 'level3' ? 'l3' : variableToNexradGroup(variable);
|
|
169
|
+
const l3Product = dataSource === 'level3' ? opts.level3Product ?? ((_getNexradLevel3Entry = (0, _nexrad_level3_catalog.getNexradLevel3EntryByRadarKey)(variable)) === null || _getNexradLevel3Entry === void 0 ? void 0 : _getNexradLevel3Entry.product) ?? (variable === 'VEL' ? 'N0G' : variable) : '';
|
|
170
|
+
const fetchL3Motion = dataSource === 'level3' && l3Product === 'N0G' && variable === 'VEL' && level3StormRelative === true;
|
|
171
|
+
const fetchL2VelMotion = dataSource === 'level2' && variable === 'VEL' && level3StormRelative === true;
|
|
172
|
+
const key = dataSource === 'level3' ? `${stationId}_l3_${l3Product}_${elevNormUse}` : `${stationId}_${group}_${elevNormUse}`;
|
|
173
|
+
const level3MotionKey = dataSource === 'level3' && fetchL3Motion ? `${stationId}_l3_${_nexrad_level3_catalog.NEXRAD_LEVEL3_MOTION_PRODUCT}_${elevNormUse}` : '';
|
|
174
|
+
const l2StormMotionListKey = dataSource === 'level2' && fetchL2VelMotion ? `${stationId}_l3_${_nexrad_level3_catalog.NEXRAD_LEVEL3_MOTION_PRODUCT}_${_nexrad_level3_catalog.NEXRAD_LEVEL3_ELEV}` : '';
|
|
175
|
+
let times = [];
|
|
176
|
+
let timeToKeyMap = {};
|
|
177
|
+
let l3MotionUnixTimes = [];
|
|
178
|
+
let l3MotionTimeToKeyMap = {};
|
|
179
|
+
if (dataSource === 'level3') {
|
|
180
|
+
const l3Primary = await fetchLevel3ProductTimesForStation(stationId, l3Product, listingWindowHours);
|
|
181
|
+
times = l3Primary.unixTimes;
|
|
182
|
+
timeToKeyMap = l3Primary.timeToKeyMap;
|
|
183
|
+
if (fetchL3Motion) {
|
|
184
|
+
const l3Motion = await fetchLevel3ProductTimesForStation(stationId, _nexrad_level3_catalog.NEXRAD_LEVEL3_MOTION_PRODUCT, listingWindowHours);
|
|
185
|
+
l3MotionUnixTimes = l3Motion.unixTimes;
|
|
186
|
+
l3MotionTimeToKeyMap = l3Motion.timeToKeyMap;
|
|
187
|
+
}
|
|
188
|
+
} else {
|
|
189
|
+
const params = new URLSearchParams({
|
|
190
|
+
station: stationId,
|
|
191
|
+
field: group,
|
|
192
|
+
elev: elevNormUse,
|
|
193
|
+
hours: String(listingWindowHours)
|
|
194
|
+
});
|
|
195
|
+
const url = `${NEXRAD_SWEEP_LAMBDA_URL}?${params.toString()}`;
|
|
196
|
+
const res = await fetch(url);
|
|
197
|
+
if (!res.ok) throw new Error(`NEXRAD lambda HTTP ${res.status}`);
|
|
198
|
+
const data = await res.json();
|
|
199
|
+
if (Array.isArray(data === null || data === void 0 ? void 0 : data.times)) {
|
|
200
|
+
times = data.times;
|
|
201
|
+
} else if (data !== null && data !== void 0 && data.body) {
|
|
202
|
+
const body = typeof data.body === 'string' ? JSON.parse(data.body) : data.body;
|
|
203
|
+
times = Array.isArray(body === null || body === void 0 ? void 0 : body.times) ? body.times : [];
|
|
204
|
+
}
|
|
205
|
+
const groupId = nexradBinGroupIdForKey(group);
|
|
206
|
+
const elevNorm = elevNormUse;
|
|
207
|
+
times.forEach(t => {
|
|
208
|
+
timeToKeyMap[String(t)] = `${stationId}_${elevNorm}_${t}_g${groupId}.bin`;
|
|
209
|
+
});
|
|
210
|
+
if (fetchL2VelMotion) {
|
|
211
|
+
const l3Motion = await fetchLevel3ProductTimesForStation(stationId, _nexrad_level3_catalog.NEXRAD_LEVEL3_MOTION_PRODUCT, listingWindowHours);
|
|
212
|
+
l3MotionUnixTimes = l3Motion.unixTimes;
|
|
213
|
+
l3MotionTimeToKeyMap = l3Motion.timeToKeyMap;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
const out = {
|
|
217
|
+
cacheKey: key,
|
|
218
|
+
unixTimes: times,
|
|
219
|
+
timeToKeyMap,
|
|
220
|
+
level3MotionKey: level3MotionKey || null,
|
|
221
|
+
level3MotionUnixTimes: l3MotionUnixTimes,
|
|
222
|
+
level3MotionTimeToKeyMap: l3MotionTimeToKeyMap,
|
|
223
|
+
l2StormMotionListKey: l2StormMotionListKey || null
|
|
224
|
+
};
|
|
225
|
+
return out;
|
|
226
|
+
}
|
|
227
|
+
const L3_TILT_INDEX_MANIFEST_SLOTS = 6;
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Raw manifest tilt list before coalescing (same rules as aguacero-frontend `radarTiltOptionsRaw`).
|
|
231
|
+
* Use {@link coalesceNexradTiltOptionsForDisplay} or {@link getAvailableNexradTilts} for UI controls.
|
|
232
|
+
*
|
|
233
|
+
* @param {string} siteId
|
|
234
|
+
* @param {'level2'|'level3'} nexradDataSource
|
|
235
|
+
* @param {string} [nexradProduct]
|
|
236
|
+
* @returns {number[]}
|
|
237
|
+
*/
|
|
238
|
+
function getRawNexradTiltsForCoalesce(siteId, nexradDataSource, nexradProduct) {
|
|
239
|
+
if (!siteId) return [];
|
|
240
|
+
const v = (nexradProduct || 'REF').toUpperCase();
|
|
241
|
+
const ds = nexradDataSource === 'level3' ? 'level3' : 'level2';
|
|
242
|
+
const tilts = (0, _nexradTilts.getRadarTilts)(siteId, v);
|
|
243
|
+
/** L3 super-res VEL (N*G) uses the same first-N manifest slots as KDP/N0H — not the full L2 g2-only list. */
|
|
244
|
+
if (v === 'VEL') {
|
|
245
|
+
return tilts.slice(0, L3_TILT_INDEX_MANIFEST_SLOTS);
|
|
246
|
+
}
|
|
247
|
+
if (ds === 'level2') {
|
|
248
|
+
return [...tilts];
|
|
249
|
+
}
|
|
250
|
+
if (v === 'KDP' || v === 'N0H') {
|
|
251
|
+
return tilts.slice(0, L3_TILT_INDEX_MANIFEST_SLOTS);
|
|
252
|
+
}
|
|
253
|
+
return [];
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Tilt angles for the UI: manifest tilts with adjacent 0.1° steps merged like aguacero-frontend
|
|
258
|
+
* ({@link coalesceNexradTiltOptionsForDisplay}).
|
|
259
|
+
*
|
|
260
|
+
* @param {string} siteId
|
|
261
|
+
* @param {'level2'|'level3'} nexradDataSource
|
|
262
|
+
* @param {string} [nexradProduct]
|
|
263
|
+
* @returns {number[]}
|
|
264
|
+
*/
|
|
265
|
+
function getAvailableNexradTilts(siteId, nexradDataSource, nexradProduct) {
|
|
266
|
+
const raw = getRawNexradTiltsForCoalesce(siteId, nexradDataSource, nexradProduct);
|
|
267
|
+
if (!raw.length) return [];
|
|
268
|
+
return (0, _nexradTiltCoalesce.coalesceNexradTiltOptionsForDisplay)(raw);
|
|
269
|
+
}
|