Gianpaolo Coro 2013-04-30 16:38:57 +00:00
parent c66109c505
commit 787d3b4846
4 changed files with 190 additions and 21 deletions

View File

@ -12,7 +12,6 @@ import org.gcube.spatial.data.geonetwork.GeoNetwork;
import org.gcube.spatial.data.geonetwork.GeoNetworkReader;
import org.gcube.spatial.data.geonetwork.configuration.Configuration;
import org.gcube.spatial.data.geonetwork.configuration.ConfigurationManager;
import org.geotoolkit.util.DefaultInternationalString;
import org.opengis.metadata.Metadata;
import org.opengis.metadata.citation.OnlineResource;
import org.opengis.metadata.distribution.DigitalTransferOptions;
@ -176,15 +175,48 @@ public class FeaturesManager {
return metadatalist;
}
public List<Metadata> getFastGNInfobyTitle(String info, String completeTitle, String tolerance) throws Exception {
GeoNetworkReader gn = initGeoNetworkReader();
// Form query object
gn.login();
GNSearchRequest req = new GNSearchRequest();
req.addParam(GNSearchRequest.Param.title, info);
req.addConfig(GNSearchRequest.Config.similarity, tolerance);
GNSearchResponse resp = gn.query(req);
Metadata meta = null;
List<Metadata> metadatalist = new ArrayList<Metadata>();
if (resp.getCount() != 0){
for (GNSearchResponse.GNMetadata metadata : resp) {
try {
meta = gn.getById(metadata.getUUID());
Identification id = meta.getIdentificationInfo().iterator().next();
String title = id.getCitation().getTitle().toString();
if (title.equalsIgnoreCase(completeTitle)){
metadatalist.add(meta);
break;
}
} catch (Exception e) {
AnalysisLogger.getLogger().debug("Error retrieving information for some metadata");
}
}
}
return metadatalist;
}
public Metadata checkForMetadatabyTitle(String searchString, String completetitle) throws Exception {
return checkForMetadatabyTitle(searchString, completetitle, "");
}
public Metadata checkForMetadatabyTitle(String searchString, String completetitle, String filename) throws Exception {
AnalysisLogger.getLogger().debug("Searching for: "+searchString);
List<Metadata> mlist = getAllGNInfobyTitle(searchString, "1");
List<Metadata> mlist = getFastGNInfobyTitle(searchString, completetitle,"1");
AnalysisLogger.getLogger().debug("Found:"+mlist.size()+" results");
Metadata mfound = null;
DefaultInternationalString intfilename = new DefaultInternationalString(filename);
// DefaultInternationalString intfilename = new DefaultInternationalString(filename);
for (Metadata m : mlist) {
Identification id = m.getIdentificationInfo().iterator().next();
String title = id.getCitation().getTitle().toString();

View File

@ -1,11 +1,14 @@
package org.gcube.dataanalysis.geo.retrieval;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
import org.gcube.dataanalysis.ecoengine.configuration.AlgorithmConfiguration;
import org.gcube.dataanalysis.ecoengine.signals.SignalProcessing;
import org.gcube.dataanalysis.ecoengine.utils.Tuple;
import org.gcube.dataanalysis.geo.meta.features.FeaturesManager;
import org.gcube.dataanalysis.geo.utils.EnvDataExplorer;
@ -16,10 +19,11 @@ import org.opengis.metadata.identification.Identification;
public class GeoIntersector {
private FeaturesManager featurer;
public GeoIntersector(String scope) {
private String configDir;
public GeoIntersector(String scope, String cfgDir) {
featurer = new FeaturesManager();
featurer.setScope(scope);
this.configDir=cfgDir;
}
public LinkedHashMap<String, Double> getFeaturesInTime(String layerTitle, double x, double y) throws Exception {
@ -43,10 +47,10 @@ public class GeoIntersector {
Identification id = meta.getIdentificationInfo().iterator().next();
String title = id.getCitation().getTitle().toString();
System.out.println("found a netCDF file with title " + title + " and layer name " + layer);
AnalysisLogger.getLogger().debug("found a netCDF file with title " + title + " and layer name " + layer);
features = getFeaturesFromNetCDF(featurer.getOpenDapLink(meta), layer, x, y, z);
} else {
System.out.println("found a Geo Layer with title " + layerTitle + " and layer name " + layer);
AnalysisLogger.getLogger().debug("found a Geo Layer with title " + layerTitle + " and layer name " + layer);
features = getFeaturesFromWFS(featurer.getWFSLink(meta), layer, x, y);
}
}
@ -67,24 +71,26 @@ public class GeoIntersector {
if (featurer.isThreddsFile(meta)) {
Identification id = meta.getIdentificationInfo().iterator().next();
String title = id.getCitation().getTitle().toString();
System.out.println("found a netCDF file with title " + title + " and layer name " + layer);
AnalysisLogger.getLogger().debug("found a netCDF file with title " + title + " and layer name " + layer);
for (Tuple<Double> triplet : triplets) {
double x = triplet.getElements().get(0);
double y = triplet.getElements().get(1);
double z = 0;
if (triplet.getElements().size() > 2)
z = triplet.getElements().get(2);
AnalysisLogger.getLogger().debug("Taking point: (" + x + "," + y + "," + z + ")");
LinkedHashMap<String, Double> features = new LinkedHashMap<String, Double>();
features = getFeaturesFromNetCDF(featurer.getOpenDapLink(meta), layer, x, y, z);
AnalysisLogger.getLogger().debug("Got: (" + features + ")");
featuresSets.add(features);
}
} else {
System.out.println("found a Geo Layer with title " + layerTitle + " and layer name " + layer);
AnalysisLogger.getLogger().debug("found a Geo Layer with title " + layerTitle + " and layer name " + layer);
for (Tuple<Double> triplet : triplets) {
double x = triplet.getElements().get(0);
double y = triplet.getElements().get(1);
AnalysisLogger.getLogger().debug("Taking point: (" + x + "," + y + ")");
LinkedHashMap<String, Double> features = new LinkedHashMap<String, Double>();
features = getFeaturesFromWFS(featurer.getWFSLink(meta), layer, x, y);
featuresSets.add(features);
@ -109,14 +115,77 @@ public class GeoIntersector {
return EnvDataExplorer.getFeatures(wfsUrl, layer, x, y);
}
public static void main(String args[]) throws Exception {
AnalysisLogger.setLogger("./cfg/" + AlgorithmConfiguration.defaultLoggerFile);
// GeoIntersector inters = new GeoIntersector("/gcube/devsec");
GeoIntersector inters = new GeoIntersector(null);
public double[][] takeLastTimeChunk(String layerTitle, double x1, double x2, double y1, double y2, double z, double xResolution, double yResolution) throws Exception {
AnalysisLogger.getLogger().debug("Bounding box: (" + x1 + "," + x2 + ";" + y1 + "," + y2 + ")");
if ((x2 < x1) || (y2 < y1)) {
AnalysisLogger.getLogger().debug("ERROR: BAD BOUNDING BOX!!!");
return new double[0][0];
}
// System.out.println(inters.getFeaturesInTime("temperature (04091217ruc.nc)", 0.1, 0.1));
// System.out.println(inters.getFeaturesInTime("wind stress from [05-01-07 14:00] to [04-01-12 14:00] (2D) {Monthly ASCAT global wind field: Data extracted from dataset http://tds0.ifremer.fr/thredds/dodsC/CERSAT-GLO-CLIM_WIND_L4-OBS_FULL_TIME_SERIE}", 0.1, 0.1,3000));
System.out.println(inters.getFeaturesInTime("Statistical Mean in [07-01-01 01:00] (3D) {World Ocean Atlas 09: Sea Water Temperature - annual: dods://thredds.research-infrastructures.eu/thredds/dodsC/public/netcdf/temperature_annual_1deg_ENVIRONMENT_OCEANS_.nc}", -70, 0.1, 3000));
int ysteps = (int) ((y2 - y1) / yResolution);
int xsteps = (int) ((x2 - x1) / xResolution);
double[][] slice = new double[ysteps + 1][xsteps + 1];
List<Tuple<Double>> tuples = new ArrayList<Tuple<Double>>();
AnalysisLogger.getLogger().debug("Building the points grid according to YRes:" + yResolution + " and XRes:" + xResolution);
// build the tuples according to the desired resolution
for (int i = 0; i < ysteps + 1; i++) {
double y = (i * yResolution) + y1;
if (i == ysteps)
y = y2;
for (int j = 0; j < xsteps + 1; j++) {
double x = (j * xResolution) + x1;
if (j == xsteps)
x = x2;
tuples.add(new Tuple<Double>(x, y, z));
}
}
AnalysisLogger.getLogger().debug("Taking " + ysteps + " values...");
List<LinkedHashMap<String, Double>> time = getFeaturesInTime(layerTitle, tuples);
AnalysisLogger.getLogger().debug("Taken " + time.size() + " values");
// build back the values matrix
int k = 0;
int g = 0;
int ntriplets = ysteps * xsteps;
//cycle on all the triplets to recontruct the matrix
for (int t = 0; t < ntriplets; t++) {
//take the corresponding (time,value) pair
LinkedHashMap<String, Double> tvalues = time.get(t);
//if there is value, then set it, otherwise set NaN
//the layer is undefined in that point and a value must be generated
double value = Double.NaN;
for (Double val : tvalues.values()) {
value = val;
break;
}
//assign a value to the matrix
slice[k][g] = value;
//increase the x step according to the matrix
g++;
if (g == xsteps) {
g = 0;
k++;
}
}
AnalysisLogger.getLogger().debug("Applying nearest Neighbor to all the rows");
//apply nearest neighbor to each row
AlgorithmConfiguration config = new AlgorithmConfiguration();
config.setConfigPath(configDir);
for (int i=0;i<slice.length;i++){
AnalysisLogger.getLogger().debug("Checking for unfilled values");
boolean tofill = false;
for (int j=0;j<slice[i].length;j++) {
if (slice[i][j]==Double.NaN)
tofill = true;
}
if (tofill){
AnalysisLogger.getLogger().debug("Filling signal");
slice[i] = SignalProcessing.fillSignal(slice[i]);
}
else
AnalysisLogger.getLogger().debug("Signal yet complete");
}
return slice;
}
}

View File

@ -0,0 +1,17 @@
package org.gcube.dataanalysis.geo.test;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
import org.gcube.dataanalysis.ecoengine.configuration.AlgorithmConfiguration;
import org.gcube.dataanalysis.geo.retrieval.GeoIntersector;
public class TestChunkization {
static String cfg = "./cfg/";
public static void main(String[] args) throws Exception{
String layertitle = "Statistical Mean in [07-01-01 01:00] (3D) {World Ocean Atlas 09: Sea Water Temperature - annual: dods://thredds.research-infrastructures.eu/thredds/dodsC/public/netcdf/temperature_annual_1deg_ENVIRONMENT_OCEANS_.nc}";
AnalysisLogger.setLogger(cfg+AlgorithmConfiguration.defaultLoggerFile);
GeoIntersector intersector = new GeoIntersector(null, cfg);
intersector.takeLastTimeChunk(layertitle, -180, 180, -10, 10, 0, 0.1, 0.1);
}
}

View File

@ -1,17 +1,68 @@
package org.gcube.dataanalysis.geo.test;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import org.gcube.contentmanagement.graphtools.utils.MathFunctions;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
import org.gcube.dataanalysis.ecoengine.configuration.AlgorithmConfiguration;
import org.gcube.dataanalysis.ecoengine.utils.Tuple;
import org.gcube.dataanalysis.geo.retrieval.GeoIntersector;
public class TestIntersectionNetCDF {
static String cfg = "./cfg/";
public static void main(String args[] ) throws Exception{
AnalysisLogger.setLogger("./cfg/"+AlgorithmConfiguration.defaultLoggerFile);
GeoIntersector inters = new GeoIntersector("/gcube/devsec");
public static void main1(String args[] ) throws Exception{
AnalysisLogger.setLogger(cfg+AlgorithmConfiguration.defaultLoggerFile);
GeoIntersector inters = new GeoIntersector("/gcube/devsec",cfg);
System.out.println(inters.getFeaturesInTime("temperature (04091217ruc.nc)", 0.1, 0.1));
}
public static void main2(String args[]) throws Exception {
AnalysisLogger.setLogger(cfg+AlgorithmConfiguration.defaultLoggerFile);
GeoIntersector inters = new GeoIntersector(null,cfg);
System.out.println(inters.getFeaturesInTime("Statistical Mean in [07-01-01 01:00] (3D) {World Ocean Atlas 09: Sea Water Temperature - annual: dods://thredds.research-infrastructures.eu/thredds/dodsC/public/netcdf/temperature_annual_1deg_ENVIRONMENT_OCEANS_.nc}", -70, 0.1, 3000));
}
public static void main(String args[]) throws Exception {
AnalysisLogger.setLogger(cfg+AlgorithmConfiguration.defaultLoggerFile);
GeoIntersector inters = new GeoIntersector(null,cfg);
// List<Tuple<Double>> tuples = (List<Tuple<Double>>)Arrays.asList(
// new Tuple<Double>(0.1,0.1),
// new Tuple<Double>(10d,0.1),
// new Tuple<Double>(100d,0.1),
// new Tuple<Double>(180d,0.1),
// new Tuple<Double>(270d,0.1)
// );
List<Tuple<Double>> tuples = new ArrayList<Tuple<Double>>();
double start = -180d;
double end = 360d;
int steps = 30;
double step = (end-start)/steps;
double y = 0;
for (int i=0;i<steps+1;i++){
double x = (i*step)+start;
if (i==steps)
x = end;
tuples.add(new Tuple<Double>(x,y));
}
List<LinkedHashMap<String, Double>> time = inters.getFeaturesInTime("Statistical Mean in [07-01-01 01:00] (3D) {World Ocean Atlas 09: Sea Water Temperature - annual: dods://thredds.research-infrastructures.eu/thredds/dodsC/public/netcdf/temperature_annual_1deg_ENVIRONMENT_OCEANS_.nc}",tuples );
int i=0;
for (LinkedHashMap<String, Double> timemap : time){
for (Double val:timemap.values())
{
System.out.println(tuples.get(i).getElements().get(0)+"="+MathFunctions.roundDecimal(val,2));
break;
}
i++;
}
}
}