@aguacerowx/javascript-sdk 0.0.16 → 0.0.18
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 +90 -45
- package/dist/default-colormaps.js +524 -437
- package/dist/dictionaries.js +1996 -2411
- package/package.json +1 -1
- package/src/default-colormaps.js +1308 -997
- package/src/dictionaries.js +2046 -2548
package/dist/AguaceroCore.js
CHANGED
|
@@ -81,10 +81,13 @@ class AguaceroCore extends _events.EventEmitter {
|
|
|
81
81
|
this.playbackSpeed = options.playbackSpeed || 500;
|
|
82
82
|
this.customColormaps = options.customColormaps || {};
|
|
83
83
|
const userLayerOptions = options.layerOptions || {};
|
|
84
|
+
// EDIT: Determine initial mode from options
|
|
85
|
+
const initialMode = userLayerOptions.mode || 'model';
|
|
84
86
|
const initialVariable = userLayerOptions.variable || null;
|
|
85
87
|
this.state = {
|
|
86
88
|
model: userLayerOptions.model || 'gfs',
|
|
87
|
-
|
|
89
|
+
// EDIT: Set isMRMS based on the initial mode
|
|
90
|
+
isMRMS: initialMode === 'mrms',
|
|
88
91
|
mrmsTimestamp: null,
|
|
89
92
|
variable: initialVariable,
|
|
90
93
|
date: null,
|
|
@@ -116,11 +119,16 @@ class AguaceroCore extends _events.EventEmitter {
|
|
|
116
119
|
const timestamps = this.mrmsStatus[this.state.variable] || [];
|
|
117
120
|
availableTimestamps = [...timestamps].reverse();
|
|
118
121
|
}
|
|
122
|
+
let availableHours = this.state.isMRMS ? [] : ((_this$modelStatus = this.modelStatus) === null || _this$modelStatus === void 0 || (_this$modelStatus = _this$modelStatus[this.state.model]) === null || _this$modelStatus === void 0 || (_this$modelStatus = _this$modelStatus[this.state.date]) === null || _this$modelStatus === void 0 ? void 0 : _this$modelStatus[this.state.run]) || [];
|
|
123
|
+
if (!this.state.isMRMS && this.state.variable === 'ptypeRefl' && this.state.model === 'hrrr' && availableHours.length > 0) {
|
|
124
|
+
availableHours = availableHours.filter(hour => hour !== 0);
|
|
125
|
+
}
|
|
119
126
|
const eventPayload = {
|
|
120
127
|
...this.state,
|
|
121
128
|
availableModels: this.modelStatus ? Object.keys(this.modelStatus).sort() : [],
|
|
122
|
-
availableRuns: ((_this$
|
|
123
|
-
availableHours:
|
|
129
|
+
availableRuns: ((_this$modelStatus2 = this.modelStatus) === null || _this$modelStatus2 === void 0 ? void 0 : _this$modelStatus2[this.state.model]) || {},
|
|
130
|
+
availableHours: availableHours,
|
|
131
|
+
// <-- Changed from inline calculation
|
|
124
132
|
availableVariables: this.getAvailableVariables(this.state.isMRMS ? 'mrms' : this.state.model),
|
|
125
133
|
// We need to confirm this line is working as expected.
|
|
126
134
|
availableMRMSVariables: this.getAvailableVariables('mrms'),
|
|
@@ -134,17 +142,42 @@ class AguaceroCore extends _events.EventEmitter {
|
|
|
134
142
|
async initialize(options = {}) {
|
|
135
143
|
await this.fetchModelStatus(true);
|
|
136
144
|
await this.fetchMRMSStatus(true);
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
145
|
+
let initialState = {
|
|
146
|
+
...this.state
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
// ADD: Logic to handle an initial MRMS state
|
|
150
|
+
if (initialState.isMRMS) {
|
|
151
|
+
const variable = initialState.variable;
|
|
152
|
+
if (variable && this.mrmsStatus && this.mrmsStatus[variable]) {
|
|
153
|
+
const sortedTimestamps = [...(this.mrmsStatus[variable] || [])].sort((a, b) => b - a);
|
|
154
|
+
initialState.mrmsTimestamp = sortedTimestamps.length > 0 ? sortedTimestamps[0] : null;
|
|
155
|
+
} else {
|
|
156
|
+
// Fallback if the provided variable is not valid
|
|
157
|
+
console.warn(`Initial MRMS variable '${variable}' not found. Using default.`);
|
|
158
|
+
const availableMRMSVars = this.getAvailableVariables('mrms');
|
|
159
|
+
if (availableMRMSVars.length > 0) {
|
|
160
|
+
const firstVar = availableMRMSVars[0];
|
|
161
|
+
initialState.variable = firstVar;
|
|
162
|
+
const sortedTimestamps = [...(this.mrmsStatus[firstVar] || [])].sort((a, b) => b - a);
|
|
163
|
+
initialState.mrmsTimestamp = sortedTimestamps.length > 0 ? sortedTimestamps[0] : null;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
} else {
|
|
167
|
+
// EDIT: This is the existing logic, now in an else block
|
|
168
|
+
const latestRun = findLatestModelRun(this.modelStatus, initialState.model);
|
|
169
|
+
if (latestRun) {
|
|
170
|
+
initialState = {
|
|
171
|
+
...initialState,
|
|
172
|
+
...latestRun,
|
|
173
|
+
forecastHour: 0
|
|
174
|
+
};
|
|
175
|
+
if (!initialState.variable) {
|
|
176
|
+
const availableVariables = this.getAvailableVariables(initialState.model);
|
|
177
|
+
if (availableVariables && availableVariables.length > 0) {
|
|
178
|
+
initialState.variable = availableVariables[0];
|
|
179
|
+
}
|
|
180
|
+
}
|
|
148
181
|
}
|
|
149
182
|
}
|
|
150
183
|
await this.setState(initialState);
|
|
@@ -264,20 +297,45 @@ class AguaceroCore extends _events.EventEmitter {
|
|
|
264
297
|
});
|
|
265
298
|
}
|
|
266
299
|
async setVariable(variable) {
|
|
300
|
+
// --- NEW CODE: Handle switching TO ptypeRefl on HRRR ---
|
|
301
|
+
if (variable === 'ptypeRefl' && this.state.model === 'hrrr' && this.state.forecastHour === 0) {
|
|
302
|
+
var _this$modelStatus4;
|
|
303
|
+
const availableHours = ((_this$modelStatus4 = this.modelStatus) === null || _this$modelStatus4 === void 0 || (_this$modelStatus4 = _this$modelStatus4[this.state.model]) === null || _this$modelStatus4 === void 0 || (_this$modelStatus4 = _this$modelStatus4[this.state.date]) === null || _this$modelStatus4 === void 0 ? void 0 : _this$modelStatus4[this.state.run]) || [];
|
|
304
|
+
const firstValidHour = availableHours.find(hour => hour !== 0) || 0;
|
|
305
|
+
await this.setState({
|
|
306
|
+
variable,
|
|
307
|
+
forecastHour: firstValidHour
|
|
308
|
+
});
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
// --- END NEW CODE ---
|
|
312
|
+
|
|
267
313
|
await this.setState({
|
|
268
314
|
variable
|
|
269
315
|
});
|
|
270
316
|
}
|
|
271
317
|
async setModel(modelName) {
|
|
272
|
-
var _this$
|
|
273
|
-
if (modelName === this.state.model || !((_this$
|
|
318
|
+
var _this$modelStatus5;
|
|
319
|
+
if (modelName === this.state.model || !((_this$modelStatus5 = this.modelStatus) !== null && _this$modelStatus5 !== void 0 && _this$modelStatus5[modelName])) return;
|
|
274
320
|
const latestRun = findLatestModelRun(this.modelStatus, modelName);
|
|
275
321
|
if (latestRun) {
|
|
322
|
+
// --- NEW CODE: Determine initial forecast hour ---
|
|
323
|
+
let initialHour = 0;
|
|
324
|
+
|
|
325
|
+
// If switching to HRRR with ptypeRefl, start at hour 1 instead of 0
|
|
326
|
+
if (modelName === 'hrrr' && this.state.variable === 'ptypeRefl') {
|
|
327
|
+
var _this$modelStatus6;
|
|
328
|
+
const availableHours = ((_this$modelStatus6 = this.modelStatus) === null || _this$modelStatus6 === void 0 || (_this$modelStatus6 = _this$modelStatus6[modelName]) === null || _this$modelStatus6 === void 0 || (_this$modelStatus6 = _this$modelStatus6[latestRun.date]) === null || _this$modelStatus6 === void 0 ? void 0 : _this$modelStatus6[latestRun.run]) || [];
|
|
329
|
+
// Find the first valid hour (should be 1)
|
|
330
|
+
initialHour = availableHours.find(hour => hour !== 0) || 0;
|
|
331
|
+
}
|
|
332
|
+
// --- END NEW CODE ---
|
|
333
|
+
|
|
276
334
|
await this.setState({
|
|
277
335
|
model: modelName,
|
|
278
336
|
date: latestRun.date,
|
|
279
337
|
run: latestRun.run,
|
|
280
|
-
forecastHour: 0
|
|
338
|
+
forecastHour: initialHour // <-- Changed from hardcoded 0
|
|
281
339
|
});
|
|
282
340
|
}
|
|
283
341
|
}
|
|
@@ -350,13 +408,26 @@ class AguaceroCore extends _events.EventEmitter {
|
|
|
350
408
|
console.error(`Could not find a valid run for model: ${model}`);
|
|
351
409
|
return;
|
|
352
410
|
}
|
|
411
|
+
|
|
412
|
+
// --- NEW CODE: Determine initial forecast hour for switchMode ---
|
|
413
|
+
let initialHour = forecastHour !== undefined ? forecastHour : 0;
|
|
414
|
+
|
|
415
|
+
// If switching to HRRR with ptypeRefl and hour is 0, use hour 1
|
|
416
|
+
if (model === 'hrrr' && variable === 'ptypeRefl' && initialHour === 0) {
|
|
417
|
+
var _this$modelStatus7;
|
|
418
|
+
const availableHours = ((_this$modelStatus7 = this.modelStatus) === null || _this$modelStatus7 === void 0 || (_this$modelStatus7 = _this$modelStatus7[model]) === null || _this$modelStatus7 === void 0 || (_this$modelStatus7 = _this$modelStatus7[latestRun.date]) === null || _this$modelStatus7 === void 0 ? void 0 : _this$modelStatus7[latestRun.run]) || [];
|
|
419
|
+
initialHour = availableHours.find(hour => hour !== 0) || 0;
|
|
420
|
+
}
|
|
421
|
+
// --- END NEW CODE ---
|
|
422
|
+
|
|
353
423
|
targetState = {
|
|
354
424
|
isMRMS: false,
|
|
355
425
|
model: model,
|
|
356
426
|
variable: variable,
|
|
357
427
|
date: latestRun.date,
|
|
358
428
|
run: latestRun.run,
|
|
359
|
-
forecastHour:
|
|
429
|
+
forecastHour: initialHour,
|
|
430
|
+
// <-- Changed
|
|
360
431
|
mrmsTimestamp: null
|
|
361
432
|
};
|
|
362
433
|
} else {
|
|
@@ -580,31 +651,6 @@ class AguaceroCore extends _events.EventEmitter {
|
|
|
580
651
|
const displayUnit = this._getTargetUnit(dataNativeUnit, units);
|
|
581
652
|
const conversionFunc = (0, _unitConversions.getUnitConversionFunction)(dataNativeUnit, displayUnit);
|
|
582
653
|
let displayValue = conversionFunc ? conversionFunc(nativeValue) : nativeValue;
|
|
583
|
-
|
|
584
|
-
// --- START: ADDED CODE ---
|
|
585
|
-
|
|
586
|
-
// Create a variable to hold the precipitation type, if any.
|
|
587
|
-
let precipType = null;
|
|
588
|
-
|
|
589
|
-
// Check if the current variable is one of the special ptype variables.
|
|
590
|
-
if (variable === 'ptypeRefl' || variable === 'ptypeRate') {
|
|
591
|
-
const value = nativeValue; // Use the raw, unconverted value for ptype logic
|
|
592
|
-
|
|
593
|
-
if (value >= 100 && value < 200) {
|
|
594
|
-
displayValue -= 100;
|
|
595
|
-
precipType = 'Snow';
|
|
596
|
-
} else if (value >= 200 && value < 300) {
|
|
597
|
-
displayValue -= 200;
|
|
598
|
-
precipType = 'Frzg Rain'; // Abbreviated for tooltips
|
|
599
|
-
} else if (value >= 300 && value < 400) {
|
|
600
|
-
displayValue -= 300;
|
|
601
|
-
precipType = 'Ice Pellets';
|
|
602
|
-
} else {
|
|
603
|
-
precipType = 'Rain';
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
// Return the final payload, now including the precipType.
|
|
608
654
|
return {
|
|
609
655
|
lngLat: {
|
|
610
656
|
lng,
|
|
@@ -615,8 +661,7 @@ class AguaceroCore extends _events.EventEmitter {
|
|
|
615
661
|
name: this.getVariableDisplayName(variable)
|
|
616
662
|
},
|
|
617
663
|
value: displayValue,
|
|
618
|
-
unit: displayUnit
|
|
619
|
-
precipType: precipType // NEW: Add this to the return object
|
|
664
|
+
unit: displayUnit
|
|
620
665
|
};
|
|
621
666
|
} catch (error) {
|
|
622
667
|
return null;
|