This commit is contained in:
Gianpaolo Coro 2017-09-07 10:02:32 +00:00
parent 8d02d0ebe2
commit a1f0234e0c
4 changed files with 51 additions and 8 deletions

15
src/log4j.properties Normal file
View File

@ -0,0 +1,15 @@
log4j.rootLogger=DEBUG, stdout, rollingFile
# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
log4j.appender.rollingFile=org.apache.log4j.RollingFileAppender
log4j.appender.rollingFile.File=test.log
log4j.appender.rollingFile.MaxFileSize=20MB
log4j.appender.rollingFile.MaxBackupIndex=2
log4j.appender.rollingFile.layout = org.apache.log4j.PatternLayout
log4j.appender.rollingFile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

View File

@ -141,10 +141,10 @@ public class DivaHTTPClient {
* level depth level * level depth level
*/ */
public static DivaAnalysisGetResponse getAnalysis(String id, double len, double stn, double x0, double x1, double dx, double y0, double y1, double dy, double level) throws Exception { public static DivaAnalysisGetResponse getAnalysis(String id, double len, double stn, double x0, double x1, double dx, double y0, double y1, double dy, double level) throws Exception {
return getAnalysis(id, len, stn, x0, x1, dx, y0, y1, dy, level, false); return getAnalysis(id, len, stn, x0, x1, dx, y0, y1, dy, level, false,0);
} }
public static DivaAnalysisGetResponse getAnalysis(String id, double len, double stn, double x0, double x1, double dx, double y0, double y1, double dy, double level, Boolean useCurrents) throws Exception { public static DivaAnalysisGetResponse getAnalysis(String id, double len, double stn, double x0, double x1, double dx, double y0, double y1, double dy, double level, Boolean useCurrents, int currentsWeight) throws Exception {
HttpURLConnection httpUrlConnection = null; HttpURLConnection httpUrlConnection = null;
try { try {
@ -160,7 +160,7 @@ public class DivaHTTPClient {
get_url += "dy=" + dy + "&"; get_url += "dy=" + dy + "&";
get_url += "level=" + level + ""; get_url += "level=" + level + "";
if (useCurrents) if (useCurrents)
get_url += "&adv=1"; get_url += "&adv="+currentsWeight;
// System.out.println("GET URL="+get_url); // System.out.println("GET URL="+get_url);
AnalysisLogger.getLogger().debug("Get URL to sent: \n" + get_url); AnalysisLogger.getLogger().debug("Get URL to sent: \n" + get_url);
URL url = new URL(get_url); URL url = new URL(get_url);

View File

@ -9,6 +9,7 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import org.gcube.contentmanagement.graphtools.utils.HttpRequest;
import org.gcube.contentmanagement.graphtools.utils.MathFunctions; import org.gcube.contentmanagement.graphtools.utils.MathFunctions;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger; import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
import org.gcube.dataanalysis.ecoengine.datatypes.ColumnType; import org.gcube.dataanalysis.ecoengine.datatypes.ColumnType;
@ -39,6 +40,10 @@ import com.vividsolutions.jts.io.WKTReader;
public class SeaDataNetConnector_AutoCorrelation extends StandardLocalExternalAlgorithm { public class SeaDataNetConnector_AutoCorrelation extends StandardLocalExternalAlgorithm {
//TODO
//download file from thredds
//currents resolution at 1
// Statistical result by DIVA // Statistical result by DIVA
LinkedHashMap<String, String> statResultMap = new LinkedHashMap<String, String>(); LinkedHashMap<String, String> statResultMap = new LinkedHashMap<String, String>();
@ -73,6 +78,7 @@ public class SeaDataNetConnector_AutoCorrelation extends StandardLocalExternalAl
public static String ResolutionP = "ProjectionResolution"; public static String ResolutionP = "ProjectionResolution";
public static String DepthHeightP = "DepthOrHeightLevel"; public static String DepthHeightP = "DepthOrHeightLevel";
public static String UseCurrentsP = "UseCurrentsInformation"; public static String UseCurrentsP = "UseCurrentsInformation";
public static String CurrentsWeightP = "CurrentsVelocityWeight";
Double longMinVal = null; Double longMinVal = null;
Double longMaxVal = null; Double longMaxVal = null;
@ -134,6 +140,15 @@ public class SeaDataNetConnector_AutoCorrelation extends StandardLocalExternalAl
AnalysisLogger.getLogger().debug("Resolution: " + config.getParam(ResolutionP)); AnalysisLogger.getLogger().debug("Resolution: " + config.getParam(ResolutionP));
AnalysisLogger.getLogger().debug("Depth-Heigh Level: " + config.getParam(DepthHeightP)); AnalysisLogger.getLogger().debug("Depth-Heigh Level: " + config.getParam(DepthHeightP));
AnalysisLogger.getLogger().debug("Use currents: " + config.getParam(UseCurrentsP)); AnalysisLogger.getLogger().debug("Use currents: " + config.getParam(UseCurrentsP));
AnalysisLogger.getLogger().debug("Currents weight: " + config.getParam(CurrentsWeightP));
int currentsWeight = Integer.parseInt(config.getParam(CurrentsWeightP));
if (currentsWeight<0)
currentsWeight=0;
else
currentsWeight = currentsWeight*2000/100;
AnalysisLogger.getLogger().debug("Recalculated currents weight: " + currentsWeight);
AnalysisLogger.getLogger().debug("Checking parameters consistency"); AnalysisLogger.getLogger().debug("Checking parameters consistency");
//->try - catch to manage case of NULL values //->try - catch to manage case of NULL values
@ -191,9 +206,18 @@ public class SeaDataNetConnector_AutoCorrelation extends StandardLocalExternalAl
status = 30; status = 30;
int velocityuploadingOK = 200; int velocityuploadingOK = 200;
if (useCurrents) if (useCurrents && currentsWeight>0){
velocityuploadingOK = DivaHTTPClient.postVelocityFiles(response.getSessionid(), "u", "v", new File ("./example.nc")); String currentsFile = "http://data.d4science.org/QW43dXd0RDRIYUJUOENpNXF1ekoxNnFLeUdSTjZQWGZHbWJQNStIS0N6Yz0"; //under VRE Folders->BiodiversityLab
String tempFile = "currents"+UUID.randomUUID()+".nc";
AnalysisLogger.getLogger().debug("Downloading oceans currents file from "+currentsFile);
HttpRequest.downloadFile(currentsFile, tempFile);
File tempcurrentsfile = new File(tempFile);
AnalysisLogger.getLogger().debug("Sending ocean currents to DIVA - local File exists "+tempcurrentsfile.exists());
velocityuploadingOK = DivaHTTPClient.postVelocityFiles(response.getSessionid(), "u", "v", tempcurrentsfile);
AnalysisLogger.getLogger().debug("Done - Sending ocean currents to DIVA");
tempcurrentsfile.delete();
}
//velocityuploadingOK = DivaHTTPClient.postVelocityFiles(response.getSessionid(), "u", "v", new File ("./example.nc"));
if (velocityuploadingOK!=200) if (velocityuploadingOK!=200)
throw new Exception("Could not upload currents files. Response "+velocityuploadingOK); throw new Exception("Could not upload currents files. Response "+velocityuploadingOK);
@ -205,7 +229,7 @@ public class SeaDataNetConnector_AutoCorrelation extends StandardLocalExternalAl
AnalysisLogger.getLogger().debug("Requesting analysis to DIVA..."); AnalysisLogger.getLogger().debug("Requesting analysis to DIVA...");
long t0 = System.currentTimeMillis(); long t0 = System.currentTimeMillis();
DivaAnalysisGetResponse respAnalysis = DivaHTTPClient.getAnalysis(response.getSessionid(), fitResponse.getLength_scale(), fitResponse.getSignal_to_noise(), longMinVal, longMaxVal, resolutionVal, latMinVal, latMaxVal, resolutionVal, depthLevelVal, useCurrents); DivaAnalysisGetResponse respAnalysis = DivaHTTPClient.getAnalysis(response.getSessionid(), fitResponse.getLength_scale(), fitResponse.getSignal_to_noise(), longMinVal, longMaxVal, resolutionVal, latMinVal, latMaxVal, resolutionVal, depthLevelVal, useCurrents, currentsWeight);
AnalysisLogger.getLogger().debug("Response from DIVA analysis: "+respAnalysis); AnalysisLogger.getLogger().debug("Response from DIVA analysis: "+respAnalysis);
long t1 = System.currentTimeMillis(); long t1 = System.currentTimeMillis();
//->Record the time of the analysis //->Record the time of the analysis
@ -217,7 +241,7 @@ public class SeaDataNetConnector_AutoCorrelation extends StandardLocalExternalAl
statResultMap.put("Number of observations used", "" + respAnalysis.getStat_obs_count_used()); statResultMap.put("Number of observations used", "" + respAnalysis.getStat_obs_count_used());
statResultMap.put("Signal-to-noise ratio", "" + fitResponse.getSignal_to_noise()); statResultMap.put("Signal-to-noise ratio", "" + fitResponse.getSignal_to_noise());
statResultMap.put("Geographical length of the correlation (deg)", "" + fitResponse.getLength_scale()); statResultMap.put("Geographical length of the correlation (deg)", "" + fitResponse.getLength_scale());
statResultMap.put("Fit quality", "" + fitResponse.getFit_quality()); statResultMap.put("Quality of the automatic signal-to-noise ratio estimate", "" + fitResponse.getFit_quality());
//statResultMap.put("A posteriori estimate of signal-to-noise ratio", "" + respAnalysis.getStat_posteriori_stn()); //statResultMap.put("A posteriori estimate of signal-to-noise ratio", "" + respAnalysis.getStat_posteriori_stn());
AnalysisLogger.getLogger().debug("Map of results to be returned: "+statResultMap); AnalysisLogger.getLogger().debug("Map of results to be returned: "+statResultMap);
@ -264,6 +288,7 @@ public class SeaDataNetConnector_AutoCorrelation extends StandardLocalExternalAl
PrimitiveType p5 = new PrimitiveType(Double.class.getName(), null, PrimitiveTypes.NUMBER, ResolutionP, "Resolution of the projection (minimum 0.1deg. - maximum 10deg.)", "1"); PrimitiveType p5 = new PrimitiveType(Double.class.getName(), null, PrimitiveTypes.NUMBER, ResolutionP, "Resolution of the projection (minimum 0.1deg. - maximum 10deg.)", "1");
PrimitiveType p6 = new PrimitiveType(Double.class.getName(), null, PrimitiveTypes.NUMBER, DepthHeightP, "Depth (a negative value) or height (a positive value) of the observations (in meters).", "0"); PrimitiveType p6 = new PrimitiveType(Double.class.getName(), null, PrimitiveTypes.NUMBER, DepthHeightP, "Depth (a negative value) or height (a positive value) of the observations (in meters).", "0");
PrimitiveType p7 = new PrimitiveType(Boolean.class.getName(), null, PrimitiveTypes.BOOLEAN, UseCurrentsP, "Involve information about average annual global currents velocity.", "true"); PrimitiveType p7 = new PrimitiveType(Boolean.class.getName(), null, PrimitiveTypes.BOOLEAN, UseCurrentsP, "Involve information about average annual global currents velocity.", "true");
PrimitiveType p8 = new PrimitiveType(Double.class.getName(), null, PrimitiveTypes.NUMBER, CurrentsWeightP, "The weight of the currents velocity in the analysis in percentace (0-100)", "50");
inputs.add(p1); inputs.add(p1);
inputs.add(p2); inputs.add(p2);
@ -272,6 +297,7 @@ public class SeaDataNetConnector_AutoCorrelation extends StandardLocalExternalAl
inputs.add(p5); inputs.add(p5);
inputs.add(p6); inputs.add(p6);
inputs.add(p7); inputs.add(p7);
inputs.add(p8);
DatabaseType.addDefaultDBPars(inputs); DatabaseType.addDefaultDBPars(inputs);

View File

@ -84,6 +84,8 @@ public class TestSeaDataNetConnectorAutoCorr {
config.setParam("UseCurrentsInformation", "true"); config.setParam("UseCurrentsInformation", "true");
config.setParam("CurrentsVelocityWeight", "1");
config.setParam("DatabaseUserName","dmalgorithms_u"); config.setParam("DatabaseUserName","dmalgorithms_u");
config.setParam("DatabasePassword","cdec755ed6633ba"); config.setParam("DatabasePassword","cdec755ed6633ba");