diff --git a/.vscode/launch.json b/.vscode/launch.json index ab73d23..0e57b9e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,22 +5,22 @@ "version": "0.2.0", "configurations": [ { - "type": "pwa-node", + "type": "node", "request": "launch", "name": "Test", "skipFiles": [ "/**" ], - "program": "${workspaceFolder}/demos/test.js" + "program": "${workspaceFolder}/demos/test.mjs" }, { - "type": "pwa-node", + "type": "node", "request": "launch", "name": "Benchmark", "skipFiles": [ "/**" ], - "program": "${workspaceFolder}/demos/benchmark.js" + "program": "${workspaceFolder}/demos/benchmark.mjs" } ] } \ No newline at end of file diff --git a/demos/benchmark.js b/demos/benchmark.js deleted file mode 100644 index 8fe7b7c..0000000 --- a/demos/benchmark.js +++ /dev/null @@ -1,52 +0,0 @@ -/* eslint-disable no-await-in-loop */ -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('../src'); - -// 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) => { - 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 -(async () => { - 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`); - } -})(); diff --git a/demos/benchmark.mjs b/demos/benchmark.mjs new file mode 100644 index 0000000..7822449 --- /dev/null +++ b/demos/benchmark.mjs @@ -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`); +} diff --git a/demos/test.js b/demos/test.mjs similarity index 57% rename from demos/test.js rename to demos/test.mjs index 46da6a9..da71b60 100644 --- a/demos/test.js +++ b/demos/test.mjs @@ -1,15 +1,17 @@ -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('../src'); +// 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/168/*'); // const files = glob.sync('./data/KLOT/KLOT20210812_171451_V*'); // ref palette tuning @@ -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)); }); @@ -41,22 +44,24 @@ if (single) { } // plot for each elevation and size -(async () => { - await Promise.allSettled(sizes.map(async (size) => { - const plots = plot(radarData, ['REF', 'VEL'], { - elevations, - 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 - 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); - })); -})(); + // 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'); diff --git a/package.json b/package.json index 1412d47..d25e8cd 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "2.6.4", "description": "Plotting library for nexrad-level-2-data", "main": "src/index.js", + "type": "module", "scripts": { "lint": "npx eslint .", "lint:fix": "npx eslint . --fix" diff --git a/src/draw/index.js b/src/draw/index.mjs similarity index 90% rename from src/draw/index.js rename to src/draw/index.mjs index de988d0..993bebe 100644 --- a/src/draw/index.js +++ b/src/draw/index.mjs @@ -1,15 +1,19 @@ -const canvasObj = require('canvas'); +import canvasObj from 'canvas'; -const { createCanvas } = canvasObj; +import Palette from './palettes/index.mjs'; -const Palette = require('./palettes'); -const palettizeImage = require('./palettize'); +import palettizeImage from './palettize.mjs'; // data pre-processing -const filterProduct = require('./preprocess/filterproduct'); -const downSample = require('./preprocess/downsample'); -const indexProduct = require('./preprocess/indexproduct'); -const rrle = require('./preprocess/rrle'); +import filterProduct from './preprocess/filterproduct.mjs'; +import downSample from './preprocess/downsample.mjs'; +import indexProduct from './preprocess/indexproduct.mjs'; +import rrle from './preprocess/rrle.mjs'; + +import * as ref from './palettes/ref.mjs'; +import * as vel from './palettes/vel.mjs'; + +const { createCanvas } = canvasObj; // names of data structures keyed to product name const dataNames = { @@ -28,12 +32,11 @@ const dataFunctions = { }; // generate all palettes -/* eslint-disable global-require */ + const palettes = { - REF: new Palette(require('./palettes/ref')), - VEL: new Palette(require('./palettes/vel')), + REF: new Palette(ref), + VEL: new Palette(vel), }; -/* eslint-enable global-require */ const preferredWaveformUsage = { 1: ['REF', 'SW ', 'ZDR', 'PHI', 'RHO'], @@ -96,7 +99,7 @@ const draw = (data, _options) => { ctx.fillRect(0, 0, cropTo, cropTo); // canvas settings - ctx.imageSmoothingEnabled = true; + // ctx.imageSmoothingEnabled = true; ctx.lineWidth = options.lineWidth / gateSizeScaling; ctx.translate(cropTo / 2, cropTo / 2); ctx.rotate(-Math.PI / 2); @@ -179,8 +182,10 @@ const draw = (data, _options) => { }; }; -module.exports = { +const canvas = canvasObj; + +export { draw, DEFAULT_OPTIONS, - canvas: canvasObj, + canvas, }; diff --git a/src/draw/palettes/helpers.mjs b/src/draw/palettes/helpers.mjs new file mode 100644 index 0000000..2144eb3 --- /dev/null +++ b/src/draw/palettes/helpers.mjs @@ -0,0 +1,34 @@ +const RGBA_LOOKUP_SIZE = 200; + +// create a lookup table for indices generated by findDbzIndexGenerator +const findDbzRbgaGenerator = (limits, palette) => { + const lookupRgba = []; + for (let i = 0; i < palette.length; i += 4) { + lookupRgba.push(`rgba(${palette[i]},${palette[i + 1]},${palette[i + 2]},${palette[(i + 3)] / 255})`); + } + return lookupRgba; +}; + +// create a lookup table of colors by palette index +const findDbzIndexGenerator = (limits, palette, maxDbzIndex = 14) => { + const lookupRgba = []; + for (let i = -RGBA_LOOKUP_SIZE; i <= RGBA_LOOKUP_SIZE; 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(index); + } + return lookupRgba; +}; + +const downSample = (cur, prev) => (cur === null ? prev : Math.max(cur, prev)); + +const inDeadband = (reset) => (a) => (a === null || a === reset || a === undefined); + +export { + findDbzIndexGenerator, + findDbzRbgaGenerator, + downSample, + inDeadband, + RGBA_LOOKUP_SIZE, +}; diff --git a/src/draw/palettes/hexlookup.js b/src/draw/palettes/hexlookup.js deleted file mode 100644 index 9a18d28..0000000 --- a/src/draw/palettes/hexlookup.js +++ /dev/null @@ -1 +0,0 @@ -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']; diff --git a/src/draw/palettes/hexlookup.mjs b/src/draw/palettes/hexlookup.mjs new file mode 100644 index 0000000..3ab0853 --- /dev/null +++ b/src/draw/palettes/hexlookup.mjs @@ -0,0 +1,2 @@ +const hexLookup = ['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']; +export default hexLookup; diff --git a/src/draw/palettes/index.js b/src/draw/palettes/index.mjs similarity index 72% rename from src/draw/palettes/index.js rename to src/draw/palettes/index.mjs index 6f7a504..b1aec6c 100644 --- a/src/draw/palettes/index.js +++ b/src/draw/palettes/index.mjs @@ -4,9 +4,10 @@ // 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; +import hexLookup from './hexlookup.mjs'; +import { + findDbzIndexGenerator, findDbzRbgaGenerator, downSample, inDeadband, RGBA_LOOKUP_SIZE, +} from './helpers.mjs'; class Palette { constructor(palette) { @@ -18,7 +19,7 @@ class Palette { this.closest = {}; // these may not exist and are overridden with default functions - if (palette.hasOwnProperty('downSampleReset')) { + if (Object.hasOwn(palette, 'downSampleReset')) { this.downSampleReset = palette.downSampleReset; } else { this.downSampleReset = -Infinity; @@ -38,7 +39,7 @@ class Palette { findColorIndex(dbz) { // find the rgba value of the color from the provided dbz value - return this.lookupIndex[Math.trunc(dbz + rgbaLookupSize)]; + return this.lookupIndex[Math.trunc(dbz + RGBA_LOOKUP_SIZE)]; } getPalette() { @@ -89,29 +90,4 @@ class Palette { } } -// create a lookup table for indices generated by findDbzIndexGenerator -const findDbzRbgaGenerator = (limits, palette) => { - const lookupRgba = []; - for (let i = 0; i < palette.length; i += 4) { - lookupRgba.push(`rgba(${palette[i]},${palette[i + 1]},${palette[i + 2]},${palette[(i + 3)] / 255})`); - } - return lookupRgba; -}; - -// create a lookup table of colors by palette index -const findDbzIndexGenerator = (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(index); - } - return lookupRgba; -}; - -const downSample = (cur, prev) => (cur === null ? prev : Math.max(cur, prev)); - -const inDeadband = (reset) => (a) => (a === null || a === reset || a === undefined); - -module.exports = Palette; +export default Palette; diff --git a/src/draw/palettes/ref.js b/src/draw/palettes/ref.mjs similarity index 88% rename from src/draw/palettes/ref.js rename to src/draw/palettes/ref.mjs index 726dd3d..9795a05 100644 --- a/src/draw/palettes/ref.js +++ b/src/draw/palettes/ref.mjs @@ -34,11 +34,11 @@ const palette = [ const maxDbzIndex = 14; // index of maximum dbz -const limits = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75]; +const limits = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75]; const transparentIndex = 0; -module.exports = { +export { palette, maxDbzIndex, limits, diff --git a/src/draw/palettes/vel.js b/src/draw/palettes/vel.mjs similarity index 87% rename from src/draw/palettes/vel.js rename to src/draw/palettes/vel.mjs index 083891d..defa645 100644 --- a/src/draw/palettes/vel.js +++ b/src/draw/palettes/vel.mjs @@ -41,7 +41,7 @@ const downSample = (cur, prev) => { 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 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; @@ -50,7 +50,7 @@ const maxDbzIndex = 12; // index of maximum dbz const transparentIndex = 24; -module.exports = { +export { palette, downSample, limits, diff --git a/src/draw/palettize.js b/src/draw/palettize.mjs similarity index 92% rename from src/draw/palettize.js rename to src/draw/palettize.mjs index 952b6a0..07023b9 100644 --- a/src/draw/palettize.js +++ b/src/draw/palettize.mjs @@ -1,4 +1,4 @@ -const { createCanvas } = require('canvas'); +import { createCanvas } from 'canvas'; const palettizeImage = (sourceCtx, palette) => { // get the dimensions of the image from the ctx @@ -28,4 +28,4 @@ const palettizeImage = (sourceCtx, palette) => { return indexedCanvas; }; -module.exports = palettizeImage; +export default palettizeImage; diff --git a/src/draw/preprocess/downsample.js b/src/draw/preprocess/downsample.mjs similarity index 91% rename from src/draw/preprocess/downsample.js rename to src/draw/preprocess/downsample.mjs index bd4a86d..c290a74 100644 --- a/src/draw/preprocess/downsample.js +++ b/src/draw/preprocess/downsample.mjs @@ -2,7 +2,7 @@ // this includes "cropping" the data to the specified size // calculation constants -const RAD45 = (45 * Math.PI / 180); +const RAD45 = (45 * Math.PI) / 180; const RAD90 = RAD45 * 2; const downSample = (radials, scale, resolution, options, palette) => { @@ -25,7 +25,7 @@ const downSample = (radials, scale, resolution, options, palette) => { const azWrap = (((azimuth - 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)); + const cropMaxBin = Math.ceil(Math.abs((options.cropTo / 2) * scale * azMagnitudeMult)); // compare max calculated value with length of radial const maxBin = Math.min(cropMaxBin, radial.moment_data.length); @@ -53,4 +53,4 @@ const downSample = (radials, scale, resolution, options, palette) => { }); }; -module.exports = downSample; +export default downSample; diff --git a/src/draw/preprocess/filterproduct.js b/src/draw/preprocess/filterproduct.mjs similarity index 93% rename from src/draw/preprocess/filterproduct.js rename to src/draw/preprocess/filterproduct.mjs index acc32da..4c11dac 100644 --- a/src/draw/preprocess/filterproduct.js +++ b/src/draw/preprocess/filterproduct.mjs @@ -13,4 +13,4 @@ const filterProduct = (data, product) => data.map((header) => { // remove any missing radials }).filter((d) => d); -module.exports = filterProduct; +export default filterProduct; diff --git a/src/draw/preprocess/indexproduct.js b/src/draw/preprocess/indexproduct.mjs similarity index 93% rename from src/draw/preprocess/indexproduct.js rename to src/draw/preprocess/indexproduct.mjs index 6b04369..9daa70f 100644 --- a/src/draw/preprocess/indexproduct.js +++ b/src/draw/preprocess/indexproduct.mjs @@ -13,4 +13,4 @@ const indexProduct = (radials, palette) => radials.map((radial) => { }; }); -module.exports = indexProduct; +export default indexProduct; diff --git a/src/draw/preprocess/rrle.js b/src/draw/preprocess/rrle.mjs similarity index 96% rename from src/draw/preprocess/rrle.js rename to src/draw/preprocess/rrle.mjs index b5fbbd7..e5525e8 100644 --- a/src/draw/preprocess/rrle.js +++ b/src/draw/preprocess/rrle.mjs @@ -46,7 +46,7 @@ const findTotalMatches = (radials, startI, binIdx, resolutionThreshold) => { const rrle = (radials, resolutionRad) => { // calculate the nominal angle to the next radial plus 20% to easily account for floating point inaccuracies - const resolutionThreshold = resolutionRad * 180 / Math.PI * 1.2; + const resolutionThreshold = ((resolutionRad * 180) / Math.PI) * 1.2; // sort the radials by azimuth, 0 > 360 const sorted = radials.sort((a, b) => a.azimuth - b.azimuth); @@ -73,4 +73,4 @@ const rrle = (radials, resolutionRad) => { return radials; }; -module.exports = rrle; +export default rrle; diff --git a/src/index.js b/src/index.mjs similarity index 95% rename from src/index.js rename to src/index.mjs index ba5a735..75be3ea 100644 --- a/src/index.js +++ b/src/index.mjs @@ -1,5 +1,6 @@ -const { draw, canvas } = require('./draw'); -const { writePngToFile } = require('./utils/file'); +import { draw, canvas } from './draw/index.mjs'; +import writePngToFile from './utils/writePngToFile.mjs'; + /** * Plot level 2 data * @param {Level2Data} data output from the nexrad-level-2-data library @@ -57,7 +58,9 @@ const plot = (data, _products, options) => { return result; }; -module.exports = { +export default plot; + +export { plot, writePngToFile, canvas, diff --git a/src/utils/file.js b/src/utils/writePngToFile.mjs similarity index 92% rename from src/utils/file.js rename to src/utils/writePngToFile.mjs index b9472ac..19122ad 100644 --- a/src/utils/file.js +++ b/src/utils/writePngToFile.mjs @@ -1,4 +1,4 @@ -const fs = require('fs'); +import fs from 'node:fs'; // write a canvas to a Png file /** * Write a Canvas to the specified file @@ -26,6 +26,4 @@ const writePngToFile = (fileName, data) => new Promise((resolve, reject) => { writeStream.on('error', (e) => reject(e)); }); -module.exports = { - writePngToFile, -}; +export default writePngToFile;