don't plot outside crop area

This commit is contained in:
Matt Walsh committed 2021-08-11 11:05:46 -05:00
1 parent 3fa526c96a
commit 7652e9fb81
3 files changed
+30 -18

No files matched your search

+1
View File
@@ -5,6 +5,7 @@
},
"cSpell.words": [
"KLOT",
"Mult",
"NOAA",
"Palettized",
"RGBA",
+17 -16
View File
@@ -6,8 +6,8 @@ const { plot, writePngToFile } = require('../src');
// 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/381/*');
const files = glob.sync('./data/KLOT/548/*');
// const files = glob.sync('./data/KLOT/940/*');
// const files = glob.sync('./data/KSRX/804/*');
// const files = glob.sync('./data/TORD/767/*');
@@ -29,20 +29,21 @@ const plots = [];
// plot for each elevation and size
(async () => {
await Promise.allSettled([3600, 1800, 900, 450, 100].map(async (size) => {
await Promise.allSettled(radarData.listElevations().map(async (elevation) => {
plots[elevation] = plot(radarData, ['REF', 'VEL'], {
elevation,
size,
palettize: true,
cropTo: size / 2,
});
await Promise.allSettled([3600, 1800, 900, 800, 600, 450, 100].map(async (size) => {
// await Promise.allSettled(radarData.listElevations().map(async (elevation) => {\
const elevation = radarData.listElevations()[0];
plots[elevation] = plot(radarData, ['REF', 'VEL'], {
elevation,
size,
palettize: true,
cropTo: size / 2,
});
// write files to disk
await Promise.allSettled([
writePngToFile(`./output/REF-${elevation}-${size}.png`, plots[elevation].REF),
writePngToFile(`./output/VEL-${elevation}-${size}.png`, plots[elevation].VEL),
]);
}));
// write files to disk
await Promise.allSettled([
writePngToFile(`./output/REF-${elevation}-${size}.png`, plots[elevation].REF),
writePngToFile(`./output/VEL-${elevation}-${size}.png`, plots[elevation].VEL),
]);
// }));
}));
})();
+12 -2
View File
@@ -38,6 +38,10 @@ const DEFAULT_OPTIONS = {
lineWidth: 2,
};
// calculation constants
const RAD45 = (45 * Math.PI / 180);
const RAD90 = RAD45 * 2;
const draw = (data, _options) => {
// combine options with defaults
const options = {
@@ -113,9 +117,15 @@ const draw = (data, _options) => {
let lastRemainder = 0;
// calculate maximum bin to plot based on azimuth
const azWrap = startAngle % (Math.PI / 2);
const cropMaxBin = Math.ceil(Math.abs(cropTo / Math.cos(azWrap)) - 50);
// wrap azimuth to 90° offset by -45° (% in js is remainder, the formula below make it in to modulus)
const azWrap = (((startAngle - 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));
// compare max calculated value with length of radial
const maxBin = Math.min(cropMaxBin, thisRadial.moment_data.length);
// plot each bin
for (let idx = 0; idx < maxBin; idx += 1) {
// get the value