Compare commits

..
3 Commits
Author SHA1 Message Date
Matt Walsh dcc07e5bf7 add non-hi-res plot 2022-01-30 16:53:19 -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
7 changed files with 411 additions and 976 deletions

No files matched your search

Binary file not shown.
+1
View File
@@ -14,6 +14,7 @@ const { plot, writePngToFile } = require('../src');
// 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 files = glob.sync('./data/non-hi-res/*');
// const store each file's data
const chunks = [];
+365 -952
View File
File diff suppressed because it is too large. Load diff
+3 -3
View File
@@ -1,6 +1,6 @@
{
"name": "nexrad-level-2-plot",
"version": "1.1.0",
"version": "1.1.1",
"description": "Plotting library for nexrad-level-2-data",
"main": "src/index.js",
"scripts": {
@@ -28,8 +28,8 @@
"nexrad-level-2-data": "file:../nexrad-level-2-data"
},
"devDependencies": {
"eslint": "^7.32.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint": "^8.0.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.23.4",
"glob": "^7.1.7"
},
+20 -17
View File
@@ -60,20 +60,6 @@ const draw = (data, _options) => {
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
@@ -107,10 +93,27 @@ const draw = (data, _options) => {
const indexedProduct = indexProduct(downSampledProduct, palette);
const rrlEncoded = rrle(indexedProduct, resolution);
// 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);
// calculate a gate size against the nominal size
const gateScale = rrlEncoded[0].gate_size / 0.25;
// canvas settings
ctx.imageSmoothingEnabled = true;
ctx.lineWidth = options.lineWidth * gateScale;
ctx.translate(cropTo / 2, cropTo / 2);
ctx.rotate(-Math.PI / 2);
// loop through data
rrlEncoded.forEach((radial) => {
// calculate plotting parameters
const deadZone = radial.first_gate / radial.gate_size / scale;
const deadZone = radial.first_gate / radial.gate_size / scale * gateScale;
// 10% is added to the arc to ensure that each arc bleeds into the next just slightly to avoid radial empty spaces at further distances
const startAngle = radial.azimuth * (Math.PI / 180) - halfResolution * 1.1;
@@ -124,11 +127,11 @@ const draw = (data, _options) => {
if (bin.count) {
// rrle encoded
ctx.strokeStyle = palette.lookupRgba[bin.value];
ctx.arc(0, 0, (idx + deadZone), startAngle, endAngle + resolution * (bin.count - 1));
ctx.arc(0, 0, (idx + deadZone) * gateScale, startAngle, endAngle + resolution * (bin.count - 1));
} else {
// plain data
ctx.strokeStyle = palette.lookupRgba[bin];
ctx.arc(0, 0, (idx + deadZone), startAngle, endAngle);
ctx.arc(0, 0, (idx + deadZone) * gateScale, startAngle, endAngle);
}
ctx.stroke();
}
+1 -3
View File
@@ -6,7 +6,6 @@ const palettizeImage = (sourceCtx, palette) => {
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
@@ -19,11 +18,10 @@ const palettizeImage = (sourceCtx, palette) => {
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);
+21 -1
View File
@@ -5,7 +5,27 @@
const filterProduct = (data, product) => data.map((header) => {
// get correct data
const thisRadial = header[product];
let thisRadial = header[product];
// special case for non-hi-res data
// re-formats data to expected format
if (!thisRadial.moment_data && thisRadial) {
thisRadial = {
...header,
moment_data: header[product],
};
if (product === 'refelect') {
thisRadial.gate_size = header.surveillance_range_sample_interval;
thisRadial.gate_count = header.number_of_surveillance_bins;
} else {
thisRadial.gate_size = header.doppler_range_sample_interval;
thisRadial.gate_count = header.number_of_doppler_bins;
}
thisRadial.first_gate = 2;
}
// skip if this radial isn't found
if (thisRadial === undefined) return false;
thisRadial.azimuth = header.azimuth;