forked from oeo4b/kriging.js
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
52 lines (48 loc) · 1.29 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const fs = require('fs-extra');
const kriging = require('.');
// With Promises:
fs.readJson('./examples/csvjson.json')
.then(res => {
// console.log(res);
const lngs = [];
const lats = [];
const values = [];
for (let i = 0; i < res.length; i++) {
const temp = res[i].temp;
const x = res[i].lon;
const y = res[i].lat;
if (temp !== 999999 && i < 500) {
const x1 = Number(x);
const y1 = Number(y);
const z1 = Number(temp);
if (x1 && y1 && z1 !== undefined && !isNaN(z1)) {
lngs.push(x1);
lats.push(y1);
values.push(z1);
}
}
}
console.time('train');
const variogram = kriging.train(values, lngs, lats, 'exponential', 0, 100);
console.timeEnd('train');
// console.log(variogram);
const mathGrid = true;
if (mathGrid) {
const extent = [
63.81489, 12.770034,
143.53648, 56.38334,
];
console.time('grid');
const vgrid = kriging.grid([
[
[extent[0], extent[1]], [extent[0], extent[3]],
[extent[2], extent[3]], [extent[2], extent[1]],
],
], variogram, 0.3986079500000001);
console.timeEnd('grid');
// console.log(vgrid);
}
})
.catch(err => {
console.error(err)
});