From 595a668600d2c67c3d7ae2f31139024dc10a524b Mon Sep 17 00:00:00 2001 From: Gianpaolo Coro Date: Fri, 7 Jun 2013 17:08:35 +0000 Subject: [PATCH] enhanced the output git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-analysis/EcologicalEngineGeoSpatialExtension@76907 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../geo/algorithms/MapsComparator.java | 75 ++++++++++++------- 1 file changed, 49 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/gcube/dataanalysis/geo/algorithms/MapsComparator.java b/src/main/java/org/gcube/dataanalysis/geo/algorithms/MapsComparator.java index a95096e..bd9affb 100644 --- a/src/main/java/org/gcube/dataanalysis/geo/algorithms/MapsComparator.java +++ b/src/main/java/org/gcube/dataanalysis/geo/algorithms/MapsComparator.java @@ -1,6 +1,7 @@ package org.gcube.dataanalysis.geo.algorithms; import java.awt.Image; +import java.io.File; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; @@ -9,13 +10,16 @@ import java.util.Map; import org.gcube.contentmanagement.graphtools.data.conversions.ImageTools; import org.gcube.contentmanagement.graphtools.plotting.graphs.GaussianDistributionGraph; +import org.gcube.contentmanagement.graphtools.utils.MathFunctions; import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger; import org.gcube.contentmanagement.lexicalmatcher.utils.DatabaseFactory; import org.gcube.dataanalysis.ecoengine.configuration.AlgorithmConfiguration; import org.gcube.dataanalysis.ecoengine.datatypes.DatabaseType; +import org.gcube.dataanalysis.ecoengine.datatypes.OutputTable; import org.gcube.dataanalysis.ecoengine.datatypes.PrimitiveType; import org.gcube.dataanalysis.ecoengine.datatypes.StatisticalType; import org.gcube.dataanalysis.ecoengine.datatypes.enumtypes.PrimitiveTypes; +import org.gcube.dataanalysis.ecoengine.datatypes.enumtypes.TableTemplates; import org.gcube.dataanalysis.ecoengine.evaluation.DiscrepancyAnalysis; import org.gcube.dataanalysis.ecoengine.interfaces.DataAnalysis; import org.gcube.dataanalysis.ecoengine.utils.DatabaseUtils; @@ -164,7 +168,7 @@ public class MapsComparator extends DataAnalysis { da.setConfiguration(config); da.init(false); outputParameters = da.analyze(); - outputParameters.put("RESOLUTION", "" + resolution); + outputParameters.put("RESOLUTION", "" + MathFunctions.roundDecimal(resolution,4)); status = 80; AnalysisLogger.getLogger().debug("MapsComparator: Output: " + outputParameters); @@ -193,8 +197,8 @@ public class MapsComparator extends DataAnalysis { @Override public List getInputParameters(){ - IOHelper.addStringInput(inputs,layer1, "First Layer Title or UUID: The title or the UUID (preferred) of a layer indexed in the e-Infrastructure on GeoNetwork - You can retrieve it from GeoExplorer", "Sarda australis"); - IOHelper.addStringInput(inputs, layer2, "Second Layer Title or UUID: The title or the UUID (preferred) of a second layer indexed in the e-Infrastructure on GeoNetwork - You can retrieve it from GeoExplorer", "Sarda orientalis"); + IOHelper.addStringInput(inputs,layer1, "First Layer Title or UUID: The title or the UUID (preferred) of a layer indexed in the e-Infrastructure on GeoNetwork - You can retrieve it from GeoExplorer", "86a7ac79-866a-49c6-b5d5-602fc2d87ddd");//"Sarda australis"); + IOHelper.addStringInput(inputs, layer2, "Second Layer Title or UUID: The title or the UUID (preferred) of a second layer indexed in the e-Infrastructure on GeoNetwork - You can retrieve it from GeoExplorer", "0e03d0fa-9c44-4a0c-a7e3-9f6d48710d00");//"Sarda orientalis"); IOHelper.addIntegerInput(inputs, zString, "value of Z. Default is 0, that means comparison will be at surface level", "0"); IOHelper.addDoubleInput(inputs, valuesThr, "A comparison threshold for the values in the map. Null equals to 0.1", "0.1"); IOHelper.addIntegerInput(inputs, t1, "First Layer Time Index. The default is the first", "0"); @@ -212,39 +216,54 @@ public class MapsComparator extends DataAnalysis { } + + + + + + protected Image generateGaussian(double mean, double variance){ + // gaussian + XYSeriesCollection xyseriescollection = new XYSeriesCollection(); + if (variance == 0) + variance = 0.01; + 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, (mean - (2 * variance)), (mean + (2 * variance)), 121, "Distribution of the Error"); + xyseriescollection.addSeries(xyseries); + // end gaussian + + JFreeChart chart = GaussianDistributionGraph.createStaticChart(xyseriescollection, mean, variance); + Image image = ImageTools.toImage(chart.createBufferedImage(680, 420)); + /* + * GaussianDistributionGraph graph = new GaussianDistributionGraph("Error Distribution"); graph.mean=mean;graph.variance=variance; graph.render(xyseriescollection); + */ + // end build image + AnalysisLogger.getLogger().debug("MapsComparator: Gaussian Distribution Produced"); + return image; + } + @Override public StatisticalType getOutput() { + // set the output map containing values - PrimitiveType p = new PrimitiveType(Map.class.getName(), PrimitiveType.stringMap2StatisticalMap(outputParameters), PrimitiveTypes.MAP, "Discrepancy Analysis", ""); AnalysisLogger.getLogger().debug("MapsComparator: Producing Gaussian Distribution for the errors"); + // build image: HashMap producedImages = new HashMap(); - - // gaussian - XYSeriesCollection xyseriescollection = new XYSeriesCollection(); double mean = Double.parseDouble(outputParameters.get("MEAN")); double variance = Double.parseDouble(outputParameters.get("VARIANCE")); - if (variance == 0) - variance = 0.01; + producedImages.put("Error Distribution", generateGaussian(mean, variance)); + PrimitiveType images = new PrimitiveType("Images", producedImages, PrimitiveTypes.IMAGES, "Distribution of the Error", "The distribution of the error along with 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, (mean - (2 * variance)), (mean + (2 * variance)), 121, "Distribution of the Error"); - xyseriescollection.addSeries(xyseries); - // end gaussian - JFreeChart chart = GaussianDistributionGraph.createStaticChart(xyseriescollection, mean, variance); - Image image = ImageTools.toImage(chart.createBufferedImage(680, 420)); - producedImages.put("Gaussian Distribution of the Error", image); - - PrimitiveType images = new PrimitiveType(HashMap.class.getName(), producedImages, PrimitiveTypes.IMAGES, "ErrorRepresentation", "Graphical representation of the error spread"); - /* - * GaussianDistributionGraph graph = new GaussianDistributionGraph("Error Distribution"); graph.mean=mean;graph.variance=variance; graph.render(xyseriescollection); - */ - // end build image - AnalysisLogger.getLogger().debug("MapsComparator: Gaussian Distribution Produced"); - // collect all the outputs LinkedHashMap map = new LinkedHashMap(); - map.put("Result", p); + + for (String key:outputParameters.keySet()){ + String value = outputParameters.get(key); + PrimitiveType val = new PrimitiveType(String.class.getName(), "" + value, PrimitiveTypes.STRING, key, key); + map.put(key, val); + } + + // collect all the outputs map.put("Images", images); // generate a primitive type for the collection @@ -253,6 +272,10 @@ public class MapsComparator extends DataAnalysis { return output; } + @Override + public float getStatus() { + return status; + } }