Compare commits

..
53 Commits
Author SHA1 Message Date
Matt Walsh c9b7790eca 3.0.0 2026-08-12 21:20:24 -05:00
Matt Walsh 12031fb807 switch to for loops where high iteration counts occur 2026-08-12 00:40:29 -05:00
Matt Walsh d13142052e add bin batching to plot code 2026-08-12 00:36:03 -05:00
Matt Walsh ea23ea2e68 improve palletizing algorithm 2026-08-12 00:17:21 -05:00
Matt Walsh 53857aabd9 convert complete 2026-08-12 00:12:45 -05:00
Matt Walsh 7ea73c0cc6 eslint update 2026-08-11 23:30:18 -05:00
Matt Walsh 6ca3b0816f convert to esm 2025-05-14 13:46:01 -05:00
Matt Walsh 86c2f9e8ee 2.6.4 2024-05-30 11:33:53 -05:00
Matt Walsh f881493aa4 update and test for node 20 2024-05-30 11:33:49 -05:00
Matt Walsh 5767f2a10e 2.6.3 2023-01-16 12:36:21 -06:00
Matt Walsh a718f5c3e3 correct tdwr gate size scaling 2023-01-16 12:36:09 -06:00
Matt Walsh 20c4552d0a add demo to readme 2023-01-04 22:35:15 -06:00
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
Matt Walsh a6f27875e9 2.6.0 2022-07-13 10:34:43 -05:00
Matt Walsh 1ef5053ca0 add canvas options 2022-07-13 10:34:29 -05:00
Matt Walsh ea4cb9de74 update documentation close #3 2022-07-10 21:11:07 -05:00
Matt Walsh e3c882a57c 2.5.1 2022-06-21 11:17:10 -05:00
Matt Walsh aa4b02236a remove debug logging 2022-06-21 11:17:05 -05:00
Matt Walsh 847d4cbecc 2.5.0 2022-06-21 11:13:18 -05:00
Matt Walsh 7731d64af6 fix interpertation of 300km flag 2022-06-21 11:13:11 -05:00
Matt Walsh 96d3f36545 2.4.0 2022-06-01 13:01:32 -05:00
Matt Walsh 6a7f0868a5 handle gate sizing properly for tdwr 2022-06-01 13:01:16 -05:00
Matt Walsh bed3043ccd 2.3.0 2022-05-25 23:52:30 -05:00
Matt Walsh 676c63dc1c handle super-res long range scaling properly 2022-05-25 23:51:53 -05:00
Matt Walsh e559ba1d9c better benchmark statistics 2022-05-13 10:28:26 -05:00
Matt Walsh febb902f15 2.2.1 2022-05-12 22:02:18 -05:00
Matt Walsh aa307c44c0 update nexrad-level-2-data version 2022-05-12 22:01:57 -05:00
Matt Walsh a9fd62a513 update dependencies 2022-05-12 16:02:22 -05:00
Matt Walsh c12f6bbb95 update dependencies 2022-03-30 16:16:09 -05:00
Matt Walsh 28cfd34bcd 2.2.0 2022-03-18 15:57:32 -05:00
Matt Walsh a3987914bc update nexrad-level-2-data dependency 2022-03-18 15:56:38 -05:00
Matt Walsh 2b8fbbc3b5 2.1.1 2022-03-11 13:31:01 -06:00
Matt Walsh cab1556cc4 disable preferred products for chunk mode 2022-03-11 13:30:51 -06:00
Matt Walsh 2017a6f4ff fix benchmark code 2022-03-11 09:53:14 -06:00
Matt Walsh b8389de11f 2.1.0 2022-03-11 09:13:12 -06:00
Matt Walsh dc02fe5f50 add preferred waveforms 2022-03-11 09:13:05 -06:00
Matt Walsh e9fde8161f 2.0.0 2022-03-10 23:56:32 -06:00
Matt Walsh 90025427c6 plot all elevations 2022-03-10 23:56:24 -06:00
Matt Walsh 8cea4fb15d 1.1.2 2022-01-30 16:55:57 -06:00
Matt Walsh 9b4295e872 correct nexrad-level-2-data dependency 2022-01-30 16:55:48 -06:00
Matt Walsh 483f73547b 1.1.1 2022-01-26 16:23:47 -06:00
Matt Walsh 68ab79161b remove internal console.log 2022-01-26 16:23:39 -06:00
Matt Walsh 0a781e961b 1.1.0 2021-11-04 16:05:41 -05:00
Matt Walsh 95434ea5c4 Merge branch 'indexed-colors' 2021-11-04 16:05:29 -05:00
Matt Walsh 428978c55a update readme 2021-11-04 16:04:16 -05:00
Matt Walsh 3a6fbeee3b add benchmarking 2021-11-04 14:23:30 -05:00
Matt Walsh 010642db5e rrle completed 2021-11-04 14:14:43 -05:00
Matt Walsh c9092cd8dd correct scaling 2021-11-04 12:06:33 -05:00
Matt Walsh 637064b19d restore output gitignore 2021-11-04 11:18:30 -05:00
Matt Walsh a4724e641e extract pre processing 2021-11-04 11:16:48 -05:00
118 changed files with 7008 additions and 6583 deletions

No files matched your search

