Compare commits

..
4 Commits
Author SHA1 Message Date
Matt Walsh d108e96cea 2.6.2 2022-07-13 15:52:52 -05:00
Matt Walsh ba885085d2 minor performance optimization 2022-07-13 15:52:44 -05:00
Matt Walsh 2b6e0ba3fd 2.6.1 2022-07-13 12:01:03 -05:00
Matt Walsh 347c530edd improve hex lookup during paletizing 2022-07-13 12:00:55 -05:00
9 changed files with 44 additions and 27 deletions

No files matched your search

+1
View File
@@ -1 +1,2 @@
node_modules
*.cpuprofile
+9
View File
@@ -0,0 +1,9 @@
{
"words": [
"nexrad",
"KSRX",
"TORD",
"palettizing",
"tdwr"
]
}
+4 -1
View File
@@ -22,7 +22,7 @@ files.forEach((file) => {
const radarData = Level2Radar.combineData(chunks);
const size = 1800;
const iterations = 10;
const iterations = 5;
// plot for each elevation and size
(async () => {
@@ -32,6 +32,9 @@ const iterations = 10;
size,
palettize: true,
cropTo: size / 2,
alpha: false,
imageSmoothingEnabled: false,
antialias: 'none',
});
// write files to disk
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "nexrad-level-2-plot",
"version": "2.6.0",
"version": "2.6.2",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "nexrad-level-2-plot",
"version": "2.6.0",
"version": "2.6.2",
"license": "MIT",
"dependencies": {
"canvas": "^2.9.1",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "nexrad-level-2-plot",
"version": "2.6.0",
"version": "2.6.2",
"description": "Plotting library for nexrad-level-2-data",
"main": "src/index.js",
"scripts": {
+14 -14
View File
@@ -146,20 +146,20 @@ const draw = (data, _options) => {
// plot each bin
radial.moment_data.forEach((bin, idx) => {
if (bin !== null) {
ctx.beginPath();
// different methods for rrle encoded or not
if (bin.count) {
// rrle encoded
ctx.strokeStyle = palette.lookupRgba[bin.value];
ctx.arc(0, 0, (idx + deadZone) * gateSizeScaling, startAngle, endAngle + resolution * (bin.count - 1));
} else {
// plain data
ctx.strokeStyle = palette.lookupRgba[bin];
ctx.arc(0, 0, (idx + deadZone) * gateSizeScaling, startAngle, endAngle);
}
ctx.stroke();
if (bin === null) return;
ctx.beginPath();
// different methods for rrle encoded or not
if (bin.count) {
// rrle encoded
ctx.strokeStyle = palette.lookupRgba[bin.value];
ctx.arc(0, 0, (idx + deadZone) * gateSizeScaling, startAngle, endAngle + resolution * (bin.count - 1));
} else {
// plain data
ctx.strokeStyle = palette.lookupRgba[bin];
ctx.arc(0, 0, (idx + deadZone) * gateSizeScaling, startAngle, endAngle);
}
ctx.stroke();
});
});
@@ -171,7 +171,7 @@ const draw = (data, _options) => {
}
// palettize image
const palettized = palettizeImage(canvas.getContext('2d'), palette);
const palettized = palettizeImage(ctx, palette);
// return palettized image
return {
+1
View File
@@ -0,0 +1 @@
module.exports = ['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '0a', '0b', '0c', '0d', '0e', '0f', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '1a', '1b', '1c', '1d', '1e', '1f', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '2a', '2b', '2c', '2d', '2e', '2f', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '3a', '3b', '3c', '3d', '3e', '3f', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '4a', '4b', '4c', '4d', '4e', '4f', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '5a', '5b', '5c', '5d', '5e', '5f', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '6a', '6b', '6c', '6d', '6e', '6f', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '7a', '7b', '7c', '7d', '7e', '7f', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '8a', '8b', '8c', '8d', '8e', '8f', '90', '91', '92', '93', '94', '95', '96', '97', '98', '99', '9a', '9b', '9c', '9d', '9e', '9f', 'a0', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9', 'aa', 'ab', 'ac', 'ad', 'ae', 'af', 'b0', 'b1', 'b2', 'b3', 'b4', 'b5', 'b6', 'b7', 'b8', 'b9', 'ba', 'bb', 'bc', 'bd', 'be', 'bf', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'c7', 'c8', 'c9', 'ca', 'cb', 'cc', 'cd', 'ce', 'cf', 'd0', 'd1', 'd2', 'd3', 'd4', 'd5', 'd6', 'd7', 'd8', 'd9', 'da', 'db', 'dc', 'dd', 'de', 'df', 'e0', 'e1', 'e2', 'e3', 'e4', 'e5', 'e6', 'e7', 'e8', 'e9', 'ea', 'eb', 'ec', 'ed', 'ee', 'ef', 'f0', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'fa', 'fb', 'fc', 'fd', 'fe', 'ff'];
+5 -1
View File
@@ -4,6 +4,8 @@
// this ensures that the colors are not blended because the index should be returned in the a position
// after the entire image is drawn the index information must be shifted from g to a
const hexLookup = require('./hexlookup');
const rgbaLookupSize = 200;
class Palette {
@@ -59,7 +61,8 @@ class Palette {
// short circuit for transparent (black)
if (match[0] <= 2 && match[1] <= 2 && match[2] <= 2) return this.transparentIndex;
// short circuit previously calculated matches
const asHex = match[0].toString(16).padStart(2, '0') + match[1].toString(16).padStart(2, '0') + match[2].toString(16).padStart(2, '0');
const asHex = hexLookup[match[0]] + hexLookup[match[1]] + hexLookup[match[2]];
// const asHex = match[0].toString(16).padStart(2, '0') + match[1].toString(16).padStart(2, '0') + match[2].toString(16).padStart(2, '0');
if (this.closest[asHex]) return this.closest[asHex];
// initial conditions
let closestIndex = 0;
@@ -80,6 +83,7 @@ class Palette {
}
// geometric distance
// square root is intentionally not taken for performance reasons
static geometricDistance(a, b) {
return a.reduce((acc, val, idx) => acc + (val - b[idx]) ** 2, 0);
}
+7 -8
View File
@@ -4,8 +4,6 @@
const findTotalMatches = (radials, startI, binIdx, resolutionThreshold) => {
// get the target value
const target = radials[startI].moment_data[binIdx];
// check for null
if (target === null) return false;
// start a counter for matches
let count = 1;
@@ -23,7 +21,7 @@ const findTotalMatches = (radials, startI, binIdx, resolutionThreshold) => {
// end condition is the number of radials available
// a radial not within the resolution threshold
// or the binIdx under test not present in one of the next radials
while (nextI < radials.length && checkNext) {
while (checkNext && nextI < radials.length) {
// reset flag
checkNext = false;
const nextAzimuth = radials[nextI].azimuth;
@@ -60,13 +58,14 @@ const rrle = (radials, resolutionRad) => {
// look at each bin on the radial
radial.moment_data.forEach((bin, binIdx) => {
if (radials[i].moment_data[binIdx] === null) return;
const totalMatches = findTotalMatches(radials, i, binIdx, resolutionThreshold);
// if a total match was found update the bin data and null out the remaining bins in the run
if (totalMatches) {
radial.moment_data[binIdx] = { value: bin, count: totalMatches };
for (let clearI = i + 1; clearI <= i + totalMatches - 1; clearI += 1) {
sorted[clearI].moment_data[binIdx] = null;
}
if (!totalMatches) return;
radial.moment_data[binIdx] = { value: bin, count: totalMatches };
const loopEnd = i + totalMatches - 1;
for (let clearI = i + 1; clearI <= loopEnd; clearI += 1) {
sorted[clearI].moment_data[binIdx] = null;
}
});
}