list radar timestamps

This commit is contained in:
Matt Walsh 2020-12-29 10:22:20 -06:00
parent 887e0aa676
commit a9d0968e28
3 changed files with 79 additions and 48 deletions

View file

@ -20,13 +20,9 @@ module.exports = {
'tab', 'tab',
], ],
'no-tabs': 0, 'no-tabs': 0,
'no-use-before-define': 0,
'no-console': 0, 'no-console': 0,
'linebreak-style': [
'error',
'unix',
],
'max-len': 0, 'max-len': 0,
'linebreak-style': 0,
quotes: [ quotes: [
'error', 'error',
'single', 'single',
@ -47,6 +43,18 @@ module.exports = {
'no-floating-decimal': ['error'], 'no-floating-decimal': ['error'],
'no-trailing-spaces': ['error'], 'no-trailing-spaces': ['error'],
'brace-style': [2, '1tbs', { allowSingleLine: true }], 'brace-style': [2, '1tbs', { allowSingleLine: true }],
'no-mixed-operators': [
'error',
{
groups: [
['&', '|', '^', '~', '<<', '>>', '>>>'],
['==', '!=', '===', '!==', '>', '>=', '<', '<='],
['&&', '||'],
['in', 'instanceof'],
],
allowSamePrecedence: true,
},
],
}, },
ignorePatterns: [ ignorePatterns: [
'*.min.js', '*.min.js',

View file

@ -36,12 +36,12 @@ class Radar extends WeatherDisplay {
this.backgroundImage = utils.image.load('images/BackGround4_1.png'); this.backgroundImage = utils.image.load('images/BackGround4_1.png');
} }
async getData(_weatherParameters) { async getData(weatherParameters) {
super.getData(_weatherParameters); super.getData(weatherParameters);
const weatherParameters = _weatherParameters ?? this.weatherParameters; if (!weatherParameters) weatherParameters = this.weatherParameters;
// ALASKA ISN'T SUPPORTED! // ALASKA AND HAWAII AREN'T SUPPORTED!
if (weatherParameters.state === 'AK') { if (weatherParameters.state === 'AK' || weatherParameters.state === 'HI') {
this.setStatus(STATUS.noData); this.setStatus(STATUS.noData);
return; return;
} }
@ -51,30 +51,50 @@ class Radar extends WeatherDisplay {
// get the base map // get the base map
let src = 'images/4000RadarMap2.jpg'; let src = 'images/4000RadarMap2.jpg';
if (weatherParameters.state === 'HI') src = 'images/HawaiiRadarMap2.png'; if (weatherParameters.State === 'HI') src = 'images/HawaiiRadarMap2.png';
this.baseMap = await utils.image.load(src); this.baseMap = await utils.image.load(src);
const baseUrl = 'https://radar.weather.gov/Conus/RadarImg/'; const baseUrl = 'https://mesonet.agron.iastate.edu/archive/data/';
const baseUrlEnd = '/GIS/uscomp';
const baseUrls = [];
let date = DateTime.utc().minus({ days: 1 }).startOf('day');
let radarHtml; // make urls for yesterday, today and tomorrow
try { while (date <= DateTime.utc().plus({ days: 1 }).startOf('day')) {
// get a list of available radars baseUrls.push(`${baseUrl}${date.toFormat('yyyy/LL/dd')}${baseUrlEnd}`);
radarHtml = await utils.fetch.text(baseUrl, { cors: true }); date = date.plus({ days: 1 });
} catch (e) {
console.error('Unable to get list of radars');
console.error(e);
this.setStatus(STATUS.failed);
return;
} }
const lists = (await Promise.all(baseUrls.map(async (url) => {
try {
// get a list of available radars
const radarHtml = await utils.fetch.text(url, { cors: true });
return radarHtml;
} catch (e) {
console.log('Unable to get list of radars');
console.error(e);
this.setStatus(STATUS.failed);
return false;
}
}))).filter((d) => d);
// convert to an array of gif urls // convert to an array of gif urls
const parser = new DOMParser(); const pngs = lists.map((html, htmlIdx) => {
const xmlDoc = parser.parseFromString(radarHtml, 'text/html'); const parser = new DOMParser();
const anchors = xmlDoc.getElementsByTagName('a'); const xmlDoc = parser.parseFromString(html, 'text/html');
const gifs = []; // add the base url
Object.values(anchors).forEach((a) => { const base = xmlDoc.createElement('base');
gifs.push(a.innerHTML); base.href = baseUrls[htmlIdx];
}); xmlDoc.head.append(base);
const anchors = xmlDoc.getElementsByTagName('a');
const gifs = [];
for (const idx in anchors) {
if (anchors[idx].innerHTML?.includes('png') && anchors[idx].innerHTML?.includes('n0r_')) {
gifs.push(anchors[idx].href);
}
}
return gifs;
}).flat();
// filter for selected urls // filter for selected urls
let filter = /Conus_\d/; let filter = /Conus_\d/;
@ -94,16 +114,16 @@ class Radar extends WeatherDisplay {
let sourceXY; let sourceXY;
let width; let width;
let height; let height;
if (weatherParameters.state === 'HI') { if (weatherParameters.State === 'HI') {
width = 600; width = 600;
height = 571; height = 571;
sourceXY = Radar.getXYFromLatitudeLongitudeHI(weatherParameters.latitude, weatherParameters.longitude, offsetX, offsetY); sourceXY = this.getXYFromLatitudeLongitudeHI(weatherParameters.latitude, weatherParameters.longitude, offsetX, offsetY);
} else { } else {
width = 2550; width = 2550;
height = 1600; height = 1600;
offsetX *= 2; offsetX *= 2;
offsetY *= 2; offsetY *= 2;
sourceXY = Radar.getXYFromLatitudeLongitudeDoppler(weatherParameters.latitude, weatherParameters.longitude, offsetX, offsetY); sourceXY = this.getXYFromLatitudeLongitudeDoppler(weatherParameters.latitude, weatherParameters.longitude, offsetX, offsetY);
} }
// create working context for manipulation // create working context for manipulation
@ -116,11 +136,11 @@ class Radar extends WeatherDisplay {
// calculate radar offsets // calculate radar offsets
let radarOffsetX = 117; let radarOffsetX = 117;
let radarOffsetY = 60; let radarOffsetY = 60;
let radarSourceXY = Radar.getXYFromLatitudeLongitudeDoppler(weatherParameters.latitude, weatherParameters.longitude, offsetX, offsetY); let radarSourceXY = this.getXYFromLatitudeLongitudeDoppler(weatherParameters.latitude, weatherParameters.longitude, offsetX, offsetY);
let radarSourceX = radarSourceXY.x / 2; let radarSourceX = radarSourceXY.x / 2;
let radarSourceY = radarSourceXY.y / 2; let radarSourceY = radarSourceXY.y / 2;
if (weatherParameters.state === 'HI') { if (weatherParameters.State === 'HI') {
radarOffsetX = 120; radarOffsetX = 120;
radarOffsetY = 69; radarOffsetY = 69;
radarSourceXY = this.getXYFromLatitudeLongitudeHI(weatherParameters.latitude, weatherParameters.longitude, offsetX, offsetY); radarSourceXY = this.getXYFromLatitudeLongitudeHI(weatherParameters.latitude, weatherParameters.longitude, offsetX, offsetY);
@ -167,7 +187,7 @@ class Radar extends WeatherDisplay {
const imgBlob = await utils.image.load(blob); const imgBlob = await utils.image.load(blob);
// draw the entire image // draw the entire image
if (weatherParameters.state === 'HI') { if (weatherParameters.State === 'HI') {
workingContext.clearRect(0, 0, 571, 600); workingContext.clearRect(0, 0, 571, 600);
workingContext.drawImage(imgBlob, 0, 0, 571, 600); workingContext.drawImage(imgBlob, 0, 0, 571, 600);
} else { } else {
@ -186,10 +206,10 @@ class Radar extends WeatherDisplay {
cropContext.imageSmoothingEnabled = false; cropContext.imageSmoothingEnabled = false;
cropContext.drawImage(workingCanvas, radarSourceX, radarSourceY, (radarOffsetX * 2), (radarOffsetY * 2.33), 0, 0, 640, 367); cropContext.drawImage(workingCanvas, radarSourceX, radarSourceY, (radarOffsetX * 2), (radarOffsetY * 2.33), 0, 0, 640, 367);
// clean the image // clean the image
Radar.removeDopplerRadarImageNoise(cropContext); this.removeDopplerRadarImageNoise(cropContext);
// merge the radar and map // merge the radar and map
Radar.mergeDopplerRadarImage(context, cropContext); this.mergeDopplerRadarImage(context, cropContext);
return { return {
canvas, canvas,
@ -292,26 +312,30 @@ class Radar extends WeatherDisplay {
return { x, y }; return { x, y };
} }
static getXYFromLatitudeLongitudeDoppler(Latitude, Longitude, OffsetX, OffsetY) { static GetXYFromLatitudeLongitudeDoppler(pos, offsetX, offsetY) {
let y = 0; let y = 0;
let x = 0; let x = 0;
const ImgHeight = 3200; const imgHeight = 6000;
const ImgWidth = 5100; const imgWidth = 2800;
y = (51 - pos.latitude) * 61.4481;
// center map
y -= offsetY;
y = (51.75 - Latitude) * 55.2;
y -= OffsetY; // Centers map.
// Do not allow the map to exceed the max/min coordinates. // Do not allow the map to exceed the max/min coordinates.
if (y > (ImgHeight - (OffsetY * 2))) { if (y > (imgHeight - (offsetY * 2))) {
y = ImgHeight - (OffsetY * 2); y = imgHeight - (offsetY * 2);
} else if (y < 0) { } else if (y < 0) {
y = 0; y = 0;
} }
x = ((-130.37 - Longitude) * 41.775) * -1; x = ((-129.138 - pos.longitude) * 42.1768) * -1;
x -= OffsetX; // Centers map. // center map
x -= offsetX;
// Do not allow the map to exceed the max/min coordinates. // Do not allow the map to exceed the max/min coordinates.
if (x > (ImgWidth - (OffsetX * 2))) { if (x > (imgWidth - (offsetX * 2))) {
x = ImgWidth - (OffsetX * 2); x = imgWidth - (offsetX * 2);
} else if (x < 0) { } else if (x < 0) {
x = 0; x = 0;
} }

View file

@ -234,7 +234,6 @@ const utils = (() => {
const rewriteUrl = (_url) => { const rewriteUrl = (_url) => {
let url = _url; let url = _url;
url = url.replace('https://api.weather.gov/', window.location.href); url = url.replace('https://api.weather.gov/', window.location.href);
url = url.replace('https://radar.weather.gov/', window.location.href);
url = url.replace('https://www.cpc.ncep.noaa.gov/', window.location.href); url = url.replace('https://www.cpc.ncep.noaa.gov/', window.location.href);
return url; return url;
}; };