mirror of
https://github.com/netbymatt/nexrad-level-3-plot.git
synced 2026-11-28 18:48:04 -08:00
optional logging
This commit is contained in:
1 parent
324bf8bc81
commit
c87294e92d
7 files changed
+1150
-2091
No files matched your search
@@ -31,7 +31,6 @@ module.exports = {
|
||||
],
|
||||
'no-tabs': 0,
|
||||
'max-len': 0,
|
||||
'no-console': 0,
|
||||
'no-bitwise': 0,
|
||||
},
|
||||
ignorePatterns: [
|
||||
|
||||
@@ -56,6 +56,7 @@ options.size|integer|1800|1 to 1800. Size of the x and y axis in pixels. The ima
|
||||
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.palletize|boolean\|object|false|After drawing the image convert the image from RGBA to a palettized image. When true the same pallet as the product is used. Additional options are described in [palletizing](#palletizing). This can significantly reduce the size of the resulting image with minimal loss of clarity.
|
||||
|options.logger|logger|console|By default messages and errors will be logged to the console. These can be surpressed by passing false. A custom logger can be provided. It must provide the functions ``log()`` and ``error()``.
|
||||
|
||||
### Downsampling
|
||||
A full size plot is 1800 x 1800 pixels. This corresponds to the maximum range of the radar ~250 mi * maximum resolution 0.25 mi/bin * 2 (east and west side of radar).
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable no-console */
|
||||
const fs = require('fs');
|
||||
const { plotAndData, writePngToFile } = require('../src');
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable no-console */
|
||||
const fs = require('fs');
|
||||
const { plotAndData, writePngToFile } = require('../src');
|
||||
|
||||
|
||||
Generated
+1126
-2083
File diff suppressed because it is too large.
Load diff
+3
-3
@@ -25,12 +25,12 @@
|
||||
},
|
||||
"homepage": "https://github.com/netbymatt/nexrad-level-3-plot#readme",
|
||||
"devDependencies": {
|
||||
"eslint": "^7.21.0",
|
||||
"eslint-config-airbnb-base": "^14.2.1",
|
||||
"eslint": "^8.0.0",
|
||||
"eslint-config-airbnb-base": "^15.0.0",
|
||||
"eslint-plugin-import": "^2.22.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"canvas": "^2.6.1",
|
||||
"nexrad-level-3-data": "^0.4.0"
|
||||
"nexrad-level-3-data": "^0.5.0"
|
||||
}
|
||||
}
|
||||
+18
-4
@@ -4,7 +4,8 @@ const { draw } = require('./draw');
|
||||
const palletize = require('./palletize');
|
||||
const { writePngToFile } = require('./utils/file');
|
||||
|
||||
const plotAndData = (file, options) => {
|
||||
const plotAndData = (file, _options) => {
|
||||
const options = combineOptions(_options);
|
||||
// parse the file
|
||||
const data = NexradLevel3Data(file);
|
||||
// test the product code and product type
|
||||
@@ -15,8 +16,6 @@ const plotAndData = (file, options) => {
|
||||
|
||||
// test for a null product code
|
||||
if (data.productDescription.nullProductFlag) {
|
||||
console.log('Null data');
|
||||
console.log(data.productDescription.nullProductFlag);
|
||||
return {
|
||||
image: null,
|
||||
data,
|
||||
@@ -42,7 +41,7 @@ const plotAndData = (file, options) => {
|
||||
};
|
||||
} catch (e) {
|
||||
// don't return the failed palletized image
|
||||
console.error(e.stack);
|
||||
options.logger.error(e.stack);
|
||||
return {
|
||||
image,
|
||||
data,
|
||||
@@ -55,6 +54,21 @@ const plot = (file, options) => {
|
||||
return palletized ?? image;
|
||||
};
|
||||
|
||||
// combine options and defaults
|
||||
const combineOptions = (newOptions) => {
|
||||
let logger = newOptions?.logger ?? console;
|
||||
if (logger === false) logger = nullLogger;
|
||||
return {
|
||||
...newOptions, logger,
|
||||
};
|
||||
};
|
||||
|
||||
// null logger for options.logger = false
|
||||
const nullLogger = {
|
||||
log: () => {},
|
||||
error: () => {},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
plot,
|
||||
writePngToFile,
|
||||
|
||||
Reference in new issue
Block a user