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 | |
|---|---|---|---|
|
|
2b6e0ba3fd | ||
|
|
347c530edd | ||
|
|
a6f27875e9 | ||
|
|
1ef5053ca0 | ||
|
|
ea4cb9de74 | ||
|
|
e3c882a57c | ||
|
|
aa4b02236a |
No files matched your search
@@ -1 +1,2 @@
|
||||
node_modules
|
||||
*.cpuprofile
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"words": [
|
||||
"nexrad",
|
||||
"KSRX",
|
||||
"TORD",
|
||||
"palettizing",
|
||||
"tdwr"
|
||||
]
|
||||
}
|
||||
@@ -16,10 +16,10 @@ const { plot, writeToPngFile } = require('nexrad-level-3-plot');
|
||||
// read a file
|
||||
const file = fs.readFileSync('<path to data>');
|
||||
// parse and plot
|
||||
const level2Plot = plot(file, {elevation: 1, product: 'REF'});
|
||||
const level2Plot = plot(file, 'REF', {elevations: 1});
|
||||
// use bundled utility to write to disk
|
||||
(async () => {
|
||||
await writePngToFile('<path to output>.png', level2Plot.REF.canvas);
|
||||
await writePngToFile('<path to output>.png', level2Plot[0].REF);
|
||||
})();
|
||||
```
|
||||
# Data
|
||||
@@ -56,7 +56,7 @@ Returns an array of objects. The order of elevations in the returned array match
|
||||
canvas: <Canvas>,
|
||||
palette: <Uint8ClampedArray>
|
||||
},
|
||||
//... additional products
|
||||
// ... additional products
|
||||
},
|
||||
// ... additional elevations
|
||||
]
|
||||
@@ -79,6 +79,9 @@ options.lineWidth|integer|2|The raster image is created by drawing several arcs
|
||||
options.palettize|boolean\|object|false|After drawing the image convert the image from RGBA to a palettized image. When true the same palette as the product is used. Additional options are described in [palettizing](#palettizing). This can significantly reduce the size of the resulting image with minimal loss of clarity.
|
||||
options.elevations|undefined\|integer\|Array of integers|undefined|The specific elevations to plot. If undefined (default) all available elevations will be plotted. If an integer is provided a single elevation will be plotted with all the selected ```products```. If an array of integers are provided each ```products``` in each elevation will be plotted. Note that when a product and elevation combination do not exist the returned object will have false in the missing location. This is common where elevation 1 will have reflectivity data and elevation 2 (altough at the same angle as elevation 1) will contain velocity data.
|
||||
options.usePreferredWaveforms|boolean|true|Waveform types of 1, 2, 3, 4 and 5 are produced by the radar. Type 1 is typically exclusive to reflectivity, Type 2 is typically exclusive to velocity however it also produces reflectivity data. Types 3, 4 and 5 all produce both velocity and reflectivity. When set to true type 1 waveforms will not plot velocity data, and type 2 waveforms will not plot reflectivity data. If you must see all information set this to false.
|
||||
options.alpha|boolean|true|Draw on a 32-bit canvas. Passed directly to getContext('2d', {alpha}).
|
||||
options.imageSmoothingEnabled|boolean|true|Enable image smoothing. Passed directly to ctx.imageSmoothingEnabled.
|
||||
options.antialias|string|'default'|Enable antialias. Passed directly to ctx.antialias (part of node-canvas)
|
||||
|
||||
### Downsampling
|
||||
A full size plot is 3600 x 3600 pixels. This corresponds to the maximum range of the radar 460km (~250 mi) * maximum resolution 0.25 mi/bin * 2 (east and west side of radar).
|
||||
@@ -114,6 +117,9 @@ data|{canvas[palette]}|Typically the output of [plot()](#plotfile-options).\<pro
|
||||
|
||||
# Notable and breaking changes
|
||||
|
||||
## v2.6.0 Notable, Additional canvas configuration options
|
||||
The options antialias, imageSmoothingEnabled, and alpha were added and passed directly to the canvas context when creating it before plotting. Disabling these options (which were previously defaulted to on) can speed up plotting by about 5% and reduce output image size by up to 10% at a very slight cost of visual appearance.
|
||||
|
||||
## v2.5.0 Notable, 300km range now interperted correctly
|
||||
Prior to this version, if the data had the ```super_res_control.300km``` flag set the resulting image would effectively be "zoomed in by 2x". Upon examing the results of this flag on the plot, reference plots and the ```gate_count``` values it was determined no scaling needed to be performed if this flag was present. Instead, the ```gate_count``` already reflects the additional data the flag indicates. This mainly affects VEL plots and some REF plots at higher elevations, depending on the VCP the radar is using.
|
||||
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "nexrad-level-2-plot",
|
||||
"version": "2.5.0",
|
||||
"version": "2.6.1",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "nexrad-level-2-plot",
|
||||
"version": "2.5.0",
|
||||
"version": "2.6.1",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"canvas": "^2.9.1",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "nexrad-level-2-plot",
|
||||
"version": "2.5.0",
|
||||
"version": "2.6.1",
|
||||
"description": "Plotting library for nexrad-level-2-data",
|
||||
"main": "src/index.js",
|
||||
"scripts": {
|
||||
|
||||
+6
-6
@@ -51,6 +51,9 @@ const DEFAULT_OPTIONS = {
|
||||
background: 'black',
|
||||
lineWidth: 2,
|
||||
usePreferredWaveforms: true,
|
||||
alpha: true,
|
||||
imageSmoothingEnabled: true,
|
||||
antialias: 'default',
|
||||
};
|
||||
|
||||
const draw = (data, _options) => {
|
||||
@@ -80,17 +83,14 @@ const draw = (data, _options) => {
|
||||
const gateSizeScaling = 0.25 / realGateSize;
|
||||
|
||||
// calculate crop, adjust if necessary
|
||||
console.log('');
|
||||
console.log(`ELEVATION: ${options.product} ${options.elevation}`);
|
||||
console.log(`Gate size: ${data?.data?.[options.elevation]?.[0]?.record?.reflect?.gate_size}`);
|
||||
console.log('Super Res:', data?.vcp?.record?.elevations?.[options.elevation]?.super_res_control?.super_res);
|
||||
console.log(`Gate count: ${data?.data?.[options.elevation]?.[0]?.record?.reflect.gate_count}`);
|
||||
const cropTo = Math.min(options.size, options.cropTo);
|
||||
if (options.cropTo < 1) throw new Error('Provide options.cropTo > 0');
|
||||
|
||||
// create the canvas and context
|
||||
const canvas = createCanvas(cropTo, cropTo);
|
||||
const ctx = canvas.getContext('2d');
|
||||
const ctx = canvas.getContext('2d', { alpha: options.alpha });
|
||||
ctx.antialias = options.antialias;
|
||||
ctx.imageSmoothingEnabled = options.imageSmoothingEnabled;
|
||||
|
||||
// fill background with black
|
||||
ctx.fillStyle = options.background;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,9 @@ const { writePngToFile } = require('./utils/file');
|
||||
* @param {(boolean|object)} [options.palettize] After drawing the image convert the image from RGBA to a palettized image. When true the same palette as the product is used.
|
||||
* @param {(undefined|number|number[])} [options.elevations=undefined] List of elevations to plot.
|
||||
* @param {boolean} [options.usePreferredWaveforms = true] Limit the plotted data to the preferred use of waveforms 1 and 2.
|
||||
* @param {boolean} [options.alpha = true] Draw on a 32-bit canvas. Passed directly to getContext('2d', {alpha}).
|
||||
* @param {boolean} [options.imageSmoothingEnabled = true] Control image smoothing. Passed directly to ctx.imageSmoothingEnabled.
|
||||
* @param {string} [options.antialias = 'default'] Control antialias. Passed directly to ctx.antialias (part of node-canvas)
|
||||
* @returns Canvas
|
||||
*/
|
||||
const plot = (data, _products, options) => {
|
||||
|
||||
Reference in new issue
Block a user