Published
Edited
Dec 7, 2020
2 forks
8 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
interpolation_result = {
let initRegressionFieldDate = new Date();
let gpu = new GPU.GPU();
const calculateInterp = gpu.createKernel(function(altitude, dist, regrCoefs) {
return regrCoefs[0] + regrCoefs[1] * altitude[this.thread.y][this.thread.x] + regrCoefs[2] * dist[this.thread.y][this.thread.x];
})
.setOutput([fixData.xSize, fixData.ySize]);
let interpResult = calculateInterp(
GPU.input(Float32Array.from(fixData.data[1]), [1000, 970]),
GPU.input(Float32Array.from(fixData.data[0]), [1000, 970]),
regression_result.beta);
viewof regression_field_time.value = new Date() - initRegressionFieldDate;
return interpResult;
}
Insert cell
regression = data => {
let result = {};
const conv = convertData(data);
const X = conv.X;
const Y = conv.Y
const X_T = numeric.transpose(X);
const multipliedXMatrix = numeric.dot(X_T,X);
const LeftSide = numeric.inv(multipliedXMatrix);
const RightSide = numeric.dot(X_T,Y);
result.beta = numeric.dot(LeftSide,RightSide);
const yhat = numeric.dot(X, result.beta);
result.residual = numeric.sub(Y, yhat);
return result;
}
Insert cell
Insert cell
Insert cell
residuals_result = {
let initResidualsFieldDate = new Date();
let xPos = station_data.map(d => {return (d.lon - fixData.geoTransform[0])/fixData.geoTransform[1];});
let yPos = station_data.map(d => {return (d.lat - fixData.geoTransform[3])/fixData.geoTransform[5];});
let gpu = new GPU.GPU();
const calculateResidues = gpu.createKernel(function(xpos, ypos, values) {
let nominator=0;
let denominator=0;
let flagDist = -1;

for (let i = 0; i < this.constants.numPoints; i++) {

let dist = 5 + Math.sqrt((this.thread.x-xpos[i])*(this.thread.x-xpos[i])+
(this.thread.y-ypos[i])*(this.thread.y-ypos[i]) + 2);
nominator=nominator+(values[i]/dist)
denominator=denominator+(1/dist)

}
return nominator/denominator;

})
.setConstants({ numPoints: xPos.length, tiffWidth: fixData.xSize, tiffHeight: fixData.ySize })
.setOutput([fixData.xSize, fixData.ySize]);
let residualsResult = calculateResidues(xPos, yPos, regression_result.residual);
viewof residuals_field_time.value = new Date() - initResidualsFieldDate;
return residualsResult;
}
Insert cell
final_result = {
let initFinalFieldDate = new Date();

let gpu = new GPU.GPU();
const addResidues = gpu.createKernel(function(interpResult, residuesResult) {
return interpResult[this.thread.y][this.thread.x] - residuesResult[this.thread.y][this.thread.x];
})
.setOutput([fixData.xSize, fixData.ySize]);
let temperatureField = addResidues(interpolation_result, residuals_result);
viewof final_field_time.value = new Date() - initFinalFieldDate;
return temperatureField;
}
Insert cell
Insert cell
station_data = (await fetch("https://cdn.rawgit.com/rveciana/sigte2018/gh-pages/ml/station_data.json")).json()
Insert cell
fixData = {
let tiff_data = await (await fetch("https://cdn.rawgit.com/rveciana/sigte2018/gh-pages/ml/vars.tiff")).arrayBuffer();
let tiff = await GeoTIFF.fromArrayBuffer(tiff_data);
let image = await tiff.getImage();
let origin = image.getOrigin();
let resolution = image.getResolution();
let geoTransform = [origin[0], resolution[0], 0, origin[1], 0, resolution[1]];
let invGeoTransform = [-geoTransform[0]/geoTransform[1], 1/geoTransform[1],0,-geoTransform[3]/geoTransform[5],0,1/geoTransform[5]];
let data = await image.readRasters();
return {"data": data, "geoTransform": geoTransform, "invGeoTransform": invGeoTransform, "xSize": image.getWidth(), "ySize": image.getHeight()};
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
GeoTIFF = require("geotiff@1.0.0-beta.6/dist/geotiff.bundle.min.js")
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more