Compare commits

..
3 Commits
Author SHA1 Message Date
Matt Walsh 4a1f29cfae change to piscina 2022-07-13 23:21:58 -05:00
Matt Walsh 8b244a41a6 testing 2022-07-13 21:42:07 -05:00
Matt Walsh 97b07611e8 initial threading tests 2022-07-13 16:36:43 -05:00
79 changed files with 2315 additions and 1927 deletions

No files matched your search

+2 -1
View File
@@ -11,7 +11,8 @@
"skipFiles": [ "skipFiles": [
"<node_internals>/**" "<node_internals>/**"
], ],
"program": "${workspaceFolder}/demos/test.js" "program": "${workspaceFolder}/demos/test.js",
"outputCapture": "std",
}, },
{ {
"type": "pwa-node", "type": "pwa-node",
-3
View File
@@ -2,9 +2,6 @@
> A javascript implementation for plotting Nexrad Level II data parsed via [nexrad-level-2-data](https://github.com/netbymatt/nexrad-level-2-data/). > 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 # Use
## Install ## Install
```bash ```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.
+1 -1
View File
@@ -39,7 +39,7 @@ const iterations = 5;
// write files to disk // write files to disk
const writePromises = []; const writePromises = [];
plots.forEach((p) => { (await plots).forEach((p) => {
const { elevation } = p; const { elevation } = p;
writePromises.push(writePngToFile(`./output/REF-${elevation}-${size}.png`, p.REF)); writePromises.push(writePngToFile(`./output/REF-${elevation}-${size}.png`, p.REF));
writePromises.push(writePngToFile(`./output/VEL-${elevation}-${size}.png`, p.VEL)); writePromises.push(writePngToFile(`./output/VEL-${elevation}-${size}.png`, p.VEL));
+5 -4
View File
@@ -10,9 +10,9 @@ const { plot, writePngToFile } = require('../src');
// const files = glob.sync('./data/KLOT/381/*'); // const files = glob.sync('./data/KLOT/381/*');
// const files = glob.sync('./data/KLOT/548/*'); // const files = glob.sync('./data/KLOT/548/*');
// const files = glob.sync('./data/KLOT/940/*'); // const files = glob.sync('./data/KLOT/940/*');
const files = glob.sync('./data/KSRX/804/*'); // const files = glob.sync('./data/KSRX/804/*');
// const files = glob.sync('./data/TORD/168/*'); // 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/KLOT20210812_171451_V*'); // ref palette tuning
// const files = glob.sync('./data/KLOT/KLOT20210621_041151_V06'); // vel palette tuning // const files = glob.sync('./data/KLOT/KLOT20210621_041151_V06'); // vel palette tuning
// const store each file's data // const store each file's data
@@ -43,10 +43,11 @@ if (single) {
// plot for each elevation and size // plot for each elevation and size
(async () => { (async () => {
await Promise.allSettled(sizes.map(async (size) => { await Promise.allSettled(sizes.map(async (size) => {
const plots = plot(radarData, ['REF', 'VEL'], { const plots = await plot(radarData, ['REF', 'VEL'], {
elevations, elevations,
size, size,
palettize: true, palettize: true,
elevations: 1,
cropTo: size / 2, cropTo: size / 2,
}); });
+2273 -1900
View File
File diff suppressed because it is too large. Load diff
+5 -4
View File
@@ -1,6 +1,6 @@
{ {
"name": "nexrad-level-2-plot", "name": "nexrad-level-2-plot",
"version": "2.6.4", "version": "2.6.2",
"description": "Plotting library for nexrad-level-2-data", "description": "Plotting library for nexrad-level-2-data",
"main": "src/index.js", "main": "src/index.js",
"scripts": { "scripts": {
@@ -24,14 +24,15 @@
}, },
"homepage": "https://github.com/netbymatt/nexrad-level-2-plot#readme", "homepage": "https://github.com/netbymatt/nexrad-level-2-plot#readme",
"dependencies": { "dependencies": {
"canvas": "^2.11.2", "canvas": "^2.9.3",
"nexrad-level-2-data": "^2.3.5" "nexrad-level-2-data": "../nexrad-level-2-data",
"piscina": "^3.2.0"
}, },
"devDependencies": { "devDependencies": {
"eslint": "^8.0.0", "eslint": "^8.0.0",
"eslint-config-airbnb-base": "^15.0.0", "eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.23.4", "eslint-plugin-import": "^2.23.4",
"glob": "^10.0.0" "glob": "^7.1.7"
}, },
"engines": { "engines": {
"node": ">=13.0.0" "node": ">=13.0.0"
+3 -2
View File
@@ -76,10 +76,11 @@ const draw = (data, _options) => {
if (options.size < 1) throw new Error('Provide options.size > 0'); if (options.size < 1) throw new Error('Provide options.size > 0');
const scale = DEFAULT_OPTIONS.size / options.size; const scale = DEFAULT_OPTIONS.size / options.size;
// wsr88d uses a gate size of 0.25km, tdwr uses a gate size of 0.15km or 0.30km // 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
// this calculation scales the plot accordingly to the nominal 0.25km so all generated plots are at the same scale // 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 rawGateSize = data?.data?.[options.elevation]?.[0]?.record?.reflect?.gate_size ?? 0.25;
const gateSizeScaling = rawGateSize / 0.25; const realGateSize = rawGateSize !== 0.3 ? rawGateSize : rawGateSize / 2;
const gateSizeScaling = 0.25 / realGateSize;
// calculate crop, adjust if necessary // calculate crop, adjust if necessary
const cropTo = Math.min(options.size, options.cropTo); const cropTo = Math.min(options.size, options.cropTo);
+9
View File
@@ -0,0 +1,9 @@
const { Level2Radar } = require('nexrad-level-2-data');
const { workerData } = require('piscina');
const { draw } = require('./index');
module.exports = (options) => {
const level2Radar = Level2Radar(workerData);
const plot = draw(level2Radar, options);
return plot;
};
+17 -12
View File
@@ -1,5 +1,8 @@
const { draw, canvas } = require('./draw'); const { Piscina } = require('piscina');
const path = require('path');
const { canvas } = require('./draw');
const { writePngToFile } = require('./utils/file'); const { writePngToFile } = require('./utils/file');
/** /**
* Plot level 2 data * Plot level 2 data
* @param {Level2Data} data output from the nexrad-level-2-data library * @param {Level2Data} data output from the nexrad-level-2-data library
@@ -17,10 +20,7 @@ const { writePngToFile } = require('./utils/file');
* @param {string} [options.antialias = 'default'] Control antialias. Passed directly to ctx.antialias (part of node-canvas) * @param {string} [options.antialias = 'default'] Control antialias. Passed directly to ctx.antialias (part of node-canvas)
* @returns Canvas * @returns Canvas
*/ */
const plot = (data, _products, options) => { const plot = async (data, _products, options) => {
// store result
const result = [];
let products; let products;
// make product list into an array // make product list into an array
if (_products && Array.isArray(_products)) { if (_products && Array.isArray(_products)) {
@@ -41,19 +41,24 @@ const plot = (data, _products, options) => {
if (!elevations) elevations = availableElevations; if (!elevations) elevations = availableElevations;
if (typeof elevations === 'number') elevations = [elevations]; if (typeof elevations === 'number') elevations = [elevations];
elevations.forEach((elevation) => { const staticPool = new Piscina({
filename: path.resolve(__dirname, './draw/thread.js'),
workerData: data.toObject(),
});
const result = await Promise.all(elevations.map(async (elevation) => {
const elevationResult = { elevation }; const elevationResult = { elevation };
products.forEach((product) => { await Promise.all(products.map(async (product) => {
// parse and store result // parse and store result
elevationResult[product] = draw(data, { elevationResult[product] = await staticPool.run({
...options, ...options,
elevation, elevation,
product, product,
}); });
}); }));
result.push(elevationResult); return elevationResult;
}); }));
staticPool.destroy();
return result; return result;
}; };