mirror of
https://github.com/netbymatt/nexrad-level-2-plot.git
synced 2026-11-28 18:28:05 -08:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dcc07e5bf7 |
No files matched your search
Binary file not shown.
@@ -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 = [];
|
||||
|
||||
+20
-17
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user