Permalink
Cannot retrieve contributors at this time
Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign up
Fetching contributors…
| const PNG = require('pngjs').PNG; | |
| 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 width = u.Ni; | |
| const height = u.Nj - 1; | |
| const png = new PNG({ | |
| colorType: 2, | |
| filterType: 4, | |
| width: width, | |
| height: height | |
| }); | |
| 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 + 2] = 0; | |
| png.data[i + 3] = 255; | |
| } | |
| } | |
| 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), | |
| width: width, | |
| height: height, | |
| uMin: u.minimum, | |
| uMax: u.maximum, | |
| vMin: v.minimum, | |
| vMax: v.maximum | |
| }, null, 2) + '\n'); | |
| function formatDate(date, time) { | |
| return date.substr(0, 4) + '-' + date.substr(4, 2) + '-' + date.substr(6, 2) + 'T' + | |
| (time < 10 ? '0' + time : time) + ':00Z'; | |
| } |