Gianpaolo Coro 2014-02-26 00:02:47 +00:00
parent 57f150e546
commit eadc863c18
1 changed files with 73 additions and 31 deletions

View File

@ -1,6 +1,10 @@
package org.gcube.dataanalysis.geo.utils;
import java.util.ArrayList;
import java.util.List;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
import org.gcube.dataanalysis.ecoengine.utils.Tuple;
import ucar.ma2.ArrayByte;
import ucar.ma2.ArrayDouble;
@ -8,7 +12,6 @@ import ucar.ma2.IndexIterator;
public class VectorTransformations {
public static ArrayDouble.D2 arrayByte2DArrayDouble(ArrayByte bytes) {
int[] shapeD = bytes.getShape();
int yD = shapeD[0];
@ -26,7 +29,6 @@ public class VectorTransformations {
return doublea;
}
public static ArrayDouble.D3 arrayByte3DArrayDouble(ArrayByte bytes) {
int[] shapeD = bytes.getShape();
int zD = shapeD[0];
@ -49,5 +51,45 @@ public class VectorTransformations {
return doublea;
}
/**
* Finds the best association between a grid of 3d points in a certain time instant and a set of 5 dimensional points. each tuple is expected to be formed by (x,y,z,t,value) in 5 dimensions and by (x,y,z) in 3 dimensions
**/
// suggestion: given a resolution R, give Math.sqrt(2)*R/2=0.7*R as tolerance
public static List<Double> assignPointsValuesToGrid(List<Tuple<Double>> grid3d, int gridTimeInstant, List<Tuple<Double>> coordinates5d, double tolerance) {
List<Double> valuesForGrid = new ArrayList<Double>();
int gridSize = grid3d.size();
for (int i = 0; i < gridSize; i++) {
valuesForGrid.add(Double.NaN);
}
for (Tuple<Double> coord5d : coordinates5d) {
double rx = coord5d.getElements().get(0);
double ry = coord5d.getElements().get(1);
double rz = coord5d.getElements().get(2);
double rt = coord5d.getElements().get(3);
double rvalue = coord5d.getElements().get(4);
int gridIdx = 0;
for (Tuple<Double> coord3d : grid3d) {
double x = coord3d.getElements().get(0);
double y = coord3d.getElements().get(1);
double z = coord3d.getElements().get(2);
double d = distance(x, y, z, gridTimeInstant, rx, ry, rz, rt);
if (d <= tolerance) {
// AnalysisLogger.getLogger().debug("Association: distance between grid:("+x+","+y+","+z+","+gridTimeInstant+") and point:("+rx+","+ry+","+rz+","+rt+") is "+d);
valuesForGrid.set(gridIdx, rvalue);
}
gridIdx++;
}
}
return valuesForGrid;
}
public static double distance(double x1, double y1, double z1, double t1, double x2, double y2, double z2, double t2) {
return Math.sqrt(((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2)) + ((z1 - z2) * (z1 - z2)) + ((t1 - t2) * (t1 - t2)));
}
}