diff --git a/data/non-hi-res/KLOT19950413_132143.gz b/data/non-hi-res/KLOT19950413_132143.gz new file mode 100644 index 0000000..84a5272 Binary files /dev/null and b/data/non-hi-res/KLOT19950413_132143.gz differ diff --git a/demos/test.js b/demos/test.js index 8728a52..5f1b642 100644 --- a/demos/test.js +++ b/demos/test.js @@ -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 = []; diff --git a/src/draw/index.js b/src/draw/index.js index 202ea19..9c433b8 100644 --- a/src/draw/index.js +++ b/src/draw/index.js @@ -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(); } diff --git a/src/draw/preprocess/filterproduct.js b/src/draw/preprocess/filterproduct.js index acc32da..4c4c6ec 100644 --- a/src/draw/preprocess/filterproduct.js +++ b/src/draw/preprocess/filterproduct.js @@ -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;