Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ npm start

1. Install [ecCodes](https://confluence.ecmwf.int//display/ECC/ecCodes+Home) (e.g. `brew install eccodes`).
2. Edit constants in `data/download.sh` for desired date, time and resolution.
3. Run `./data/download.sh <dir>` to generate wind data files (`png` and `json`) for use with the library.
3. Run `./data/download.sh demo/wind 20210627 00` to generate wind data files (`png` and `json`) for use with the library.
4. Modify the `windFiles`, object in demo/index.js to reference the new dataset
1. Object keys are offsets in hours from the first date/time
2. The label for the GUI control is in the `meta` object
3. The min, max, and interval for the GUI control are on the `gui.add(meta, ...)` line
44 changes: 35 additions & 9 deletions data/download.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,49 @@
#!/bin/bash

GFS_DATE="20161120"
GFS_TIME="00"; # 00, 06, 12, 18
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

function usage() {
cat <<EOF
usage: download.sh <directory> [<date> <hour>]
e.g. download.sh demo/wind 20210701 00
EOF
}

if ! [ -d "${1}" ]; then
echo "error: directory does not exist" >&2
usage >&2
exit 2
fi
cd "${1}"

# Default date & time is 2021-07-01 at 00 hours
GFS_DATE="${2:=20210701}"
GFS_TIME="${3:=00}"; # 00, 06, 12, 18

if ! echo "${GFS_DATE}${GFS_TIME}" | egrep -q '^[0-9]{10}$'; then
echo "error: incorrect date / time format" >&2
usage >&2
exit 2
fi

RES="1p00" # 0p25, 0p50 or 1p00
BBOX="leftlon=0&rightlon=360&toplat=90&bottomlat=-90"
LEVEL="lev_10_m_above_ground=on"
GFS_URL="http://nomads.ncep.noaa.gov/cgi-bin/filter_gfs_${RES}.pl?file=gfs.t${GFS_TIME}z.pgrb2.${RES}.f000&${LEVEL}&${BBOX}&dir=%2Fgfs.${GFS_DATE}${GFS_TIME}"
GFS_URL="https://nomads.ncep.noaa.gov/cgi-bin/filter_gfs_${RES}.pl?file=gfs.t${GFS_TIME}z.pgrb2.${RES}.anl&lev_max_wind=on&${BBOX}&dir=%2Fgfs.${GFS_DATE}%2F${GFS_TIME}%2Fatmos"


curl "${GFS_URL}&var_UGRD=on" -o utmp.grib
curl "${GFS_URL}&var_VGRD=on" -o vtmp.grib
curl -L "${GFS_URL}&var_UGRD=on" -o utmp.grib
curl -L "${GFS_URL}&var_VGRD=on" -o vtmp.grib

grib_set -r -s packingType=grid_simple utmp.grib utmp.grib
grib_set -r -s packingType=grid_simple vtmp.grib vtmp.grib
grib_set -r -s packingType=grid_simple utmp.grib utmp.grib.new
grib_set -r -s packingType=grid_simple vtmp.grib vtmp.grib.new
mv utmp.grib.new utmp.grib
mv vtmp.grib.new vtmp.grib

printf "{\"u\":`grib_dump -j utmp.grib`,\"v\":`grib_dump -j vtmp.grib`}" > tmp.json

rm utmp.grib vtmp.grib

DIR=`dirname $0`
node ${DIR}/prepare.js ${1}/${GFS_DATE}${GFS_TIME}
node ${DIR}/prepare.js ./${GFS_DATE}${GFS_TIME}

rm tmp.json
17 changes: 14 additions & 3 deletions data/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,19 @@ const fs = require('fs');

const data = JSON.parse(fs.readFileSync('tmp.json'));
const name = process.argv[2];
const u = data.u;
const v = data.v;



const umessage = data.u.messages[0];
const vmessage = data.v.messages[0];

const unpack = (message) =>
message.reduce((acc, { key, value }) => ({ ...acc, [key]: value }), {});
const u = unpack(umessage);
const v = unpack(vmessage);




const width = u.Ni;
const height = u.Nj - 1;
Expand All @@ -29,7 +40,7 @@ for (let y = 0; y < height; y++) {

png.pack().pipe(fs.createWriteStream(name + '.png'));

fs.writeFileSync(name + '.json', JSON.stringify({
fs.writeFileSync('./' + name + '.json', JSON.stringify({
source: 'http://nomads.ncep.noaa.gov',
date: formatDate(u.dataDate + '', u.dataTime),
width: width,
Expand Down
18 changes: 7 additions & 11 deletions demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,21 @@ gui.add(wind, 'dropRate', 0, 0.1);
gui.add(wind, 'dropRateBump', 0, 0.2);

const windFiles = {
0: '2016112000',
6: '2016112006',
12: '2016112012',
18: '2016112018',
24: '2016112100',
30: '2016112106',
36: '2016112112',
42: '2016112118',
48: '2016112200'
0: '2021062700',
24: '2021062800',
48: '2021062900',
72: '2021063000',
96: '2021070100'
};

const meta = {
'2016-11-20+h': 0,
'2021-06-27+h': 0,
'retina resolution': true,
'github.com/mapbox/webgl-wind': function () {
window.location = 'https://github.com/mapbox/webgl-wind';
}
};
gui.add(meta, '2016-11-20+h', 0, 48, 6).onFinishChange(updateWind);
gui.add(meta, '2021-06-27+h', 0, 96, 24).onFinishChange(updateWind);
if (pxRatio !== 1) {
gui.add(meta, 'retina resolution').onFinishChange(updateRetina);
}
Expand Down
10 changes: 0 additions & 10 deletions demo/wind/2016112000.json

This file was deleted.

Binary file removed demo/wind/2016112000.png
Binary file not shown.
10 changes: 0 additions & 10 deletions demo/wind/2016112006.json

This file was deleted.

Binary file removed demo/wind/2016112006.png
Binary file not shown.
10 changes: 0 additions & 10 deletions demo/wind/2016112012.json

This file was deleted.

Binary file removed demo/wind/2016112012.png
Binary file not shown.
10 changes: 0 additions & 10 deletions demo/wind/2016112018.json

This file was deleted.

Binary file removed demo/wind/2016112018.png
Binary file not shown.
10 changes: 0 additions & 10 deletions demo/wind/2016112100.json

This file was deleted.

Binary file removed demo/wind/2016112100.png
Binary file not shown.
10 changes: 0 additions & 10 deletions demo/wind/2016112106.json

This file was deleted.

Binary file removed demo/wind/2016112106.png
Binary file not shown.
10 changes: 0 additions & 10 deletions demo/wind/2016112112.json

This file was deleted.

Binary file removed demo/wind/2016112112.png
Binary file not shown.
10 changes: 0 additions & 10 deletions demo/wind/2016112118.json

This file was deleted.

Binary file removed demo/wind/2016112118.png
Binary file not shown.
10 changes: 0 additions & 10 deletions demo/wind/2016112200.json

This file was deleted.

Binary file removed demo/wind/2016112200.png
Binary file not shown.
10 changes: 10 additions & 0 deletions demo/wind/2021062700.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"source": "http://nomads.ncep.noaa.gov",
"date": "2021-06-27T00:00Z",
"width": 360,
"height": 180,
"uMin": -49.9619,
"uMax": 101.538,
"vMin": -75.6065,
"vMax": 65.2935
}
Binary file added demo/wind/2021062700.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions demo/wind/2021062800.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"source": "http://nomads.ncep.noaa.gov",
"date": "2021-06-28T00:00Z",
"width": 360,
"height": 180,
"uMin": -51.4175,
"uMax": 87.2825,
"vMin": -63.9471,
"vMax": 70.3529
}
Binary file added demo/wind/2021062800.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions demo/wind/2021062900.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"source": "http://nomads.ncep.noaa.gov",
"date": "2021-06-29T00:00Z",
"width": 360,
"height": 180,
"uMin": -59.0631,
"uMax": 94.7369,
"vMin": -66.5897,
"vMax": 70.7103
}
Binary file added demo/wind/2021062900.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions demo/wind/2021063000.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"source": "http://nomads.ncep.noaa.gov",
"date": "2021-06-30T00:00Z",
"width": 360,
"height": 180,
"uMin": -59.8576,
"uMax": 98.1424,
"vMin": -68.6488,
"vMax": 76.2512
}
Binary file added demo/wind/2021063000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions demo/wind/2021070100.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"source": "http://nomads.ncep.noaa.gov",
"date": "2021-07-01T00:00Z",
"width": 360,
"height": 180,
"uMin": -56.0845,
"uMax": 96.3155,
"vMin": -69.8492,
"vMax": 68.2508
}
Binary file added demo/wind/2021070100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.