Gianpaolo Coro 2014-02-24 11:52:47 +00:00
parent 44af71dd70
commit b5892c36a4
2 changed files with 87 additions and 90 deletions

View File

@ -1,13 +1,10 @@
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;
import java.util.List;
import java.util.Map;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.contentmanagement.graphtools.data.conversions.ImageTools;
@ -17,20 +14,17 @@ 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;
import org.gcube.dataanalysis.ecoengine.utils.IOHelper;
import org.gcube.dataanalysis.geo.insertion.RasterTable;
import org.gcube.dataanalysis.geo.meta.OGCFormatter;
import org.gcube.dataanalysis.geo.meta.features.FeaturesManager;
import org.gcube.dataanalysis.geo.retrieval.GeoIntersector;
import org.gcube.dataanalysis.geo.utils.ThreddsDataExplorer;
import org.gcube.dataanalysis.geo.connectors.netcdf.NetCDFDataExplorer;
import org.gcube.dataanalysis.geo.infrastructure.GeoNetworkInspector;
import org.gcube.dataanalysis.geo.matrixmodel.MatrixExtractor;
import org.gcube.dataanalysis.geo.matrixmodel.RasterTable;
import org.jfree.chart.JFreeChart;
import org.jfree.data.function.NormalDistributionFunction2D;
import org.jfree.data.general.DatasetUtilities;
@ -64,6 +58,11 @@ public class MapsComparator extends DataAnalysis {
return "An algorithm for comparing two OGC/NetCDF maps in seamless way to the user. Supported maps can only be in WFS, Opendap or ASC formats. The algorithm assesses the similarities between two geospatial maps by comparing them in a point-to-point fashion. It accepts as input the two geospatial maps (via their UUIDs in the infrastructure spatial data repository - recoverable through the Geoexplorer portlet) and some parameters affecting the comparison such as the z-index, the time index, the comparison threshold.";
}
public double BBxLL = -180;
public double BBxUR = 180;
public double BByLL = -90;
public double BByUR = 90;
@Override
public void compute() throws Exception{
status = 0;
@ -108,82 +107,29 @@ public class MapsComparator extends DataAnalysis {
// scope = "/gcube";
// String scope = null;
AnalysisLogger.getLogger().debug("MapsComparator: Using Scope: " + scope + " Z: " + z + " Values Threshold: " + valuesthreshold + " Layer1: " + layerT1 + " vs " + layerT2);
GeoIntersector intersector = new GeoIntersector(scope, config.getConfigPath());
AnalysisLogger.getLogger().debug("MapsComparator: GeoIntersector initialized");
double x1 = -180;
double x2 = 180;
double y1 = -90;
double y2 = 90;
MatrixExtractor intersector = new MatrixExtractor(scope, config.getConfigPath());
AnalysisLogger.getLogger().debug("MapsComparator: MatrixExtractor initialized");
status = 10;
FeaturesManager fm = intersector.getFeaturer();
AnalysisLogger.getLogger().debug("MapsComparator: Taking info for the layer: " + layerT1);
Metadata meta1 = fm.getGNInfobyUUIDorName(layerT1);
if (meta1==null) throw new Exception("No Correspondence with Layer 1");
double resolution1 = 0;
try {
resolution1 = FeaturesManager.getResolution(meta1);
} catch (Exception e) {
AnalysisLogger.getLogger().debug("MapsComparator: Undefined resolution");
}
AnalysisLogger.getLogger().debug("MapsComparator: Resolution: " + resolution1);
if (fm.isThreddsFile(meta1)){
AnalysisLogger.getLogger().debug("MapsComparator: recalculating the spatial extent of the comparison");
String fileurl = fm.getOpenDapLink(meta1);
GridDataset gds = ucar.nc2.dt.grid.GridDataset.open(fileurl);
List<GridDatatype> gridTypes = gds.getGrids();
GridDatatype gdt = gridTypes.get(0);
x1 = ThreddsDataExplorer.getMinX(gdt.getCoordinateSystem());
x2 = ThreddsDataExplorer.getMaxX(gdt.getCoordinateSystem());
y1 = ThreddsDataExplorer.getMinY(gdt.getCoordinateSystem());
y2 = ThreddsDataExplorer.getMaxY(gdt.getCoordinateSystem());
}
AnalysisLogger.getLogger().debug("MapsComparator: Spatial extent of the comparison: x1: "+x1+" x2: "+x2+" y1: "+y1+" y2: "+y2);
status = 15;
AnalysisLogger.getLogger().debug("MapsComparator: Taking info for the layer: " + layerT2);
AnalysisLogger.getLogger().debug("MapsComparator: Trying with UUID..." + layerT2);
Metadata meta2 = fm.getGNInfobyUUIDorName(layerT2);
if (meta2==null) throw new Exception("No Correspondence with Layer 2");
double resolution2 = 0;
try {
resolution2 = FeaturesManager.getResolution(meta2);
} catch (Exception e) {
AnalysisLogger.getLogger().debug("MapsComparator: Undefined resolution");
}
AnalysisLogger.getLogger().debug("MapsComparator: Resolution: " + resolution2);
status = 20;
// take the lowest resolution to perform the comparison
double resolution = Math.max(resolution1, resolution2);
AnalysisLogger.getLogger().debug("MapsComparator: Theoretical Resolution: " + resolution);
if (resolution == 0)
resolution = 0.5d;
// I added the following control to limit the amount of calculations
if (resolution<0.5 && resolution>0.01)
resolution = 0.5d;
else if (resolution<0.01)
resolution = 0.01d;
double resolution = getBestComparisonResolution(intersector, layerT1, layerT2);
AnalysisLogger.getLogger().debug("MapsComparator: Evaluation Indeed at Resolution: " + resolution);
AnalysisLogger.getLogger().debug("MapsComparator: ****Rasterizing map 1****");
double[][] slice1 = intersector.takeTimeSlice(layerT1, time1, x1, x2, y1, y2, z, resolution, resolution);
double[][] slice1 = intersector.takeTimeInstantMatrix(layerT1, time1, BBxLL, BBxUR, BByLL, BByUR, z, resolution, resolution);
AnalysisLogger.getLogger().debug("MapsComparator: Dumping map 1");
status = 30;
RasterTable raster1 = new RasterTable(x1, x2, y1, y2, z, resolution, resolution, slice1, config);
RasterTable raster1 = new RasterTable(BBxLL, BBxUR, BByLL, BByUR, z, resolution, resolution, slice1, config);
raster1.dumpGeoTable();
String rastertable1 = raster1.getTablename();
AnalysisLogger.getLogger().debug("MapsComparator: Map 1 was dumped in table: " + rastertable1);
status = 40;
AnalysisLogger.getLogger().debug("MapsComparator: ****Rasterizing map 2****");
double[][] slice2 = intersector.takeTimeSlice(layerT2, time2, x1, x2, y1, y2, z, resolution, resolution);
double[][] slice2 = intersector.takeTimeInstantMatrix(layerT2, time2, BBxLL, BBxUR, BByLL, BByUR, z, resolution, resolution);
AnalysisLogger.getLogger().debug("MapsComparator: Dumping map 2");
status = 50;
RasterTable raster2 = new RasterTable(x1, x2, y1, y2, z, resolution, resolution, slice2, config);
RasterTable raster2 = new RasterTable(BBxLL, BBxUR, BByLL, BByUR, z, resolution, resolution, slice2, config);
raster2.dumpGeoTable();
String rastertable2 = raster2.getTablename();
AnalysisLogger.getLogger().debug("MapsComparator: Map 2 was dumped in table: " + rastertable2);
@ -228,6 +174,62 @@ public class MapsComparator extends DataAnalysis {
}
public double getBestComparisonResolution(MatrixExtractor intersector, String layerID1, String layerID2) throws Exception{
GeoNetworkInspector fm = intersector.getFeaturer();
AnalysisLogger.getLogger().debug("MapsComparator: Taking info for the layer: " + layerID1);
Metadata meta1 = fm.getGNInfobyUUIDorName(layerID1);
if (meta1==null) throw new Exception("No Correspondence with Layer 1");
double resolution1 = 0;
try {
resolution1 = GeoNetworkInspector.getResolution(meta1);
} catch (Exception e) {
AnalysisLogger.getLogger().debug("MapsComparator: Undefined resolution");
}
AnalysisLogger.getLogger().debug("MapsComparator: Resolution: " + resolution1);
if (fm.isNetCDFFile(meta1)){
AnalysisLogger.getLogger().debug("MapsComparator: recalculating the spatial extent of the comparison");
String fileurl = fm.getOpenDapLink(meta1);
GridDataset gds = ucar.nc2.dt.grid.GridDataset.open(fileurl);
List<GridDatatype> gridTypes = gds.getGrids();
GridDatatype gdt = gridTypes.get(0);
BBxLL = NetCDFDataExplorer.getMinX(gdt.getCoordinateSystem());
BBxUR = NetCDFDataExplorer.getMaxX(gdt.getCoordinateSystem());
BByLL = NetCDFDataExplorer.getMinY(gdt.getCoordinateSystem());
BByUR = NetCDFDataExplorer.getMaxY(gdt.getCoordinateSystem());
}
AnalysisLogger.getLogger().debug("MapsComparator: Spatial extent of the comparison: x1: "+BBxLL+" x2: "+BBxUR+" y1: "+BByLL+" y2: "+BByUR);
AnalysisLogger.getLogger().debug("MapsComparator: Taking info for the layer: " + layerID2);
AnalysisLogger.getLogger().debug("MapsComparator: Trying with UUID..." + layerID2);
Metadata meta2 = fm.getGNInfobyUUIDorName(layerID2);
if (meta2==null) throw new Exception("No Correspondence with Layer 2");
double resolution2 = 0;
try {
resolution2 = GeoNetworkInspector.getResolution(meta2);
} catch (Exception e) {
AnalysisLogger.getLogger().debug("MapsComparator: Undefined resolution");
}
AnalysisLogger.getLogger().debug("MapsComparator: Resolution: " + resolution2);
// take the lowest resolution to perform the comparison
double resolution = Math.max(resolution1, resolution2);
AnalysisLogger.getLogger().debug("MapsComparator: Theoretical Resolution: " + resolution);
if (resolution == 0)
resolution = 0.5d;
// I added the following control to limit the amount of calculations
if (resolution<0.5 && resolution>0.01)
resolution = 0.5d;
else if (resolution<0.01)
resolution = 0.01d;
return resolution;
}
@Override
public List<StatisticalType> getInputParameters(){
@ -250,11 +252,6 @@ public class MapsComparator extends DataAnalysis {
}
protected Image generateGaussian(double mean, double variance){
// gaussian
XYSeriesCollection xyseriescollection = new XYSeriesCollection();

View File

@ -23,9 +23,9 @@ import org.gcube.dataanalysis.ecoengine.utils.Transformations;
import org.gcube.dataanalysis.ecoengine.utils.Tuple;
import org.gcube.dataanalysis.executor.generators.D4ScienceDistributedProcessing;
import org.gcube.dataanalysis.executor.job.management.QueueJobManager;
import org.gcube.dataanalysis.geo.meta.features.FeaturesManager;
import org.gcube.dataanalysis.geo.retrieval.GeoIntersector;
import org.gcube.dataanalysis.geo.utils.ThreddsDataExplorer;
import org.gcube.dataanalysis.geo.connectors.netcdf.NetCDFDataExplorer;
import org.gcube.dataanalysis.geo.infrastructure.GeoNetworkInspector;
import org.gcube.dataanalysis.geo.matrixmodel.MatrixExtractor;
import org.opengis.metadata.Metadata;
import ucar.nc2.dt.GridDatatype;
@ -141,7 +141,7 @@ public class MapsComparatorNode extends ActorNode{
if (scope == null)
scope = ScopeProvider.instance.get();
GeoIntersector intersector = new GeoIntersector(scope, config.getConfigPath());
MatrixExtractor intersector = new MatrixExtractor(scope, config.getConfigPath());
AnalysisLogger.getLogger().debug("MapsComparator: GeoIntersector initialized");
double x1 = -180;
@ -150,28 +150,28 @@ public class MapsComparatorNode extends ActorNode{
double y2 = 90;
status = 10;
FeaturesManager fm = intersector.getFeaturer();
GeoNetworkInspector fm = intersector.getFeaturer();
AnalysisLogger.getLogger().debug("MapsComparator: Taking info for the layer: " + layerT1);
Metadata meta1 = fm.getGNInfobyUUIDorName(layerT1);
if (meta1==null) throw new Exception("No Correspondence with Layer 1");
double resolution1 = 0;
try {
resolution1 = FeaturesManager.getResolution(meta1);
resolution1 = GeoNetworkInspector.getResolution(meta1);
} catch (Exception e) {
AnalysisLogger.getLogger().debug("MapsComparator: Undefined resolution");
}
AnalysisLogger.getLogger().debug("MapsComparator: Resolution: " + resolution1);
if (fm.isThreddsFile(meta1)){
if (fm.isNetCDFFile(meta1)){
AnalysisLogger.getLogger().debug("MapsComparator: recalculating the spatial extent of the comparison");
String fileurl = fm.getOpenDapLink(meta1);
GridDataset gds = ucar.nc2.dt.grid.GridDataset.open(fileurl);
List<GridDatatype> gridTypes = gds.getGrids();
GridDatatype gdt = gridTypes.get(0);
x1 = ThreddsDataExplorer.getMinX(gdt.getCoordinateSystem());
x2 = ThreddsDataExplorer.getMaxX(gdt.getCoordinateSystem());
y1 = ThreddsDataExplorer.getMinY(gdt.getCoordinateSystem());
y2 = ThreddsDataExplorer.getMaxY(gdt.getCoordinateSystem());
x1 = NetCDFDataExplorer.getMinX(gdt.getCoordinateSystem());
x2 = NetCDFDataExplorer.getMaxX(gdt.getCoordinateSystem());
y1 = NetCDFDataExplorer.getMinY(gdt.getCoordinateSystem());
y2 = NetCDFDataExplorer.getMaxY(gdt.getCoordinateSystem());
}
AnalysisLogger.getLogger().debug("MapsComparator: Spatial extent of the comparison: x1: "+x1+" x2: "+x2+" y1: "+y1+" y2: "+y2);
@ -183,7 +183,7 @@ public class MapsComparatorNode extends ActorNode{
double resolution2 = 0;
try {
resolution2 = FeaturesManager.getResolution(meta2);
resolution2 = GeoNetworkInspector.getResolution(meta2);
} catch (Exception e) {
AnalysisLogger.getLogger().debug("MapsComparator: Undefined resolution");
}
@ -261,12 +261,12 @@ public class MapsComparatorNode extends ActorNode{
int positivescount = 0;
if (slicey1<=y2){
GeoIntersector intersector = new GeoIntersector(scope, config.getConfigPath());
MatrixExtractor intersector = new MatrixExtractor(scope, config.getConfigPath());
AnalysisLogger.getLogger().debug("MapsComparator: GeoIntersector initialized");
AnalysisLogger.getLogger().debug("MapsComparator: ****Rasterizing map 1 in the range: ("+x1+" , "+slicey1+"; "+x2+" , "+slicey2+") with res "+resolution);
double[][] slice1 = intersector.takeTimeSlice(layerT1, time1, x1, x2, slicey1, slicey2, z, resolution, resolution);
double[][] slice1 = intersector.takeTimeInstantMatrix(layerT1, time1, x1, x2, slicey1, slicey2, z, resolution, resolution);
AnalysisLogger.getLogger().debug("MapsComparator: ****Rasterizing map 2 in the range: ("+x1+" , "+slicey1+"; "+x2+" , "+slicey2+") with res "+resolution);
double[][] slice2 = intersector.takeTimeSlice(layerT2, time1, x1, x2, slicey1, slicey2, z, resolution, resolution);
double[][] slice2 = intersector.takeTimeInstantMatrix(layerT2, time1, x1, x2, slicey1, slicey2, z, resolution, resolution);
int xsize = slice1[0].length;
int ysize = slice1.length;