netbymatt / nexrad-level-2-plot

Plot nexrad level 2 radar data
MIT License
6 stars 2 forks source link

[bug] Error: No product found for product type: SW #3

Closed SteepAtticStairs closed 2 years ago

SteepAtticStairs commented 2 years ago

I have been trying to get this library to work for me, but no luck so far.

I spent a long time on the error telling me that data.listElevations() was not a function, but that was because I was passing the output of fs.readFileSync() to plot(), not new Level2Radar() as I should have been doing.

However, I am now stuck on a new error. I am using this file with the path demos/myTest.js:

const fs = require('fs');
const { plot, writePngToFile } = require('../src');
const { Level2Radar } = require('nexrad-level-2-data')

const rawData = fs.readFileSync('KCRP20170825_235733_V06');
var l2rad = new Level2Radar(rawData)

// parse and plot
const level2Plot = plot(l2rad, {elevation: 1, product: 'REF'});
// use bundled utility to write to disk
(async () => {
    await writePngToFile('output.png', level2Plot.REF.canvas);
})();

but I am getting this output:

$ node myTest.js

/Users/me/Downloads/nexrad-level-2-plot/src/draw/index.js:103
        if (!palette) throw new Error(`No product found for product type: ${options.product}`);
                      ^

Error: No product found for product type: SW 
    at draw (/Users/me/Downloads/nexrad-level-2-plot/src/draw/index.js:103:22)
    at /Users/me/Downloads/nexrad-level-2-plot/src/index.js:45:31
    at Array.forEach (<anonymous>)
    at /Users/me/Downloads/nexrad-level-2-plot/src/index.js:43:12
    at Array.forEach (<anonymous>)
    at plot (/Users/me/Downloads/nexrad-level-2-plot/src/index.js:41:13)
    at Object.<anonymous> (/Users/me/Downloads/nexrad-level-2-plot/demos/myTest.js:9:20)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)

Do you have any idea what I am doing wrong, or how I can fix it?

Here is the download link to the radar file I am using, KCRP20170825_235733_V06. https://noaa-nexrad-level2.s3.amazonaws.com/2017/08/25/KCRP/KCRP20170825_235733_V06

SteepAtticStairs commented 2 years ago

I wrote this issue with something similar to a big report in mind, so to me the "bug" label is what I would have added. Although if you purposely added the enhancement label, sorry for misunderstanding!

netbymatt commented 2 years ago

Good news, I can recreate this. I'll take a look into what's going on. The enhancement label was an errant click when I first was reading through the issue.

SteepAtticStairs commented 2 years ago

Awesome - I have been looking for a javascript implementation of NEXRAD data and yours is the only one that has been able to decode the binary data into readable numbers, I'm just having trouble plotting them with this library.

Your repository nexrad-level-3-plot works fine for me - I'm currently working on adding more color pallets for unsupported products. I might open up an issue there if I have trouble.

netbymatt commented 2 years ago

The example in the documentation had become out of date, but the specifics listed in the API section of the readme were correct. Here is corrected code.

const fs = require('fs');
const { plot, writePngToFile } = require('nexrad-level-2-plot');
const { Level2Radar } = require('nexrad-level-2-data')

const rawData = fs.readFileSync('KCRP20170825_235733_V06');
var l2rad = new Level2Radar(rawData)

// parse and plot
const level2Plot = plot(l2rad, 'REF', {elevations: 1});
// use bundled utility to write to disk
(async () => {
        await writePngToFile('output.png', level2Plot[0].REF);
})();

The two changes are the signature for plot(l2rad, 'REF', {elevation: 1}); where the product is now the second argument instead of inside the options block. This is the initial problem you were experiencing where it would try to plot all products and throw an error when it got to SW. elevation also changes to elevations. Both of these can use a single value, or an array of values if needed.

After adjusting that line, I then had to change await writePngToFile('output.png', level2Plot[0].REF); to select index 0 in the result and the REF property.

Your example and data produce a nice plot of hurricane Harvey!

SteepAtticStairs commented 2 years ago

Thanks!!! You're a lifesaver - it works perfectly. It is a nice scan of Harvey - that is the radar file I always use while testing 😁

netbymatt commented 2 years ago

Just out of curiosity I looked a little into the output of the -data package. This particular data set has lowest elevation data in 4 places: elevation numbers 1 (REF), 2 (VEL), 9 (REF), 10 (VEL).

I learned about this the hard way when putting this into production and the weather.gov and my favorite Android app were showing radar timestamps between what only plotting elevation 1 was producing. The reasoning behind this is MESO-SAILS.

My production workflow does something along these lines:

  1. Parse the data with nexrad-level-2-data
  2. Iterate through l2rad.vcp.elevations and find all the elevations that have the lowest elevation_angle.
  3. Pass all of the lowest elevations to plot as {elevations: [1,2,9,10]}