git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-analysis/EcologicalEngineGeoSpatialExtension@76604 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
db36f7613a
commit
30eba80a83
|
@ -1,7 +1,11 @@
|
||||||
package org.gcube.dataanalysis.geo.algorithms;
|
package org.gcube.dataanalysis.geo.algorithms;
|
||||||
|
|
||||||
|
import java.awt.Image;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.gcube.contentmanagement.graphtools.plotting.graphs.GaussianDistributionGraph;
|
||||||
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
|
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
|
||||||
import org.gcube.contentmanagement.lexicalmatcher.utils.DatabaseFactory;
|
import org.gcube.contentmanagement.lexicalmatcher.utils.DatabaseFactory;
|
||||||
import org.gcube.dataanalysis.ecoengine.datatypes.DatabaseType;
|
import org.gcube.dataanalysis.ecoengine.datatypes.DatabaseType;
|
||||||
|
@ -15,6 +19,9 @@ import org.gcube.dataanalysis.geo.insertion.RasterTable;
|
||||||
import org.gcube.dataanalysis.geo.meta.features.FeaturesManager;
|
import org.gcube.dataanalysis.geo.meta.features.FeaturesManager;
|
||||||
import org.gcube.dataanalysis.geo.retrieval.GeoIntersector;
|
import org.gcube.dataanalysis.geo.retrieval.GeoIntersector;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
|
import org.jfree.data.function.NormalDistributionFunction2D;
|
||||||
|
import org.jfree.data.general.DatasetUtilities;
|
||||||
|
import org.jfree.data.xy.XYSeriesCollection;
|
||||||
import org.opengis.metadata.Metadata;
|
import org.opengis.metadata.Metadata;
|
||||||
|
|
||||||
public class MapsComparator extends StandardLocalExternalAlgorithm{
|
public class MapsComparator extends StandardLocalExternalAlgorithm{
|
||||||
|
@ -22,6 +29,8 @@ public class MapsComparator extends StandardLocalExternalAlgorithm{
|
||||||
static String layer1 = "LayerTitle_1";
|
static String layer1 = "LayerTitle_1";
|
||||||
static String layer2 = "LayerTitle_2";
|
static String layer2 = "LayerTitle_2";
|
||||||
static String zString = "Z";
|
static String zString = "Z";
|
||||||
|
static String t1 = "TimeIndex_1";
|
||||||
|
static String t2 = "TimeIndex_2";
|
||||||
static String valuesThr = "ValuesComparisonThreshold";
|
static String valuesThr = "ValuesComparisonThreshold";
|
||||||
|
|
||||||
protected SessionFactory dbConnection;
|
protected SessionFactory dbConnection;
|
||||||
|
@ -45,6 +54,11 @@ public class MapsComparator extends StandardLocalExternalAlgorithm{
|
||||||
String layerT2 = getInputParameter(layer2);
|
String layerT2 = getInputParameter(layer2);
|
||||||
String z$ = getInputParameter(zString);
|
String z$ = getInputParameter(zString);
|
||||||
String valuesthr$ = getInputParameter(valuesThr);
|
String valuesthr$ = getInputParameter(valuesThr);
|
||||||
|
String time1$ = getInputParameter(t1);
|
||||||
|
String time2$ = getInputParameter(t2);
|
||||||
|
int time1 = ((time1$!=null) && (time1$.trim().length()>0))? Integer.parseInt(time1$):0;
|
||||||
|
int time2 = ((time2$!=null) && (time2$.trim().length()>0))? Integer.parseInt(time2$):0;
|
||||||
|
|
||||||
double valuesthreshold = 0.1;
|
double valuesthreshold = 0.1;
|
||||||
if ((valuesthr$!=null)&&(valuesthr$.trim().length()>0))
|
if ((valuesthr$!=null)&&(valuesthr$.trim().length()>0))
|
||||||
try{valuesthreshold =Double.parseDouble(valuesthr$);}catch(Exception ee){}
|
try{valuesthreshold =Double.parseDouble(valuesthr$);}catch(Exception ee){}
|
||||||
|
@ -58,7 +72,7 @@ public class MapsComparator extends StandardLocalExternalAlgorithm{
|
||||||
AnalysisLogger.getLogger().debug("MapsComparator: Using Scope: "+scope+" Z: "+z+" Values Threshold: "+valuesthreshold+" Layer1: "+layerT1+" vs "+layerT2);
|
AnalysisLogger.getLogger().debug("MapsComparator: Using Scope: "+scope+" Z: "+z+" Values Threshold: "+valuesthreshold+" Layer1: "+layerT1+" vs "+layerT2);
|
||||||
GeoIntersector intersector = new GeoIntersector(scope, config.getConfigPath());
|
GeoIntersector intersector = new GeoIntersector(scope, config.getConfigPath());
|
||||||
AnalysisLogger.getLogger().debug("MapsComparator: GeoIntersector initialized");
|
AnalysisLogger.getLogger().debug("MapsComparator: GeoIntersector initialized");
|
||||||
int t = 0;
|
|
||||||
double x1 = -180;
|
double x1 = -180;
|
||||||
double x2 = 180;
|
double x2 = 180;
|
||||||
double y1 = -90;
|
double y1 = -90;
|
||||||
|
@ -82,7 +96,7 @@ public class MapsComparator extends StandardLocalExternalAlgorithm{
|
||||||
AnalysisLogger.getLogger().debug("MapsComparator: Evaluation Resolution: "+resolution);
|
AnalysisLogger.getLogger().debug("MapsComparator: Evaluation Resolution: "+resolution);
|
||||||
|
|
||||||
AnalysisLogger.getLogger().debug("MapsComparator: ****Rasterizing map 1****");
|
AnalysisLogger.getLogger().debug("MapsComparator: ****Rasterizing map 1****");
|
||||||
double[][] slice1 = intersector.takeTimeSlice(layerT1, t, x1, x2, y1,y2,z,resolution,resolution);
|
double[][] slice1 = intersector.takeTimeSlice(layerT1, time1, x1, x2, y1,y2,z,resolution,resolution);
|
||||||
AnalysisLogger.getLogger().debug("MapsComparator: Dumping map 1");
|
AnalysisLogger.getLogger().debug("MapsComparator: Dumping map 1");
|
||||||
status = 30;
|
status = 30;
|
||||||
RasterTable raster1 = new RasterTable(x1, x2, y1, y2, z, resolution, resolution, slice1, config);
|
RasterTable raster1 = new RasterTable(x1, x2, y1, y2, z, resolution, resolution, slice1, config);
|
||||||
|
@ -91,7 +105,7 @@ public class MapsComparator extends StandardLocalExternalAlgorithm{
|
||||||
AnalysisLogger.getLogger().debug("MapsComparator: Map 1 was dumped in table: "+rastertable1);
|
AnalysisLogger.getLogger().debug("MapsComparator: Map 1 was dumped in table: "+rastertable1);
|
||||||
status = 40;
|
status = 40;
|
||||||
AnalysisLogger.getLogger().debug("MapsComparator: ****Rasterizing map 2****");
|
AnalysisLogger.getLogger().debug("MapsComparator: ****Rasterizing map 2****");
|
||||||
double[][] slice2 = intersector.takeTimeSlice(layerT2, t, x1, x2, y1,y2,z,resolution,resolution);
|
double[][] slice2 = intersector.takeTimeSlice(layerT2, time2, x1, x2, y1,y2,z,resolution,resolution);
|
||||||
AnalysisLogger.getLogger().debug("MapsComparator: Dumping map 2");
|
AnalysisLogger.getLogger().debug("MapsComparator: Dumping map 2");
|
||||||
status = 50;
|
status = 50;
|
||||||
RasterTable raster2 = new RasterTable(x1, x2, y1, y2, z, resolution, resolution, slice2, config);
|
RasterTable raster2 = new RasterTable(x1, x2, y1, y2, z, resolution, resolution, slice2, config);
|
||||||
|
@ -147,10 +161,13 @@ public class MapsComparator extends StandardLocalExternalAlgorithm{
|
||||||
@Override
|
@Override
|
||||||
protected void setInputParameters() {
|
protected void setInputParameters() {
|
||||||
|
|
||||||
addStringInput(layer1,"The title of a layer indexed in the e-Infrastructure on GeoNetwork","Sarda australis");
|
addStringInput(layer1,"First Layer Title: The title of a layer indexed in the e-Infrastructure on GeoNetwork","Sarda australis");
|
||||||
addStringInput(layer2,"The title of a second layer indexed in the e-Infrastructure on GeoNetwork","Sarda orientalis");
|
addStringInput(layer2,"Second Layer Title: The title of a second layer indexed in the e-Infrastructure on GeoNetwork","Sarda orientalis");
|
||||||
addNumberInput(zString,"value of Z. Default is 0, that means comparison will be at surface level","0");
|
addNumberInput(zString,"value of Z. Default is 0, that means comparison will be at surface level","0");
|
||||||
addNumberInput(valuesThr,"A comparison threshold for the values in the map. Null equals to 0.1","0.1");
|
addNumberInput(valuesThr,"A comparison threshold for the values in the map. Null equals to 0.1","0.1");
|
||||||
|
addNumberInput(t1,"First Layer Time Index. The default is the first","0");
|
||||||
|
addNumberInput(t2,"Second Layer Time Index. The default is the first","0");
|
||||||
|
|
||||||
DatabaseType.addDefaultDBPars(inputs);
|
DatabaseType.addDefaultDBPars(inputs);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -163,8 +180,37 @@ public class MapsComparator extends StandardLocalExternalAlgorithm{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StatisticalType getOutput() {
|
public StatisticalType getOutput() {
|
||||||
|
//set the output map containing values
|
||||||
PrimitiveType p = new PrimitiveType(Map.class.getName(), PrimitiveType.stringMap2StatisticalMap(outputParameters), PrimitiveTypes.MAP, "Discrepancy Analysis","");
|
PrimitiveType p = new PrimitiveType(Map.class.getName(), PrimitiveType.stringMap2StatisticalMap(outputParameters), PrimitiveTypes.MAP, "Discrepancy Analysis","");
|
||||||
return p;
|
AnalysisLogger.getLogger().debug("MapsComparator: Producing Gaussian Distribution for the errors");
|
||||||
|
//build image:
|
||||||
|
HashMap<String, Image> producedImages = new HashMap<String, Image>();
|
||||||
|
GaussianDistributionGraph gauss = new GaussianDistributionGraph("Error Distribution");
|
||||||
|
XYSeriesCollection xyseriescollection = new XYSeriesCollection();
|
||||||
|
double mean = Double.parseDouble(outputParameters.get("MEAN"));
|
||||||
|
double variance = Double.parseDouble(outputParameters.get("VARIANCE"));
|
||||||
|
|
||||||
|
AnalysisLogger.getLogger().debug("MapsComparator: Adopting mean:"+ mean+" and variance:"+variance);
|
||||||
|
|
||||||
|
NormalDistributionFunction2D normaldistributionfunction2d = new NormalDistributionFunction2D(mean,variance);
|
||||||
|
org.jfree.data.xy.XYSeries xyseries = DatasetUtilities.sampleFunction2DToSeries(normaldistributionfunction2d, 0, mean, 121, "NormalDistribution");
|
||||||
|
xyseriescollection.addSeries(xyseries);
|
||||||
|
producedImages.put("Gaussian Distribution of the Error", gauss.renderImgObject(680, 420, xyseriescollection));
|
||||||
|
PrimitiveType images = new PrimitiveType(HashMap.class.getName(), producedImages, PrimitiveTypes.IMAGES, "ErrorRepresentation", "Graphical representation of the error spread");
|
||||||
|
|
||||||
|
gauss.render(xyseriescollection);
|
||||||
|
//end build image
|
||||||
|
AnalysisLogger.getLogger().debug("MapsComparator: Gaussian Distribution Produced");
|
||||||
|
//collect all the outputs
|
||||||
|
LinkedHashMap<String, StatisticalType> map = new LinkedHashMap<String, StatisticalType>();
|
||||||
|
map.put("Result", p);
|
||||||
|
map.put("Images", images);
|
||||||
|
|
||||||
|
//generate a primitive type for the collection
|
||||||
|
PrimitiveType output = new PrimitiveType(HashMap.class.getName(), map, PrimitiveTypes.MAP, "ResultsMap", "Results Map");
|
||||||
|
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue