diff --git a/.vscode/launch.json b/.vscode/launch.json index ec3b514..63f1e81 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -23,6 +23,15 @@ ], "program": "${workspaceFolder}/demos/80-ntp-storm-total-accumulation.js", }, + { + "type": "pwa-node", + "request": "launch", + "name": "170 DAA", + "skipFiles": [ + "/**" + ], + "program": "${workspaceFolder}/demos/170-dta-digital-one-hour", + }, { "type": "pwa-node", "request": "launch", diff --git a/demos/170-dta-digital-one-hour.js b/demos/170-dta-digital-one-hour.js new file mode 100644 index 0000000..edf7262 --- /dev/null +++ b/demos/170-dta-digital-one-hour.js @@ -0,0 +1,17 @@ +const fs = require('fs'); +const { plot } = require('../src'); +const { writePngToFile } = require('../src/utils/file'); + +// read file +const fileName = 'LOT_DAA_2021_02_28_12_14_47'; +const file = fs.readFileSync(`./demos/data/${fileName}`); + +// pass to plotting engine as a string or buffer +const level3Plot = plot(file); + +(async () => { + writePngToFile(`./demos/output/${fileName}.png`, level3Plot); +})(); + +console.log(level3Plot); +console.log(); diff --git a/demos/data/LOT_DAA_2021_02_28_12_14_47 b/demos/data/LOT_DAA_2021_02_28_12_14_47 new file mode 100644 index 0000000..0b8bee0 Binary files /dev/null and b/demos/data/LOT_DAA_2021_02_28_12_14_47 differ diff --git a/src/draw/index.js b/src/draw/index.js index 0c87ccb..03684c8 100644 --- a/src/draw/index.js +++ b/src/draw/index.js @@ -22,22 +22,20 @@ const draw = (data, product) => { ctx.translate(dim.x / 2, dim.y / 2); ctx.rotate(-Math.PI / 2); - // get scaling from product or use default - const scaling = { - scale: data?.productDescription?.plot?.scale ?? 1, - offset: data?.productDescription?.plot?.offset ?? 0, - }; - // generate a palette const palette = Palette.generate(product.palette); - + // calculate scaling paramater with respect to pallet's designed criteria + const paletteScale = (data?.productDescription?.plot?.maxDataValue ?? 255) / (product.palette.baseScale ?? data?.productDescription?.plot?.maxDataValue ?? 1); + // use the raw values to avoid scaling and un-scaling data.radialPackets[0].radials.forEach((radial) => { const startAngle = radial.startAngle * (Math.PI / 180); const endAngle = startAngle + radial.angleDelta * (Math.PI / 180); // for each bin radial.bins.forEach((bin, idx) => { + // skip null values + if (bin === null) return; ctx.beginPath(); - ctx.strokeStyle = palette[Math.round((bin - scaling.offset) / scaling.scale)]; + ctx.strokeStyle = palette[Math.round(bin * paletteScale)]; ctx.arc(0, 0, idx + data.radialPackets[0].firstBin, startAngle, endAngle); ctx.stroke(); }); diff --git a/src/nexrad-level-3-data b/src/nexrad-level-3-data index 321253c..e5d439c 160000 --- a/src/nexrad-level-3-data +++ b/src/nexrad-level-3-data @@ -1 +1 @@ -Subproject commit 321253cb6d77f29090f59d3a1266f2d8320271d7 +Subproject commit e5d439cf52f1c07393104068248c56d9c63eb9a3 diff --git a/src/products/170/index.js b/src/products/170/index.js new file mode 100644 index 0000000..70f2b29 --- /dev/null +++ b/src/products/170/index.js @@ -0,0 +1,20 @@ +const code = 170; +const abbreviation = 'DAA'; +const description = 'Digital One Hour Accumulation'; + +// same colors as 172 +const { colors } = require('../172').palette; + +const palette = { + colors, + thresholds: [1, 2, 4, 6, 9, 11, 21, 32, 43, 64, 58, 128, 170, 213, 255], + + baseScale: 6.0, +}; + +module.exports = { + code, + abbreviation, + description, + palette, +}; diff --git a/src/products/172/index.js b/src/products/172/index.js index 6c3a38f..2f49c96 100644 --- a/src/products/172/index.js +++ b/src/products/172/index.js @@ -26,6 +26,7 @@ const palette = { 255, 255, 255, ], thresholds: [8, 16, 24, 32, 40, 56, 72, 88, 104, 120, 136, 152, 168, 184, 200, 208, 216, 224, 232], + baseScale: 2.56, }; module.exports = {