netbymatt / nexrad-level-2-plot

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

[documentation] Upscaling example #4

Closed SteepAtticStairs closed 2 years ago

SteepAtticStairs commented 2 years ago

In the README you say

options.size > 3600 is invalid as this would cause data to be interpolated and would not be a true representation of the data returned by the radar. If you need this functionality it's recommended to use an image scaling package such as jimp or gm on the Canvas returned by plot() which will also be much faster than the drawing methods used for a radar plot.

Do you have a way in mind you could achieve this with any of these libraries? Everything I could find was upscaling raster images, e.g. jpg or png - not canvas objects.

Perhaps exporting the canvas to a vector graphic might be easier, but I assume this would happen in src/draw/index.js.

netbymatt commented 2 years ago

My initial thought is to let the client do it. I don't know what your end product is but can the web browser, mobile app, OS image viewer, etc do that for you?

If not, I know Jimp can take a buffer directly. Without looking through all the documentation I believe it would be something like:

Jimp.read(level2Plot[1].REF.toBuffer()).resize(4000,4000);

A long time ago I did try SVG. I creates huge files so it wasn't practical for anything that I was doing with it.

SteepAtticStairs commented 2 years ago

Ah - thanks for the response. I tried what you said, and it ended up being

Jimp.read(level2Plot[0].REF.canvas.toBuffer(), (err, img) => {
        if (err) throw err;
        img
          .resize(4000, 4000) // resize
          .write('out.png'); // save
});

But what it seemed to do was just make the lower quality image in pixel size, not actually making the radar output quality better.

That would make massive files anyways, so maybe it's not doable.