mirror of
https://github.com/netbymatt/nexrad-level-2-plot.git
synced 2026-11-28 18:28:05 -08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5767f2a10e | ||
|
|
a718f5c3e3 | ||
|
|
20c4552d0a | ||
|
|
d108e96cea | ||
|
|
ba885085d2 | ||
|
|
2b6e0ba3fd | ||
|
|
347c530edd |
No files matched your search
@@ -1 +1,2 @@
|
||||
node_modules
|
||||
*.cpuprofile
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"words": [
|
||||
"nexrad",
|
||||
"KSRX",
|
||||
"TORD",
|
||||
"palettizing",
|
||||
"tdwr"
|
||||
]
|
||||
}
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
> A javascript implementation for plotting Nexrad Level II data parsed via [nexrad-level-2-data](https://github.com/netbymatt/nexrad-level-2-data/).
|
||||
|
||||
# Demo
|
||||
A live demo showing the output of this library (via [nexrad-level-2-data](https://www.github.com/netbymatt/nexrad-level-2-data)) for select radar sites is available at https://nexrad-demo.netbymatt.com/
|
||||
|
||||
# Use
|
||||
## Install
|
||||
```bash
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+4
-1
@@ -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
|
||||
|
||||
+3
-3
@@ -10,9 +10,9 @@ const { plot, writePngToFile } = require('../src');
|
||||
// const files = glob.sync('./data/KLOT/381/*');
|
||||
// const files = glob.sync('./data/KLOT/548/*');
|
||||
// const files = glob.sync('./data/KLOT/940/*');
|
||||
// const files = glob.sync('./data/KSRX/804/*');
|
||||
// const files = glob.sync('./data/TORD/767/*');
|
||||
const files = glob.sync('./data/KLOT/KLOT20210812_171451_V*'); // ref palette tuning
|
||||
const files = glob.sync('./data/KSRX/804/*');
|
||||
// const files = glob.sync('./data/TORD/168/*');
|
||||
// const files = glob.sync('./data/KLOT/KLOT20210812_171451_V*'); // ref palette tuning
|
||||
// const files = glob.sync('./data/KLOT/KLOT20210621_041151_V06'); // vel palette tuning
|
||||
|
||||
// const store each file's data
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "nexrad-level-2-plot",
|
||||
"version": "2.6.0",
|
||||
"version": "2.6.3",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "nexrad-level-2-plot",
|
||||
"version": "2.6.0",
|
||||
"version": "2.6.3",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"canvas": "^2.9.1",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "nexrad-level-2-plot",
|
||||
"version": "2.6.0",
|
||||
"version": "2.6.3",
|
||||
"description": "Plotting library for nexrad-level-2-data",
|
||||
"main": "src/index.js",
|
||||
"scripts": {
|
||||
|
||||
+16
-17
@@ -76,11 +76,10 @@ const draw = (data, _options) => {
|
||||
if (options.size < 1) throw new Error('Provide options.size > 0');
|
||||
const scale = DEFAULT_OPTIONS.size / options.size;
|
||||
|
||||
// wsr88d uses a gate size of 0.25km, tdwr uses a gate size of 0.15km, although it is reported as 0.3km for processing reasons
|
||||
// wsr88d uses a gate size of 0.25km, tdwr uses a gate size of 0.15km or 0.30km
|
||||
// this calculation scales the plot accordingly to the nominal 0.25km so all generated plots are at the same scale
|
||||
const rawGateSize = data?.data?.[options.elevation]?.[0]?.record?.reflect?.gate_size ?? 0.25;
|
||||
const realGateSize = rawGateSize !== 0.3 ? rawGateSize : rawGateSize / 2;
|
||||
const gateSizeScaling = 0.25 / realGateSize;
|
||||
const gateSizeScaling = rawGateSize / 0.25;
|
||||
|
||||
// calculate crop, adjust if necessary
|
||||
const cropTo = Math.min(options.size, options.cropTo);
|
||||
@@ -146,20 +145,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 +170,7 @@ const draw = (data, _options) => {
|
||||
}
|
||||
|
||||
// palettize image
|
||||
const palettized = palettizeImage(canvas.getContext('2d'), palette);
|
||||
const palettized = palettizeImage(ctx, palette);
|
||||
|
||||
// return palettized image
|
||||
return {
|
||||
|
||||
@@ -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'];
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user