@aguacerowx/javascript-sdk 0.0.18 → 0.0.20

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.
@@ -190,6 +190,92 @@ export const DEFAULT_COLORMAPS = {
190
190
  },
191
191
  },
192
192
  },
193
+ "nexrad_kdp" : {
194
+ units : {
195
+ 'deg/km' : {
196
+ colormap : [
197
+ -2, "#8e8e8e",
198
+ -0.5, "#4c0001",
199
+ 0.25, "#a3072f",
200
+ 1, "#ea73b4",
201
+ 1.5, "#997eb9",
202
+ 2, "#68f4f4",
203
+ 2.5, "#1aba34",
204
+ 3, "#11f910",
205
+ 4, "#f7fc00",
206
+ 5, "#ff7c10",
207
+ 7, "#ffc47c",
208
+ 10, "#790279",
209
+ ],
210
+ breakpoints : [-2, -0.5, 0.25, 1, 1.5, 2, 2.5, 3, 4, 5, 7, 10],
211
+ },
212
+ },
213
+ },
214
+ "nexrad_l3_n0h": {
215
+ units: {
216
+ None: {
217
+ colormap: [
218
+ 0, "#d0d0d0",
219
+ 1, "#696969",
220
+ 2, "#ffccd5",
221
+ 3, "#a8d8f0",
222
+ 4, "#2566d8",
223
+ 5, "#b8f5b8",
224
+ 6, "#1a8f1a",
225
+ 7, "#f5e6b8",
226
+ 8, "#ff8787",
227
+ 9, "#e02020",
228
+ 10, "#5c0000",
229
+ 11, "#ffd700",
230
+ ],
231
+ breakpoints: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
232
+ },
233
+ },
234
+ },
235
+ "nexrad_l3_hhc": {
236
+ units: {
237
+ None: {
238
+ colormap: [
239
+ 0, "#d0d0d0",
240
+ 1, "#696969",
241
+ 2, "#ffccd5",
242
+ 3, "#a8d8f0",
243
+ 4, "#2566d8",
244
+ 5, "#b8f5b8",
245
+ 6, "#1a8f1a",
246
+ 7, "#f5e6b8",
247
+ 8, "#ff8787",
248
+ 9, "#e02020",
249
+ 10, "#5c0000",
250
+ 11, "#ffd700",
251
+ ],
252
+ breakpoints: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
253
+ },
254
+ },
255
+ },
256
+ "nexrad_l3_eet": {
257
+ units: {
258
+ kft: {
259
+ colormap: [
260
+ 5, "#737373",
261
+ 10, "#818181",
262
+ 15, "#919191",
263
+ 20, "#a5a5a5",
264
+ 25, "#49af45",
265
+ 30, "#19770b",
266
+ 35, "#fedd00",
267
+ 40, "#fc6901",
268
+ 45, "#bf0005",
269
+ 50, "#800001",
270
+ 55, "#cf2ad3",
271
+ 60, "#b117b5",
272
+ 65, "#00b6c5",
273
+ 70, "#009ca9",
274
+ ],
275
+ breakpoints: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22],
276
+ },
277
+ },
278
+ },
193
279
  "rotation" : {
194
280
  units : {
195
281
  's⁻¹' : {
@@ -3007,6 +3007,69 @@ export const DICTIONARIES = {
3007
3007
  defaultUnit: 'm/s',
3008
3008
  description: 'Spread of velocities within a radar sample volume. High values indicate turbulence or wind shear.',
3009
3009
  },
3010
+ "nexrad_kdp": {
3011
+ category: "NEXRAD",
3012
+ variable: "Specific Differential Phase",
3013
+ shortname: "KDP",
3014
+ defaultUnit: 'deg/km',
3015
+ description: 'Rate of change of differential phase along the radar beam; used to estimate rain rate.',
3016
+ },
3017
+ "nexrad_l3_n0k": {
3018
+ category: "NEXRAD",
3019
+ variable: "Specific Differential Phase (Level III)",
3020
+ shortname: "N0K",
3021
+ defaultUnit: 'deg/km',
3022
+ description: 'Level-III KDP (digital) by tilt slot.',
3023
+ },
3024
+ "nexrad_l3_dvl": {
3025
+ category: "NEXRAD",
3026
+ variable: "Vertically Integrated Liquid",
3027
+ shortname: "DVL",
3028
+ defaultUnit: 'kg/m²',
3029
+ description: 'Integrated liquid water content in the column above each gate.',
3030
+ },
3031
+ "nexrad_l3_eet": {
3032
+ category: "NEXRAD",
3033
+ variable: "Enhanced Echo Tops",
3034
+ shortname: "EET",
3035
+ defaultUnit: 'kft',
3036
+ description: 'Height of echo tops in hundreds of feet MSL (product-dependent scaling).',
3037
+ },
3038
+ "nexrad_l3_n0h": {
3039
+ category: "NEXRAD",
3040
+ variable: "Hydrometeor Classification",
3041
+ shortname: "N0H",
3042
+ defaultUnit: 'None',
3043
+ description: 'Digital hydrometeor classification by class index.',
3044
+ },
3045
+ "nexrad_l3_hhc": {
3046
+ category: "NEXRAD",
3047
+ variable: "Hybrid Hydrometeor Classification",
3048
+ shortname: "HHC",
3049
+ defaultUnit: 'None',
3050
+ description: 'Hybrid hydrometeor classification product.',
3051
+ },
3052
+ "nexrad_l3_daa": {
3053
+ category: "NEXRAD",
3054
+ variable: "1-Hour Accumulation",
3055
+ shortname: "DAA",
3056
+ defaultUnit: 'in',
3057
+ description: 'One-hour precipitation accumulation.',
3058
+ },
3059
+ "nexrad_l3_du3": {
3060
+ category: "NEXRAD",
3061
+ variable: "3-Hour Accumulation",
3062
+ shortname: "DU3",
3063
+ defaultUnit: 'in',
3064
+ description: 'Three-hour precipitation accumulation.',
3065
+ },
3066
+ "nexrad_l3_dta": {
3067
+ category: "NEXRAD",
3068
+ variable: "Storm Total Precipitation",
3069
+ shortname: "DTA",
3070
+ defaultUnit: 'in',
3071
+ description: 'Storm-total precipitation accumulation.',
3072
+ },
3010
3073
  "MergedAzShear_0-2kmAGL_00.50": {
3011
3074
  category: "Rotation",
3012
3075
  variable: "Rotation Track (Instant)",
@@ -3394,6 +3457,16 @@ export const DICTIONARIES = {
3394
3457
  'nexrad_rho': 'MergedRhoHV_04.00',
3395
3458
  'nexrad_vel': 'nexrad_vel',
3396
3459
  'nexrad_sw': 'nexrad_sw',
3460
+ 'nexrad_kdp': 'nexrad_kdp',
3461
+ 'nexrad_l3_n0k': 'nexrad_kdp',
3462
+ 'nexrad_l3_n0h': 'nexrad_l3_n0h',
3463
+ 'nexrad_l3_hhc': 'nexrad_l3_hhc',
3464
+ 'nexrad_l3_eet': 'nexrad_l3_eet',
3465
+ 'nexrad_l3_dvl': 'vil',
3466
+ 'nexrad_l3_nvl': 'vil',
3467
+ 'nexrad_l3_daa': 'tp_0_1',
3468
+ 'nexrad_l3_du3': 'tp_0_total',
3469
+ 'nexrad_l3_dta': 'tp_0_total',
3397
3470
  //mrms
3398
3471
  'MergedReflectivityQCComposite_00.50': 'refc_0',
3399
3472
  'CREF_1HR_MAX_00.50': 'refc_0',
@@ -1,22 +1,8 @@
1
- // This module acts as a platform-agnostic proxy.
2
-
3
- let getBundleIdImpl;
4
-
5
- try {
6
- // This line will ONLY succeed in a React Native environment where the
7
- // 'react-native-device-info' module is installed.
8
- const DeviceInfo = require('react-native-device-info');
9
-
10
- // If the above line doesn't throw an error, we set the implementation
11
- // to the native version.
12
- getBundleIdImpl = () => DeviceInfo.getBundleId();
13
-
14
- } catch (e) {
15
- // If require() fails, we know we are in a non-React Native environment
16
- // (like the web). We set the implementation to a "dummy" function
17
- // that does nothing and returns null.
18
- getBundleIdImpl = () => null;
19
- }
20
-
21
- // Export the chosen implementation.
22
- export const getBundleId = getBundleIdImpl;
1
+ /**
2
+ * Default implementation for web and Node bundlers (Vite, webpack).
3
+ * Do not import react-native-device-info here: static analysis would pull in
4
+ * `react-native` (Flow sources) and break esbuild.
5
+ *
6
+ * Metro resolves `getBundleId.native.js` on iOS/Android instead of this file.
7
+ */
8
+ export const getBundleId = () => null;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * React Native (Metro picks this file over getBundleId.js on native platforms).
3
+ */
4
+
5
+ let getBundleIdImpl;
6
+
7
+ try {
8
+ const DeviceInfo = require('react-native-device-info');
9
+ getBundleIdImpl = () => DeviceInfo.getBundleId();
10
+ } catch {
11
+ getBundleIdImpl = () => null;
12
+ }
13
+
14
+ export const getBundleId = getBundleIdImpl;
@@ -0,0 +1,32 @@
1
+ import { decompress } from 'fzstd';
2
+
3
+ function reconstructData(decompressedDeltas, encoding) {
4
+ const expectedLength = encoding.length;
5
+ const reconstructedData = new Int8Array(expectedLength);
6
+
7
+ if (decompressedDeltas.length > 0 && expectedLength > 0) {
8
+ reconstructedData[0] = decompressedDeltas[0] > 127 ? decompressedDeltas[0] - 256 : decompressedDeltas[0];
9
+ for (let i = 1; i < expectedLength; i++) {
10
+ const delta = decompressedDeltas[i] > 127 ? decompressedDeltas[i] - 256 : decompressedDeltas[i];
11
+ reconstructedData[i] = reconstructedData[i - 1] + delta;
12
+ }
13
+ }
14
+ return new Uint8Array(reconstructedData.buffer);
15
+ }
16
+
17
+ /**
18
+ * zstd decompress → delta reconstruction → unsigned byte offset for GPU lookup.
19
+ * Used on the main thread as a fallback and inside {@link ./gridDecodeWorker.js}.
20
+ */
21
+ export function processCompressedGrid(compressedData, encoding) {
22
+ const decompressedDeltas = decompress(compressedData);
23
+ const finalData = reconstructData(decompressedDeltas, encoding);
24
+
25
+ const transformedData = new Uint8Array(finalData.length);
26
+ for (let i = 0; i < finalData.length; i++) {
27
+ const signedValue = finalData[i] > 127 ? finalData[i] - 256 : finalData[i];
28
+ transformedData[i] = signedValue + 128;
29
+ }
30
+
31
+ return { data: transformedData, encoding };
32
+ }
@@ -0,0 +1,24 @@
1
+ import { processCompressedGrid } from './gridDecodePipeline.js';
2
+
3
+ self.onmessage = (e) => {
4
+ const { id, encoding, compressedBuffer, compressedByteOffset, compressedByteLength } = e.data;
5
+ try {
6
+ const compressedData = new Uint8Array(compressedBuffer, compressedByteOffset, compressedByteLength);
7
+ const { data, encoding: enc } = processCompressedGrid(compressedData, encoding);
8
+ self.postMessage(
9
+ {
10
+ id,
11
+ encoding: enc,
12
+ dataBuffer: data.buffer,
13
+ dataByteOffset: data.byteOffset,
14
+ dataByteLength: data.byteLength,
15
+ },
16
+ [data.buffer]
17
+ );
18
+ } catch (err) {
19
+ self.postMessage({
20
+ id,
21
+ error: err?.message || String(err),
22
+ });
23
+ }
24
+ };
package/src/index.js CHANGED
@@ -5,7 +5,23 @@ import { AguaceroCore } from './AguaceroCore.js';
5
5
  import { EventEmitter } from './events.js';
6
6
  import { THEME_CONFIGS } from './map-styles.js';
7
7
  import { DICTIONARIES } from './dictionaries.js';
8
+ import { DEFAULT_COLORMAPS } from './default-colormaps.js';
8
9
  import { getUnitConversionFunction } from './unitConversions.js';
10
+ export {
11
+ SATELLITE_FRAMES_URL,
12
+ GOES_EAST_SATELLITE_SECTORS,
13
+ GOES_SATELLITE_CHANNELS,
14
+ GOES_SATELLITE_CHANNEL_LABELS,
15
+ SATELLITE_DURATION_CONFIG,
16
+ TIMELINE_DURATION_HOUR_VALUES,
17
+ normalizeTimelineDurationValue,
18
+ parseTimelineDurationHours,
19
+ getDefaultSatelliteDurationOption,
20
+ buildSatelliteTimelineForKey,
21
+ getAllGoesEastSatelliteKeys,
22
+ calculateUnixTimeFromSatelliteKey,
23
+ resolveSatelliteS3FileName,
24
+ } from './satellite_support.js';
9
25
 
10
26
  // Now, export them all so other packages can import them.
11
27
  export {
@@ -13,5 +29,10 @@ export {
13
29
  EventEmitter,
14
30
  THEME_CONFIGS,
15
31
  DICTIONARIES,
32
+ DEFAULT_COLORMAPS,
16
33
  getUnitConversionFunction
17
- };
34
+ };
35
+
36
+ /** NEXRAD tilt + listing helpers (also importable via subpaths; root re-export fixes Vite/esbuild subpath resolution). */
37
+ export * from './nexradTilts.js';
38
+ export * from './nexrad_support.js';
@@ -0,0 +1,128 @@
1
+ /**
2
+ * NEXRAD tilt helpers (mirrors aguacero-frontend dictionaries + radar tilts manifest behavior).
3
+ * When {@link setRadarTiltsManifest} has been called with a non-empty map, per-site tilts follow it.
4
+ */
5
+
6
+ const WSR88D_TILTS = [0.5, 0.9, 1.3, 1.8, 2.4, 3.1, 4.0, 5.1, 6.4];
7
+ const TDWR_TILTS = [0.3, 1.0, 2, 6.5, 8.8, 16.0, 21.3];
8
+
9
+ const WSR88D_SITE_IDS_WITH_T_PREFIX = new Set(['TJUA']);
10
+
11
+ /** @type {Record<string, { g1_tilts: number[]; g2_tilts: number[]; last_seen?: number }>} */
12
+ let manifestBySite = {};
13
+
14
+ export function setRadarTiltsManifest(map) {
15
+ manifestBySite = map && typeof map === 'object' ? map : {};
16
+ }
17
+
18
+ export function getRadarTiltsManifest() {
19
+ return manifestBySite;
20
+ }
21
+
22
+ export function isNexradTdwrSiteId(siteId) {
23
+ const id = String(siteId ?? '').trim().toUpperCase();
24
+ if (!id) return false;
25
+ if (WSR88D_SITE_IDS_WITH_T_PREFIX.has(id)) return false;
26
+ return id.startsWith('T');
27
+ }
28
+
29
+ export function isTerminalRadar(siteId) {
30
+ return isNexradTdwrSiteId(siteId);
31
+ }
32
+
33
+ const NEXRAD_G2_VARIABLES = new Set(['VEL', 'SW']);
34
+ const TDWR_DUAL_POL_CAPPED = new Set(['ZDR', 'PHI', 'RHO', 'KDP']);
35
+ const TDWR_DUAL_POL_MAX_TILT = 0.3;
36
+
37
+ function uniqSorted(nums) {
38
+ const arr = nums.filter((n) => typeof n === 'number' && Number.isFinite(n));
39
+ const rounded = arr.map((n) => Math.round(n * 1000) / 1000);
40
+ return [...new Set(rounded)].sort((a, b) => a - b);
41
+ }
42
+
43
+ function computeRadarTiltsFromManifestEntry(entry, siteId, radarVariable) {
44
+ const v = (radarVariable || 'REF').toUpperCase();
45
+ let base;
46
+ if (NEXRAD_G2_VARIABLES.has(v)) {
47
+ base = uniqSorted(entry.g2_tilts || []);
48
+ } else {
49
+ base = uniqSorted([...(entry.g1_tilts || []), ...(entry.g2_tilts || [])]);
50
+ }
51
+ if (isNexradTdwrSiteId(siteId) && TDWR_DUAL_POL_CAPPED.has(v)) {
52
+ return base.filter((t) => t <= TDWR_DUAL_POL_MAX_TILT);
53
+ }
54
+ return base;
55
+ }
56
+
57
+ function getDefaultTiltFromManifestEntry(entry) {
58
+ const g1 = entry.g1_tilts;
59
+ if (!Array.isArray(g1) || g1.length === 0) return null;
60
+ const sorted = uniqSorted(g1);
61
+ return sorted[0] ?? null;
62
+ }
63
+
64
+ export function getDefaultRadarTilt(siteId) {
65
+ const id = siteId?.toUpperCase();
66
+ const entry = id ? manifestBySite[id] : undefined;
67
+ if (entry) {
68
+ const t = getDefaultTiltFromManifestEntry(entry);
69
+ if (t != null) return t;
70
+ }
71
+ return isTerminalRadar(siteId) ? 0.3 : 0.5;
72
+ }
73
+
74
+ export function getRadarTilts(siteId, radarVariable) {
75
+ const id = siteId?.toUpperCase();
76
+ const entry = id ? manifestBySite[id] : undefined;
77
+ if (entry) {
78
+ const fromManifest = computeRadarTiltsFromManifestEntry(entry, siteId, radarVariable);
79
+ if (fromManifest.length) return fromManifest;
80
+ }
81
+ const base = isTerminalRadar(siteId) ? TDWR_TILTS : WSR88D_TILTS;
82
+ if (!radarVariable || !isTerminalRadar(siteId)) return [...base];
83
+ const v = radarVariable.toUpperCase();
84
+ if (['ZDR', 'PHI', 'RHO'].includes(v)) {
85
+ return base.filter((t) => t <= TDWR_DUAL_POL_MAX_TILT);
86
+ }
87
+ return [...base];
88
+ }
89
+
90
+ export function clampNexradTiltForVariable(siteId, variable, tilt) {
91
+ if (!isTerminalRadar(siteId)) return tilt;
92
+ const v = (variable || 'REF').toUpperCase();
93
+ if (['ZDR', 'PHI', 'RHO'].includes(v)) {
94
+ return Math.min(tilt, TDWR_DUAL_POL_MAX_TILT);
95
+ }
96
+ return tilt;
97
+ }
98
+
99
+ export function formatTiltForApi(tilt) {
100
+ return tilt.toFixed(2);
101
+ }
102
+
103
+ export const RADAR_TILTS_MANIFEST_URL =
104
+ 'https://radar-tilts.s3.us-east-2.amazonaws.com/manifest.json';
105
+
106
+ export async function fetchRadarTiltsManifestFromNetwork() {
107
+ try {
108
+ const res = await fetch(RADAR_TILTS_MANIFEST_URL, { cache: 'no-store' });
109
+ if (!res.ok) return null;
110
+ const raw = await res.json();
111
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return null;
112
+ const out = {};
113
+ for (const [key, val] of Object.entries(raw)) {
114
+ if (!val || typeof val !== 'object' || Array.isArray(val)) continue;
115
+ const g1 = val.g1_tilts;
116
+ const g2 = val.g2_tilts;
117
+ if (!Array.isArray(g1) || !Array.isArray(g2)) continue;
118
+ out[key.toUpperCase()] = {
119
+ g1_tilts: g1.filter((n) => typeof n === 'number' && Number.isFinite(n)),
120
+ g2_tilts: g2.filter((n) => typeof n === 'number' && Number.isFinite(n)),
121
+ last_seen: typeof val.last_seen === 'number' ? val.last_seen : undefined,
122
+ };
123
+ }
124
+ return Object.keys(out).length ? out : null;
125
+ } catch {
126
+ return null;
127
+ }
128
+ }
@@ -0,0 +1,26 @@
1
+ /** Subset of aguacero-frontend NEXRAD_LEVEL3_MENU for API product resolution. */
2
+
3
+ export const NEXRAD_LEVEL3_ELEV = '0.50';
4
+ export const NEXRAD_LEVEL3_MOTION_PRODUCT = 'N0S';
5
+
6
+ const MENU = [
7
+ { radarKey: 'VEL', product: 'N0G', fldKey: 'nexrad_vel' },
8
+ { radarKey: 'KDP', product: 'N0K', fldKey: 'nexrad_l3_n0k' },
9
+ { radarKey: 'N0H', product: 'N0H', fldKey: 'nexrad_l3_n0h' },
10
+ { radarKey: 'HHC', product: 'HHC', fldKey: 'nexrad_l3_hhc' },
11
+ { radarKey: 'EET', product: 'EET', fldKey: 'nexrad_l3_eet' },
12
+ { radarKey: 'DVL', product: 'DVL', fldKey: 'nexrad_l3_dvl' },
13
+ { radarKey: 'DAA', product: 'DAA', fldKey: 'nexrad_l3_daa' },
14
+ { radarKey: 'DU3', product: 'DU3', fldKey: 'nexrad_l3_du3' },
15
+ { radarKey: 'DTA', product: 'DTA', fldKey: 'nexrad_l3_dta' },
16
+ ];
17
+
18
+ const byRadarKey = new Map();
19
+ for (const e of MENU) {
20
+ byRadarKey.set(e.radarKey, e);
21
+ }
22
+ byRadarKey.set('NVL', byRadarKey.get('DVL'));
23
+
24
+ export function getNexradLevel3EntryByRadarKey(radarKey) {
25
+ return byRadarKey.get(radarKey);
26
+ }