Skip to content

fix bugs #19

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@


## 更新
修改了data文件夹内shell脚本及处理数据用的prepare.js文件,使脚本可正常运行



## WebGL Wind — [Demo](https://mapbox.github.io/webgl-wind/demo/)

A WebGL-powered visualization of wind power.
Expand Down Expand Up @@ -25,6 +32,6 @@ npm start

### Downloading weather data

1. Install [ecCodes](https://confluence.ecmwf.int//display/ECC/ecCodes+Home) (e.g. `brew install eccodes`).
1. Install [ecCodes](https://confluence.ecmwf.int//display/ECC/ecCodes+Home) (e.g. `brew install eccodes`)(如果是ubuntu可以运行命令:`apt install libeccodes-tools`).
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.
7 changes: 4 additions & 3 deletions data/download.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/bin/bash

GFS_DATE="20161120"
GFS_DATE="20220615"
GFS_TIME="00"; # 00, 06, 12, 18
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}"
#更改了数据下载URL
GFS_URL="https://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}%2F${GFS_TIME}%2Fatmos"

curl "${GFS_URL}&var_UGRD=on" -o utmp.grib
curl "${GFS_URL}&var_VGRD=on" -o vtmp.grib
Expand All @@ -18,6 +19,6 @@ printf "{\"u\":`grib_dump -j utmp.grib`,\"v\":`grib_dump -j vtmp.grib`}" > tmp.j
rm utmp.grib vtmp.grib

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

rm tmp.json
30 changes: 21 additions & 9 deletions data/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,20 @@ const name = process.argv[2];
const u = data.u;
const v = data.v;

const width = u.Ni;
const height = u.Nj - 1;
const udataDate=u.messages[0].find((temp)=>{return temp.key=='dataDate'}).value;
const udataTime=u.messages[0].find((temp)=>{return temp.key=='dataTime'}).value;

const uminimum=u.messages[0].find((temp)=>{return temp.key=='minimum'}).value;
const umaximum=u.messages[0].find((temp)=>{return temp.key=='maximum'}).value;

const vminimum=v.messages[0].find((temp)=>{return temp.key=='minimum'}).value;
const vmaximum=v.messages[0].find((temp)=>{return temp.key=='maximum'}).value;

const uvalues=u.messages[0].find((temp)=>{return temp.key=='values'}).value;
const vvalues=v.messages[0].find((temp)=>{return temp.key=='values'}).value;

const width = u.messages[0].find((temp)=>{return temp.key=='Ni'}).value;
const height = u.messages[0].find((temp)=>{return temp.key=='Nj'}).value-1;

const png = new PNG({
colorType: 2,
Expand All @@ -20,8 +32,8 @@ for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
const i = (y * width + x) * 4;
const k = y * width + (x + width / 2) % width;
png.data[i + 0] = Math.floor(255 * (u.values[k] - u.minimum) / (u.maximum - u.minimum));
png.data[i + 1] = Math.floor(255 * (v.values[k] - v.minimum) / (v.maximum - v.minimum));
png.data[i + 0] = Math.floor(255 * (uvalues[k] - uminimum) / (umaximum - uminimum));
png.data[i + 1] = Math.floor(255 * (vvalues[k] - vminimum) / (vmaximum - vminimum));
png.data[i + 2] = 0;
png.data[i + 3] = 255;
}
Expand All @@ -31,13 +43,13 @@ png.pack().pipe(fs.createWriteStream(name + '.png'));

fs.writeFileSync(name + '.json', JSON.stringify({
source: 'http://nomads.ncep.noaa.gov',
date: formatDate(u.dataDate + '', u.dataTime),
date: formatDate(udataDate + '', udataTime),
width: width,
height: height,
uMin: u.minimum,
uMax: u.maximum,
vMin: v.minimum,
vMax: v.maximum
uMin: uminimum,
uMax: umaximum,
vMin: vminimum,
vMax: vmaximum
}, null, 2) + '\n');

function formatDate(date, time) {
Expand Down