-103
View File
@@ -1,103 +0,0 @@
module.exports = {
root: true,
env: {
commonjs: true,
node: true,
},
extends: [
'airbnb-base',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
},
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2020,
},
plugins: ['import'],
settings: {
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],
},
'import/resolver': {
typescript: {
alwaysTryTypes: true,
},
},
},
rules: {
indent: [
'error',
'tab',
],
'no-use-before-define': [
'error',
{
variables: false,
},
],
// 'no-param-reassign': [
// 'error',
// {
// props: false,
// },
// ],
'no-tabs': 0,
'no-console': 0,
'max-len': 0,
'linebreak-style': 0,
quotes: [
'error',
'single',
],
// semi: [
// 'error',
// 'always',
// ],
// 'no-prototype-builtins': 0,
// 'comma-dangle': ['error', 'always-multiline'],
// 'block-scoped-var': ['error'],
// 'default-case': ['error'],
// 'default-param-last': ['error'],
// 'dot-location': ['error', 'property'],
// eqeqeq: ['error'],
// 'no-eval': ['error'],
// 'no-eq-null': ['error'],
// 'no-floating-decimal': ['error'],
// 'no-trailing-spaces': ['error'],
// 'brace-style': [2, '1tbs', { allowSingleLine: true }],
// 'no-mixed-operators': [
// 'error',
// {
// groups: [
// ['&', '|', '^', '~', '<<', '>>', '>>>'],
// ['==', '!=', '===', '!==', '>', '>=', '<', '<='],
// ['&&', '||'],
// ['in', 'instanceof'],
// ],
// allowSamePrecedence: true,
// },
// ],
// 'no-underscore-dangle': ['error', {
// allowAfterThis: true,
// }],
// 'no-bitwise': 0,
'import/extensions': [
'error',
'ignorePackages',
{
ts: 'never',
js: 'never',
},
],
// the following are handled by the typescript parser
'lines-between-class-members': 'off',
},
ignorePatterns: [
'*.min.js',
'dist/**',
],
};
+1
View File
@@ -1 +1,2 @@
node_modules
*.cpuprofile
+9
View File
@@ -0,0 +1,9 @@
{
"words": [
"nexrad",
"KSRX",
"TORD",
"palettizing",
"tdwr"
]
}
+5 -18
View File
@@ -5,35 +5,22 @@
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"type": "node",
"request": "launch",
"name": "Test",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/dist/demos/test.js",
"preLaunchTask": "tsc: build - tsconfig.json",
"outFiles": [
"${workspaceFolder}/dist/**/*.js",
"!**/node_modules/**"
],
"internalConsoleOptions": "openOnSessionStart",
"program": "${workspaceFolder}/demos/test.mjs"
},
{
"type": "pwa-node",
"type": "node",
"request": "launch",
"name": "Test Single",
"name": "Benchmark",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/dist/demos/test.js",
"preLaunchTask": "tsc: build - tsconfig.json",
"args": ["single"],
"outFiles": [
"${workspaceFolder}/dist/**/*.js",
"!**/node_modules/**"
],
"internalConsoleOptions": "openOnSessionStart"
"program": "${workspaceFolder}/demos/benchmark.mjs"
}
]
}
+5 -5
View File
@@ -1,19 +1,19 @@
{
"files.exclude": {
"node_modules/nexrad-level-2-data/**/node_modules": true,
"**/node_modules": true,
"dist/**": true,
"**/node_modules": true
},
"cSpell.words": [
"KLOT",
"Mult",
"NOAA",
"Palettized",
"RGBA",
"Rbga",
"palettization",
"palettize",
"Palettized",
"palletizing",
"Rbga",
"RGBA",
"rrle",
"uncommenting"
]
}
+41 -13
View File
@@ -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
@@ -16,10 +19,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
@@ -47,15 +50,19 @@ Test code and data is provided in the `./demo` folder. `test.js` can be used to
# API
## plot(data, products, options)
Returns an object
Returns an array of objects. The order of elevations in the returned array matches the order of elevations in options.elevations
``` javascript
{
REF: {
canvas: <Canvas>,
palette: <Uint8ClampedArray>
[
{
elevation: <integer>,
REF: {
canvas: <Canvas>,
palette: <Uint8ClampedArray>
},
// ... additional products
},
//... additional products
}
// ... additional elevations
]
```
The first level key in the returned object represents each requested product.
> Note: Each product may return false if no data was found for the specified elevation and product.
@@ -73,15 +80,18 @@ options.cropTo|integer|3600|1 to 3600. After scaling and downsampling as describ
options.background|string|#000000|Background color of the image. This can be transparent by using #RGBA notation. See [ctx.fillStyle](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/fillStyle) for more information.
options.lineWidth|integer|2|The raster image is created by drawing several arcs at the locations and colors specified in the data file. When scaling down you may get a better looking image by adjusting this value to something large than the default.
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).
options.size < 3600 will internally scale the image to the selected size. The scaling algorithm is specific to radar data and returns the maximum value over the range of bins that are combined due to the scaling factor. This ensures that maximum reflectivity or maximum velocity are preserved during the scaling process. Using an image scaling package is not preferred in this case as the scaling algorithm used my mask important data.
options.size > 3600 is invalid as this would cause data to be interpolated and would not be a true representation of the data returned by the radar. If you need this functionality it's recommended to use an image scaling package such as [jimp](https://www.npmjs.com/package/jimp) or [gm](https://www.npmjs.com/package/gm) on the Canvas returned by plot().
options.crop
options.size > 3600 is invalid as this would cause data to be interpolated and would not be a true representation of the data returned by the radar. If you need this functionality it's recommended to use an image scaling package such as [jimp](https://www.npmjs.com/package/jimp) or [gm](https://www.npmjs.com/package/gm) on the Canvas returned by plot() which will also be much faster than the drawing methods used for a radar plot.
### Palettizing
>If used with [plotAndData()](#plotanddatafile-options) both the original image and the palettized image will be returned if used with [plot()](#plotfile-options) only the palettized image will be returned.
@@ -90,7 +100,7 @@ Plotting what is essentially polar data (raw radar data) to a cartesean coordina
This process makes use of the RGBA color space with either 3 or 4 bytes per pixel. From the standpoint of representing radar data in an image this is very inefficient use of space as typically 16 or 32 colors (> 1 byte) is necessary to show the data in it's original format. This RGBA image also does not lend itself well to PNG compression which is lossless.
Palettizing introduces a compromise between image size and compresability. After the initial image is drawing the palettizing algorithm can then re-process the RGBA image and force all pixels to be one of the original color values specificed in the product's palette (options.palettize = true, the default). It can also generate an optimized palette that uses a set number of steps between the colors in the palette and the background color with a maximum generated palette size of 256 colors (options.palettize.generate = <steps>). Finally a custom palette can be provided in the form of [r1,g1,b1,r2,g2,b2,...] alpha values will be generated automatically.
Palettizing introduces a compromise between image size and compresability. After the initial image is drawn the palettizing algorithm can then re-process the RGBA image and force all pixels to be one of the original color values specificed in the product's palette (options.palettize = true, the default). It can also generate an optimized palette that uses a set number of steps between the colors in the palette and the background color with a maximum generated palette size of 256 colors (options.palettize.generate = <steps>). Finally a custom palette can be provided in the form of [r1,g1,b1,r2,g2,b2,...] alpha values will be generated automatically.
A look-up table is created and cached as part of the palettization process speeding up additional calls the the palettizing function. The cache is specific to the product and options provided.
@@ -108,6 +118,24 @@ Writes a PNG file to disk. Provided as a convenience function for production and
fileName|string|A file name or path used by [fs.createWriteStream()](https://nodejs.org/api/fs.html#fs_fs_createwritestream_path_options).
data|{canvas[palette]}|Typically the output of [plot()](#plotfile-options).\<product type>.
# 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.
## v2.0.0 Breaking, returns an array of objects
Previously, a single elevation would be plotted by the routine. The elevation was selected by ```options.elevation```. ```options.elevation``` has been renamed to ```options.elevations``` and will still take a single integer as an input, but in this configuration an array is still returned. The simplest way to return to the functionality of v1.1.0 is ```plot(data,products,{elevation: <integer>})[0]``` which will return only the first object in the array.
```options.elevations``` defaults to all the elevations in the provided file. This may not be the desired behavior, and will take significantly longer to plot if you do not need all of the data provided. You can query ```data.listElevations()``` to return an array of available elevations. The result can be passed directly to options.elevations or further processed to only select interesting elevations before calling ```plot()```. Additional details of ```options.elevations``` are provided above.
## v1.1.0 Notable, RRLE pre-processing
Testing and monitoring of this package in production showed that drawing each 0.5&deg; or 1.0&deg; arc as part of the plotting process was very time-expensive. Drawing a wider arc when adjacent radials had the same color at this position was significantly faster than drawing the two separate arcs.
Implementing this solution which I am calling Radial Run Length Encoding, as it spans several radials, required significant reworking of the plotting engine and resulted in much more modular code. Four pre-process routines are now run on the radar data before plotting. The first three: Downsample, FilterProduct and IndexProduct were all part of the previous version but have been extracted from the main algorithm and placed into their own modules. After each of these three modules were implemented tests were run to show that the image generated was identical to v1.0.0. The addition of the rrle pre-processing module does change the output image slightly, but these visual changes are in the level of the artifacts that are inevitable due to the polar-to-raster conversion detailed in [Palletizing](#palettizing).
# Acknowledgements
The code for this project is based upon:
- [Unidata](https://github.com/Unidata/thredds/blob/master/cdm/src/main/java/ucar/nc2/iosp/nexrad2/)
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.
+53
View File
@@ -0,0 +1,53 @@
/* eslint-disable no-console */
/* eslint-disable no-await-in-loop */
import Level2Radar from 'nexrad-level-2-data';
// eslint-disable-next-line import-x/no-extraneous-dependencies
import { glob } from 'glob';
import fs from 'node:fs';
import { plot, writePngToFile } from '../src/index.mjs';
// list files
const files = glob.sync('./data/KLOT/KLOT20210812_171451_V*'); // ref palette tuning
// const store each file's data
const chunks = [];
// parse each file
files.forEach((file) => {
// eslint-disable-next-line n/no-sync
const fileBuffer = fs.readFileSync(file);
chunks.push(new Level2Radar(fileBuffer));
});
// combine data
const radarData = Level2Radar.combineData(chunks);
const size = 1800;
const iterations = 5;
// plot for each elevation and size
const start = new Date();
for (let i = 0; i < iterations; i += 1) {
const plots = plot(radarData, ['REF', 'VEL'], {
size,
palettize: true,
cropTo: size / 2,
alpha: false,
imageSmoothingEnabled: false,
antialias: 'none',
});
// write files to disk
const writePromises = [];
plots.forEach((p) => {
const { elevation } = p;
writePromises.push(writePngToFile(`./output/REF-${elevation}-${size}.png`, p.REF));
writePromises.push(writePngToFile(`./output/VEL-${elevation}-${size}.png`, p.VEL));
});
await Promise.allSettled(writePromises);
const end = new Date();
console.log(`Iteration: ${i + 1}/${iterations} Average time: ${(end - start) / 1000 / (i + 1)} s`);
}
+32 -29
View File
@@ -1,18 +1,20 @@
const { Level2Radar } = require('nexrad-level-2-data');
// eslint-disable-next-line import/no-extraneous-dependencies
const glob = require('glob');
const fs = require('fs');
/* eslint-disable no-console */
import Level2Radar from 'nexrad-level-2-data';
const { plot, writePngToFile } = require('../index');
// eslint-disable-next-line import-x/no-extraneous-dependencies
import { glob } from 'glob';
import fs from 'node:fs';
import { plot, writePngToFile } from '../src/index.mjs';
// list files
// const files = glob.sync('./data/KLOT/34/*');
// const files = glob.sync('./data/KLOT/381/*');
// const files = glob.sync('./data/KLOT/548/*');
// const files = glob.sync('./data/KLOT/940/*');
const files = await 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/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
@@ -20,6 +22,7 @@ const chunks = [];
// parse each file
files.forEach((file) => {
// eslint-disable-next-line n/no-sync
const fileBuffer = fs.readFileSync(file);
chunks.push(new Level2Radar(fileBuffer));
});
@@ -27,13 +30,10 @@ files.forEach((file) => {
// combine data
const radarData = Level2Radar.combineData(chunks);
// result array by elevations
const plots = [];
// default to all plots unless single is specificed
const single = process.argv.includes('single');
let sizes = [3600, 1800, 900, 800, 600, 450, 100];
let sizes = [1800];
let elevations = radarData.listElevations();
if (single) {
sizes = sizes.slice(0, 1);
@@ -44,21 +44,24 @@ if (single) {
}
// plot for each elevation and size
(async () => {
await Promise.allSettled(sizes.map(async (size) => {
await Promise.allSettled(elevations.map(async (elevation) => {
plots[elevation] = plot(radarData, ['REF', 'VEL'], {
elevation,
size,
palettize: true,
cropTo: size / 2,
});
console.time('processing');
await Promise.allSettled(sizes.map(async (size) => {
const plots = plot(radarData, ['REF', 'VEL'], {
elevations,
size,
palettize: true,
cropTo: size / 2,
imageSmoothingEnabled: false,
antialias: 'none',
});
// write files to disk
await Promise.allSettled([
writePngToFile(`./output/REF-${elevation}-${size}.png`, plots[elevation].REF),
writePngToFile(`./output/VEL-${elevation}-${size}.png`, plots[elevation].VEL),
]);
}));
}));
})();
// write files to disk
const writePromises = [];
plots.forEach((p) => {
const { elevation } = p;
writePromises.push(writePngToFile(`./output/REF-${elevation}-${size}.png`, p.REF));
writePromises.push(writePngToFile(`./output/VEL-${elevation}-${size}.png`, p.VEL));
});
await Promise.allSettled(writePromises);
}));
console.timeEnd('processing');
-56
View File
@@ -1,56 +0,0 @@
"use strict";
const { Level2Radar } = require('nexrad-level-2-data');
// eslint-disable-next-line import/no-extraneous-dependencies
const glob = require('glob');
const fs = require('fs');
const { plot, writePngToFile } = require('../index');
// list files
// const files = glob.sync('./data/KLOT/34/*');
// 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/KLOT/KLOT20210621_041151_V06'); // vel palette tuning
// const store each file's data
const chunks = [];
// parse each file
files.forEach((file) => {
const fileBuffer = fs.readFileSync(file);
chunks.push(new Level2Radar(fileBuffer));
});
// combine data
const radarData = Level2Radar.combineData(chunks);
// result array by elevations
const plots = [];
// default to all plots unless single is specificed
const single = process.argv.includes('single');
let sizes = [3600, 1800, 900, 800, 600, 450, 100];
let elevations = radarData.listElevations();
if (single) {
sizes = sizes.slice(0, 1);
// elevations where the lowest elevation is present, this is to ensure velocity is available
const firstElevationIndex = elevations.slice(0, 1)[0];
const lowestAngle = radarData.vcp.record.elevations[firstElevationIndex].elevation_angle;
elevations = elevations.filter((elevation) => radarData.vcp.record.elevations[elevation].elevation_angle === lowestAngle);
}
// plot for each elevation and size
(async () => {
await Promise.allSettled(sizes.map(async (size) => {
await Promise.allSettled(elevations.map(async (elevation) => {
plots[elevation] = plot(radarData, ['REF', 'VEL'], {
elevation,
size,
palettize: true,
cropTo: size / 2,
});
// write files to disk
await Promise.allSettled([
writePngToFile(`./output/REF-${elevation}-${size}.png`, plots[elevation].REF),
writePngToFile(`./output/VEL-${elevation}-${size}.png`, plots[elevation].VEL),
]);
}));
}));
})();
//# sourceMappingURL=test.js.map
-1
View File
@@ -1 +0,0 @@
{"version":3,"file":"test.js","sourceRoot":"","sources":["../../src/demos/test.js"],"names":[],"mappings":";AAAA,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;AACvD,6DAA6D;AAC7D,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC7B,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEzB,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAErD,aAAa;AACb,+CAA+C;AAC/C,gDAAgD;AAChD,gDAAgD;AAChD,gDAAgD;AAChD,gDAAgD;AAChD,gDAAgD;AAChD,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAC,CAAC,qBAAqB;AACpF,wFAAwF;AAExF,+BAA+B;AAC/B,MAAM,MAAM,GAAG,EAAE,CAAC;AAElB,kBAAkB;AAClB,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;IACtB,MAAM,UAAU,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IACzC,MAAM,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC;AAC1C,CAAC,CAAC,CAAC;AAEH,eAAe;AACf,MAAM,SAAS,GAAG,WAAW,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;AAElD,6BAA6B;AAC7B,MAAM,KAAK,GAAG,EAAE,CAAC;AAEjB,mDAAmD;AACnD,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAE/C,IAAI,KAAK,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,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C,SAAS,CAAC,CAAC,GAAG,CAAC;aAC7E,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,EAAE,CAAC"}
-170
View File
@@ -1,170 +0,0 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const canvas_1 = __importDefault(require("canvas"));
const palettes_1 = __importDefault(require("./palettes"));
const ref_1 = __importDefault(require("./palettes/ref"));
const vel_1 = __importDefault(require("./palettes/vel"));
const palettize_1 = __importDefault(require("./palettize"));
const { createCanvas } = canvas_1.default;
// names of data structures keyed to product name
const dataNames = {
REF: 'reflect',
VEL: 'velocity',
'SW ': 'spectrum',
ZDR: 'zdr',
PHI: 'phi',
RHO: 'rho',
};
// names of data retrieval routines keyed to product name
const dataFunctions = {
REF: 'getHighresReflectivity',
VEL: 'getHighresVelocity',
};
// generate all palettes
const palettes = {
REF: new palettes_1.default(ref_1.default),
VEL: new palettes_1.default(vel_1.default),
};
// default options
const DEFAULT_OPTIONS = {
// must be a square image
size: 3600,
cropTo: 3600,
background: 'black',
lineWidth: 2,
};
// calculation constants
const RAD45 = ((45 * Math.PI) / 180);
const RAD90 = RAD45 * 2;
const draw = (data, _options) => {
// combine options with defaults
const options = {
...DEFAULT_OPTIONS,
..._options,
};
// calculate scale
if (options.size > DEFAULT_OPTIONS.size)
throw new Error(`Upsampling is not supported. Provide a size <= ${DEFAULT_OPTIONS.size}`);
if (options.size < 1)
throw new Error('Provide options.size > 0');
const scale = DEFAULT_OPTIONS.size / options.size;
// calculate crop, adjust if necessary
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');
// fill background with black
ctx.fillStyle = options.background;
ctx.fillRect(0, 0, cropTo, cropTo);
// canvas settings
ctx.imageSmoothingEnabled = true;
ctx.lineWidth = options.lineWidth;
ctx.translate(cropTo / 2, cropTo / 2);
ctx.rotate(-Math.PI / 2);
// get the palette
const palette = palettes[options.product];
// test for valid palette
if (!palette)
throw new Error(`No product found for product type: ${options.product}`);
// set the elevation
data.setElevation(options.elevation);
// get the header data
const headers = data.getHeader();
// calculate resolution in radians, default to 1°
let resolution = Math.PI / 180;
if (data?.vcp?.record?.elevation?.s[options.elevation]?.super_res_control?.super_res?.halfDegreeAzimuth)
resolution /= 2;
// calculate half resolution step for additional calculations below
const halfResolution = resolution / 2;
// match product name to data
const dataName = dataNames[options.product];
const dataFunction = dataFunctions[options.product];
// check for valid product
if (dataName === undefined)
throw new Error(`No data object name found for product: ${options.product}`);
if (dataFunction === undefined)
throw new Error(`No data function found for product: ${options.product}`);
// check for data for this product
if (headers[0][dataName] === undefined)
return false;
// loop through data
headers.forEach((header) => {
// get correct data
const thisRadial = header[dataName];
// skip if this radial isn't found
if (thisRadial === undefined)
return;
// calculate plotting parameters
const deadZone = thisRadial.first_gate / thisRadial.gate_size;
const startAngle = header.azimuth * (Math.PI / 180) - halfResolution;
const endAngle = startAngle + resolution;
// track max value for downsampling(d)
let downsampled = 0;
let lastRemainder = 0;
// calculate maximum bin to plot based on azimuth
// wrap azimuth to 90° offset by -45° (% in js is remainder, the formula below make it in to modulus)
const azWrap = (((startAngle - RAD45) % RAD90) + RAD90) % RAD90;
// calculate a magnitude multiplier as 1/sin with 45° shift removed
const azMagnitudeMult = 1 / Math.abs(Math.sin(azWrap + RAD45));
const cropMaxBin = Math.ceil(Math.abs((options.cropTo / 2) * scale * azMagnitudeMult));
// compare max calculated value with length of radial
const maxBin = Math.min(cropMaxBin, thisRadial.moment_data.length);
// plot each bin
for (let idx = 0; idx < maxBin; idx += 1) {
// get the value
const bin = thisRadial.moment_data[idx];
// skip null values
if (bin !== null) {
let thisSample;
// test for downsampling
if (scale !== 1) {
const remainder = idx % scale;
// test for rollover in scaling
if (remainder < lastRemainder) {
// plot this point and reset values
thisSample = downsampled;
downsampled = 0;
}
// store this sample if it meets downsample requirements
downsampled = palette.downSample(bin, downsampled);
// store for rollover tracking
lastRemainder = remainder;
}
else {
thisSample = bin;
}
// see if there's a sample to plot
if (thisSample && !palette.inDeadband(thisSample)) {
ctx.beginPath();
ctx.strokeStyle = palette.findColorRgba(thisSample);
ctx.arc(0, 0, (idx + deadZone) / scale, startAngle, endAngle);
ctx.stroke();
}
}
}
});
if (!options.palettize) {
// return the palette and canvas
return {
canvas,
};
}
// palettize image
const palettized = palettize_1.default(canvas.getContext('2d'), palette);
// return palettized image
return {
canvas: palettized,
palette: palette.getPalette(),
};
};
module.exports = {
draw,
DEFAULT_OPTIONS,
canvas: canvas_1.default,
};
//# sourceMappingURL=index.js.map
-1
View File
@@ -1 +0,0 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/draw/index.ts"],"names":[],"mappings":";;;;;AAAA,oDAA+B;AAC/B,0DAAiC;AACjC,yDAAiC;AACjC,yDAAiC;AACjC,4DAAyC;AAGzC,MAAM,EAAE,YAAY,EAAE,GAAG,gBAAS,CAAC;AAMnC,iDAAiD;AACjD,MAAM,SAAS,GAAiB;IAC/B,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,UAAU;IACf,KAAK,EAAE,UAAU;IACjB,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;CACV,CAAC;AAEF,yDAAyD;AACzD,MAAM,aAAa,GAAiB;IACnC,GAAG,EAAE,wBAAwB;IAC7B,GAAG,EAAE,oBAAoB;CACzB,CAAC;AAMF,wBAAwB;AACxB,MAAM,QAAQ,GAAY;IACzB,GAAG,EAAE,IAAI,kBAAO,CAAC,aAAG,CAAC;IACrB,GAAG,EAAE,IAAI,kBAAO,CAAC,aAAG,CAAC;CACrB,CAAC;AAEF,kBAAkB;AAClB,MAAM,eAAe,GAAG;IACvB,yBAAyB;IACzB,IAAI,EAAE,IAAI;I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;IAClB,MAAM,UAAU,GAAG,mBAAc,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC;IAEpE,0BAA0B;IAC1B,OAAO;QACN,MAAM,EAAE,UAAU;QAClB,OAAO,EAAE,OAAO,CAAC,UAAU,EAAE;KLine truncated
-102
View File
@@ -1,102 +0,0 @@
"use strict";
// ingest a palette and provide lookup and formatting functionality
// {palette: [r1,g1,b1,a1, r2,g2,b2,a2, ...], limits: [1,2, ...]}
// rgba values are returned with the the color index in the g position with 100% opacity
// 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
Object.defineProperty(exports, "__esModule", { value: true });
const rgbaLookupSize = 200;
class Palette {
palette;
limits;
transparentIndex;
lookupRgba;
closest;
downSampleReset;
downSample;
inDeadband;
constructor(palette) {
this.palette = palette.palette;
this.limits = palette.limits;
this.transparentIndex = palette.transparentIndex ?? 0;
this.lookupRgba = findDbzRbgaGenerator(this.limits, this.palette, palette.maxDbzIndex);
this.closest = {};
this.downSampleReset = palette.downSampleReset ?? -Infinity;
if (typeof palette.downSample === 'function') {
this.downSample = palette.downSample;
}
else {
this.downSample = downSample;
}
if (typeof palette.inDeadband === 'function') {
this.inDeadband = palette.inDeadband;
}
else {
this.inDeadband = inDeadband(this.downSampleReset);
}
}
findColorRgba(dbz) {
// find the rgba value of the color from the provided dbz value
return this.lookupRgba[Math.trunc(dbz + rgbaLookupSize)];
}
getPalette() {
// return the palette properly formatted for the PNG function
const dest = new Uint8ClampedArray(256 * 4);
this.palette.forEach((val, idx) => {
dest[idx] = val;
});
return dest;
}
transparentColorRgba() {
// return the rgba value of the transparent color
const index = this.transparentIndex;
return `rgba(${this.palette[index * 4]},${this.palette[index * 4 + 1]},${this.palette[index * 4 + 2]},${this.palette[(index * 4 + 3)] / 255})`;
}
// match = [r,g,b[,a]]
closestIndex(match) {
// 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');
if (this.closest[asHex])
return this.closest[asHex];
// initial conditions
let closestIndex = 0;
let closest = Infinity;
// loop through array
for (let i = 0; i < this.palette.length; i += 4) {
const dist = Palette.geometricDistance(match, this.palette.slice(i, i + match.length));
// test for closer
if (dist < closest) {
closest = dist;
closestIndex = i / 4;
if (dist === 0)
break;
}
}
// store closest match to speed up next iteration
this.closest[asHex] = closestIndex;
return closestIndex;
}
// geometric distance
static geometricDistance(a, b) {
return Array.from(a).reduce((acc, val, idx) => acc + (val - b[idx]) ** 2, 0);
}
}
exports.default = Palette;
// create a lookup table of colors for faster processing
const findDbzRbgaGenerator = (limits, palette, maxDbzIndex = 14) => {
const lookupRgba = [];
for (let i = -rgbaLookupSize; i <= rgbaLookupSize; i += 1) {
let index = limits.findIndex((limit) => i < limit);
// a value of -1 means it is off the end of the scale, set to highest value
if (index === -1)
index = maxDbzIndex;
lookupRgba.push(`rgba(${palette[index * 4]},${palette[index * 4 + 1]},${palette[index * 4 + 2]},${palette[(index * 4 + 3)] / 255})`);
}
return lookupRgba;
};
const downSample = (cur, prev) => (cur === null ? prev : Math.max(cur, prev));
const inDeadband = (reset) => (a) => (a === null || a === reset || a === undefined);
//# sourceMappingURL=index.js.map
-1
View File
@@ -1 +0,0 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/draw/palettes/index.ts"],"names":[],"mappings":";AAAA,mEAAmE;AACnE,iEAAiE;AACjE,wFAAwF;AACxF,sGAAsG;AACtG,oFAAoF;;AAIpF,MAAM,cAAc,GAAG,GAAG,CAAC;AAM3B,MAAqB,OAAO;IAC3B,OAAO,CAAW;IAClB,MAAM,CAAW;IACjB,gBAAgB,CAAS;IACzB,UAAU,CAAW;IACrB,OAAO,CAAU;IACjB,eAAe,CAAS;IACxB,UAAU,CAAoC;IAC9C,UAAU,CAA0B;IAEpC,YAA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E,KAAK,GAAG,WAAW,CAAC;QACtC,UAAU,CAAC,IAAI,CAAC,QAAQ,OAAO,CAAC,KAAK,GAAG,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC;KACrI;IACD,OAAO,UAAU,CAAC;AACnB,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,GAAU,EAAE,IAAW,EAAS,EAAE,CAAC,CAAC,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;AAEnG,MAAM,UAAU,GAAG,CAAC,KAAY,EAAE,EAAE,CAAC,CAAC,CAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,SAAS,CAAC,CAAC"}
-42
View File
@@ -1,42 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const palette = [
255, 255, 255, 0,
0, 128, 128, 192,
1, 80, 128, 192,
0, 0, 128, 192,
0, 255, 0, 255,
0, 200, 0, 255,
0, 144, 0, 255,
255, 255, 0, 255,
231, 192, 0, 255,
255, 144, 0, 255,
255, 0, 0, 255,
214, 0, 0, 255,
192, 0, 0, 255,
255, 0, 255, 255,
153, 85, 201, 255,
// additional halfway to black values for cleaner picture
0, 64, 64, 96,
1, 40, 64, 96,
0, 0, 64, 96,
0, 128, 0, 128,
0, 100, 0, 128,
0, 72, 0, 128,
128, 128, 0, 128,
116, 96, 0, 128,
128, 72, 0, 128,
128, 0, 0, 128,
107, 0, 0, 128,
96, 0, 0, 128,
128, 0, 128, 128,
77, 43, 101, 128,
];
const limits = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75];
const paletteData = {
palette,
limits,
maxDbzIndex: 14,
};
exports.default = paletteData;
//# sourceMappingURL=ref.js.map
-1
View File
@@ -1 +0,0 @@
{"version":3,"file":"ref.js","sourceRoot":"","sources":["../../../src/draw/palettes/ref.ts"],"names":[],"mappings":";;AAEA,MAAM,OAAO,GAAY;IACxB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;IAChB,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;IAChB,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG;IACf,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG;IACd,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG;IACd,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG;IACd,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG;IACd,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG;IAChB,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG;IAChB,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG;IAChB,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG;IACd,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG;IACd,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG;IACd,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG;IAChB,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG;IAEjB,yDAAyD;IACzD,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE;IACb,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE;IACb,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE;IACZ,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG;IACd,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG;IACd,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,GAAG;IACb,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG;IAChB,GAAG,EAAE,EAAE,EAAE,CAAC,EAAE,GAAG;IACf,GAAG,EAAE,EAAE,EAAE,CAAC,EAAE,GAAG;IACf,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG;IACd,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG;IACd,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG;IACb,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG;IAChB,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG;CAChB,CAAC;AAEF,MAAM,MAAM,GAAa,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;AAErF,MAAM,WAAW,GAAgB;IAChC,OAAO;IACP,MAAM;IACN,WAAW,EAAE,EAAE;CACf,CAAC;AAEF,kBAAe,WAAW,CAAC"}
-56
View File
@@ -1,56 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const palette = [
// 0: green/outbound
0, 255, 0, 255,
0, 240, 0, 255,
0, 223, 0, 255,
0, 206, 0, 255,
0, 189, 0, 255,
0, 172, 0, 255,
0, 155, 0, 255,
0, 138, 0, 255,
16, 121, 16, 255,
32, 113, 32, 255,
48, 104, 48, 255,
// 11: nearly zero
64, 95, 64, 255,
95, 64, 64, 255,
// 13: red/inbound
104, 32, 32, 255,
113, 16, 16, 255,
121, 0, 0, 255,
138, 0, 0, 255,
155, 0, 0, 255,
172, 0, 0, 255,
189, 0, 0, 255,
206, 0, 0, 255,
223, 0, 0, 255,
240, 0, 0, 255,
255, 0, 0, 255,
// 24: transparent
255, 255, 255, 0,
];
const downSample = (cur, prev) => {
// no data, use previous value
if (cur === null)
return prev;
// test for magnitude change, prev may be null but Math.abs(null) === 0 so this is valid
if (Math.abs(cur) >= Math.abs(prev))
return cur;
return prev;
};
const limits = [-99, -90, -80, -70, -60, -50, -40, -30, -20, -15, -10, -5, 0, 5, 10, 15, 20, 30, 40, 50, 60, 70, 80, 90, 99,
];
const downSampleReset = null;
const transparentIndex = 24;
const paletteData = {
palette,
downSample,
limits,
downSampleReset,
transparentIndex,
maxDbzIndex: 23,
};
exports.default = paletteData;
//# sourceMappingURL=vel.js.map
-1
View File
@@ -1 +0,0 @@
{"version":3,"file":"vel.js","sourceRoot":"","sources":["../../../src/draw/palettes/vel.ts"],"names":[],"mappings":";;AAEA,MAAM,OAAO,GAAY;IACxB,oBAAoB;IACpB,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG;IACd,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG;IACd,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG;IACd,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG;IACd,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG;IACd,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG;IACd,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG;IACd,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG;IACd,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG;IAChB,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG;IAChB,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG;IAEhB,kBAAkB;IAClB,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG;IACf,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG;IAEf,kBAAkB;IAClB,GAAG,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG;IAChB,GAAG,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG;IAChB,GAAG,EAA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7B,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAE5B,MAAM,WAAW,GAAgB;IAChC,OAAO;IACP,UAAU;IACV,MAAM;IACN,eAAe;IACf,gBAAgB;IAChB,WAAW,EAAE,EAAE;CACf,CAAC;AAEF,kBAAe,WAAW,CAAC"}
-30
View File
@@ -1,30 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const canvas_1 = require("canvas");
const palettizeImage = (sourceCtx, palette) => {
// get the dimensions of the image from the ctx
const dim = {
x: sourceCtx.canvas.width,
y: sourceCtx.canvas.height,
};
console.time('Palettize image');
// transform into indexed palette by finding the closest indexed color for each pixel
// create a destination image that is transparent and indexed
const indexedCanvas = canvas_1.createCanvas(dim.x, dim.y);
const indexedCtx = indexedCanvas.getContext('2d', { pixelFormat: 'A8' });
// get the source image data
const sourceImageData = sourceCtx.getImageData(0, 0, dim.x, dim.y);
// get the indexed image data (destination)
const indexedImageData = indexedCtx.getImageData(0, 0, dim.x, dim.y);
// loop through each pixel
console.log(`Palettized cache size: ${Object.keys(palette.closest).length}`);
indexedImageData.data.forEach((val, idx) => {
indexedImageData.data[idx] = palette.closestIndex(sourceImageData.data.slice(idx * 4, idx * 4 + 3));
});
console.timeEnd('Palettize image');
// write the new image data
indexedCtx.putImageData(indexedImageData, 0, 0);
return indexedCanvas;
};
exports.default = palettizeImage;
//# sourceMappingURL=palettize.js.map
-1
View File
@@ -1 +0,0 @@
{"version":3,"file":"palettize.js","sourceRoot":"","sources":["../../src/draw/palettize.ts"],"names":[],"mappings":";;AAAA,mCAAwE;AAGxE,MAAM,cAAc,GAAG,CAAC,SAAkC,EAAE,OAAgB,EAAS,EAAE;IACtF,+CAA+C;IAC/C,MAAM,GAAG,GAAG;QACX,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,KAAK;QACzB,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,MAAM;KAC1B,CAAC;IACF,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;I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2 data
* @param {Level2Data} data output from the nexrad-level-2-data library
* @param {(string|string[])} _products Options are REF, VEL, SW , ZDR, PHI and RHO
* @param {object} options Plotting options
* @param {number} [options.size=3600] 1 to 3600. Size of the x and y axis in pixels. The image must be square so only a single integer is needed.
* @param {number} [options.cropTo=3600] 1 to 3600. After scaling and downsampling as described above crop the resulting plot to the size specified. Internally, the image is actually drawn at the cropped size to save on processing time.
* @param {string} [options.background=#000000] Background color of the image. This can be transparent by using #RGBA notation.
* @param {number} [options.lineWidth=2] The raster image is created by drawing several arcs at the locations and colors specified in the data file. When scaling down you may get a better looking image by adjusting this value to something large than the default.
* @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.
* @returns Canvas
*/
const plot = (data, _products, options) => {
// store result
const result = {};
let products;
// make product list into an array
if (_products && Array.isArray(_products)) {
products = _products;
}
else if (typeof _products === 'string') {
products = [_products];
}
else {
// default to all products
products = ['REF', 'VEL', 'SW ', 'ZDR', 'PHI', 'RHO'];
}
// get the available elevations
const elevations = data.listElevations();
if (elevations.length === 0)
throw new Error('No elevations availabe');
products.forEach((product) => {
// parse and store result
result[product] = draw(data, {
...options,
product,
});
});
return result;
};
module.exports = {
plot,
writePngToFile,
canvas,
};
//# sourceMappingURL=index.js.map
-1
View File
@@ -1 +0,0 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";AAAA,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAC3C,MAAM,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AACnD;;;;;;;;;;;GAWG;AACH,MAAM,IAAI,GAAG,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE;IACzC,eAAe;IACf,MAAM,MAAM,GAAG,EAAE,CAAC;IAElB,IAAI,QAAQ,CAAC;IACb,kCAAkC;IAClC,IAAI,SAAS,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;QAC1C,QAAQ,GAAG,SAAS,CAAC;KACrB;SAAM,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;QACzC,QAAQ,GAAG,CAAC,SAAS,CAAC,CAAC;KACvB;SAAM;QACN,0BAA0B;QAC1B,QAAQ,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;KACtD;IAED,+BAA+B;IAC/B,MAAM,UAAU,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;IACzC,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAEvE,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC5B,yBAAyB;QACzB,MAAM,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE;YAC5B,GAAG,OAAO;YACV,OAAO;SACP,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,CAAC,OAAO,GAAG;IAChB,IAAI;IACJ,cAAc;IACd,MAAM;CACN,CAAC"}
-3
View File
@@ -1,3 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=types.js.map
-1
View File
@@ -1 +0,0 @@
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
-31
View File
@@ -1,31 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require('fs');
// write a canvas to a Png file
/**
* Write a Canvas to the specified file
* @param {string} fileName Path to write output to, passed to fs.createWriteStream
* @param {Canvas} data Canvas provided by the plot() function
* @returns Promise
*/
const writePngToFile = (fileName, data) => new Promise((resolve, reject) => {
// the draw function will return false if no data was found, short circuit the output here
if (!data.canvas) {
resolve();
return;
}
// get a write stream
const writeStream = fs.createWriteStream(fileName);
// options
const options = {};
if (data.palette)
options.palette = data.palette;
// write to the stream
data.canvas.createPNGStream(options).pipe(writeStream);
writeStream.on('finish', () => resolve());
writeStream.on('error', (e) => reject(e));
});
module.exports = {
writePngToFile,
};
//# sourceMappingURL=file.js.map
-1
View File
@@ -1 +0,0 @@
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../src/utils/file.ts"],"names":[],"mappings":";;AAGA,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AACzB,+BAA+B;AAC/B;;;;;GAKG;AACH,MAAM,cAAc,GAAG,CAAC,QAAgB,EAAE,IAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;IAC9F,0FAA0F;IAC1F,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;QACjB,OAAO,EAAE,CAAC;QACV,OAAO;KACP;IAED,qBAAqB;IACrB,MAAM,WAAW,GAAG,EAAE,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IAEnD,UAAU;IACV,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,IAAI,IAAI,CAAC,OAAO;QAAE,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;IAEjD,sBAAsB;IACtB,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACvD,WAAW,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;IAC1C,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAQ,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAClD,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,OAAO,GAAG;IAChB,cAAc;CACd,CAAC"}
+85
View File
@@ -0,0 +1,85 @@
import path from 'node:path';
import { includeIgnoreFile } from '@eslint/compat';
import js from '@eslint/js';
import { defineConfig } from 'eslint/config';
import { configs, plugins } from 'eslint-config-airbnb-extended';
const gitignorePath = path.resolve('.', '.gitignore');
const jsConfig = defineConfig([
// ESLint recommended config
{
name: 'js/config',
...js.configs.recommended,
},
// Stylistic plugin
plugins.stylistic,
// Import X plugin
plugins.importX,
// Airbnb base recommended config
...configs.base.recommended,
]);
const nodeConfig = defineConfig([
// Node plugin
plugins.node,
// Airbnb Node recommended config
...configs.node.recommended,
]);
const rules = {
'@stylistic/indent': ['error', 'tab', { SwitchCase: 1 }],
'@stylistic/no-tabs': 0,
'no-param-reassign': [
'error',
{
props: false,
},
],
'@stylistic/max-len': 0,
'no-underscore-dangle': [
'error',
{
allowAfterThis: true,
},
],
'import-x/no-useless-path-segments': 0,
'no-bitwise': 0,
'import-x/extensions': [
'error',
'ignorePackages',
{
js: 'always',
mjs: 'always',
json: 'always',
},
],
};
const languageOptions = {
ecmaVersion: 'latest',
parserOptions: {
ecmaVersion: 'latest',
},
};
const ignores = [
'docs/**',
];
export default defineConfig([
{
ignores,
},
// Ignore files and folders listed in .gitignore
includeIgnoreFile(gitignorePath),
// JavaScript config
...jsConfig,
// Node config
...nodeConfig,
{
languageOptions,
rules,
},
]);
+8
View File
@@ -0,0 +1,8 @@
{
"folders": [
{
"path": "."
}
],
"settings": {}
}
+3 -3
View File
@@ -1,4 +1,4 @@
# Ignore everything in this directory as it is generated dynamically
*
# Except this file
# Ignore everything in this directory as it is generated dynamically
*
# Except this file
!.gitignore
+6134 -5421
View File
File diff suppressed because it is too large. Load diff
Loaded 100 of 118 files, more files were not shown because too many files have changed in this diff. Show more