Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weather for a region is not positioned correcly #46

Closed
turban opened this issue Mar 7, 2020 · 7 comments
Closed

Weather for a region is not positioned correcly #46

turban opened this issue Mar 7, 2020 · 7 comments

Comments

@turban
Copy link

turban commented Mar 7, 2020

Thanks for a great plugin!

I've created wind data for a region and added to a Leaflet map using this plugin:
http://mastermaps.com/racetracker/hardangervidda.html

I'm reading the bounds from the JSON-file and they are correct when I draw a rectangle and zoom the map to these bounds. The wind layer is displayed below the correct position:

Screenshot 2020-03-07 at 16 34 00

Is this a know issue?

@brentfraser
Copy link
Contributor

The problem is the "scanMode" in the json (and grib) file. Currently only scanMode: 0 is supported.
If your scanMode: 64, a quick fix is to modify the json file to set "dy": -0.25 so the Y direction is incremented in the opposite direction.

A better fix is to modify the leaflet-velocity JavaScript to interpret the scanMode and adjust the parameters appropriately (and maybe just support a subset of scanModes). For example, around line 530:
if (header.scanMode === 64) Δφ = -Δφ;

But really we should decode the scanMode bits and give a message for those we don't support.

@brentfraser
Copy link
Contributor

A slightly better (but not tested) fix, at line 530:

    
    var scanModeMask = header.scanMode.toString(2)
    scanModeMask = ('0'+scanModeMask).slice(-8);
    var scanModeMaskArray = scanModeMask.split('').map(Number).map(Boolean);
    var supported = true;	
    if (scanModeMaskArray[0]) Δλ =-Δλ;
    if (scanModeMaskArray[1]) Δφ = -Δφ;
    if (scanModeMaskArray[2]) supported = false;
    if (scanModeMaskArray[3]) supported = false;
    if (scanModeMaskArray[4]) supported = false;
    if (scanModeMaskArray[5]) supported = false;
    if (scanModeMaskArray[6]) supported = false;
    if (scanModeMaskArray[7]) supported = false;
    if (!supported) console.log("Data with scanMode: "+header.scanMode+ " is not supported.");

@d03090
Copy link

d03090 commented Mar 14, 2020

Thank you very much for this solution! I was struggling with this scanMode as well. So, this worked fine for me!

Still not exactly sure why scanMode 64 (01000000) affects Bit No. 2 and not No. 7 though (why is this flipped?).

@brentfraser
Copy link
Contributor

I think it is a LSB/MSB thing. I guess I could reorder the scanModeMaskArray in the above code to match the bits in the table https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table3-4.shtml

@turban
Copy link
Author

turban commented Mar 15, 2020

Thanks @brentfraser! Your quick-fix solution worked :-)

@danwild
Copy link
Contributor

danwild commented Mar 15, 2020

Thanks @brentfraser, please consider putting in a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants