From bfd581bd3f2d459ea1e6f6e243729e543620735e Mon Sep 17 00:00:00 2001 From: Gianpaolo Coro Date: Mon, 2 Nov 2015 10:22:07 +0000 Subject: [PATCH] git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-analysis/EcologicalEngineGeoSpatialExtension@120157 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../geo/algorithms/CSquaresCreator.java | 1 + .../geo/algorithms/RasterDataPublisher.java | 1 + .../geo/test/TestFAOAreaCodesCreator.java | 8 +-- .../TestEstimateMonthlyFishingEffort.java | 58 +++++++++++++++++++ .../geo/utils/CSquareCodesConverter.java | 1 + .../geo/utils/FAOOceanAreaConverter.java | 19 +++++- .../geo/utils/GridCWPConverter.java | 55 ++++++++++++------ .../geo/utils/VectorOperations.java | 1 + .../geo/vti/CSquare2Coordinates.java | 1 - .../geo/vti/EstimateFishingActivity.java | 13 +---- .../geo/vti/GridCWP2Coordinates.java | 1 + .../geo/vti/vesselsprocessing/Bathymetry.java | 1 + .../FishingHoursCalculator.java | 3 +- .../MonthlyFishingEffortCalculator.java | 13 +++-- .../vti/vesselsprocessing/VTIBathymetry.java | 1 + .../vesselsprocessing/VTIClassificator.java | 1 + 16 files changed, 134 insertions(+), 44 deletions(-) create mode 100644 src/main/java/org/gcube/dataanalysis/geo/test/infra/TestEstimateMonthlyFishingEffort.java diff --git a/src/main/java/org/gcube/dataanalysis/geo/algorithms/CSquaresCreator.java b/src/main/java/org/gcube/dataanalysis/geo/algorithms/CSquaresCreator.java index d3057c8..d71512a 100644 --- a/src/main/java/org/gcube/dataanalysis/geo/algorithms/CSquaresCreator.java +++ b/src/main/java/org/gcube/dataanalysis/geo/algorithms/CSquaresCreator.java @@ -217,3 +217,4 @@ public class CSquaresCreator extends StandardLocalExternalAlgorithm { } } + diff --git a/src/main/java/org/gcube/dataanalysis/geo/algorithms/RasterDataPublisher.java b/src/main/java/org/gcube/dataanalysis/geo/algorithms/RasterDataPublisher.java index 079b42d..91cb091 100644 --- a/src/main/java/org/gcube/dataanalysis/geo/algorithms/RasterDataPublisher.java +++ b/src/main/java/org/gcube/dataanalysis/geo/algorithms/RasterDataPublisher.java @@ -129,3 +129,4 @@ public class RasterDataPublisher extends StandardLocalExternalAlgorithm{ } } + diff --git a/src/main/java/org/gcube/dataanalysis/geo/test/TestFAOAreaCodesCreator.java b/src/main/java/org/gcube/dataanalysis/geo/test/TestFAOAreaCodesCreator.java index c92316e..8be9de3 100644 --- a/src/main/java/org/gcube/dataanalysis/geo/test/TestFAOAreaCodesCreator.java +++ b/src/main/java/org/gcube/dataanalysis/geo/test/TestFAOAreaCodesCreator.java @@ -19,12 +19,12 @@ public class TestFAOAreaCodesCreator { // config.setParam("Longitude_Column", "centerlong"); // config.setParam("Latitude_Column", "centerlat"); - config.setParam("Longitude_Column", "long"); - config.setParam("Latitude_Column", "lat"); + config.setParam("Longitude_Column", "x_coord"); + config.setParam("Latitude_Column", "y_coord"); // config.setParam("InputTable", "interp_2024_linear_01355325354899"); // config.setParam("InputTable", "interp_2036_linear_11384851795640"); - config.setParam("InputTable", "generic_id6ef3e4fa_6a06_4df1_9445_553f2e918102"); - +// config.setParam("InputTable", "generic_id6ef3e4fa_6a06_4df1_9445_553f2e918102"); + config.setParam("InputTable", "generic_id25433bf4_c58c_4907_ac87_23919a3af0dc"); config.setParam("OutputTableName", "csqout"); config.setParam("Resolution", "5"); diff --git a/src/main/java/org/gcube/dataanalysis/geo/test/infra/TestEstimateMonthlyFishingEffort.java b/src/main/java/org/gcube/dataanalysis/geo/test/infra/TestEstimateMonthlyFishingEffort.java new file mode 100644 index 0000000..fb7f9a2 --- /dev/null +++ b/src/main/java/org/gcube/dataanalysis/geo/test/infra/TestEstimateMonthlyFishingEffort.java @@ -0,0 +1,58 @@ +package org.gcube.dataanalysis.geo.test.infra; + +import java.util.List; + +import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger; +import org.gcube.dataanalysis.ecoengine.configuration.AlgorithmConfiguration; +import org.gcube.dataanalysis.ecoengine.datatypes.StatisticalType; +import org.gcube.dataanalysis.ecoengine.interfaces.ComputationalAgent; +import org.gcube.dataanalysis.ecoengine.processing.factories.TransducerersFactory; +import org.gcube.dataanalysis.ecoengine.test.regression.Regressor; +import org.gcube.dataanalysis.geo.connectors.table.TableMatrixRepresentation; + +public class TestEstimateMonthlyFishingEffort { + + static AlgorithmConfiguration[] configs = { testGridConversion()}; + public static void main(String[] args) throws Exception { + + System.out.println("TEST 1"); + + for (int i = 0; i < configs.length; i++) { + AnalysisLogger.getLogger().debug("Executing: "+configs[i].getAgent()); + List trans = null; + trans = TransducerersFactory.getTransducerers(configs[i]); + trans.get(0).init(); + Regressor.process(trans.get(0)); + StatisticalType st = trans.get(0).getOutput(); + AnalysisLogger.getLogger().debug("ST:" + st); + trans = null; + } + } + + + private static AlgorithmConfiguration testGridConversion() { + + AlgorithmConfiguration config = new AlgorithmConfiguration(); + + config.setAgent("ESTIMATE_MONTHLY_FISHING_EFFORT"); + config.setConfigPath("./cfg/"); + config.setPersistencePath("./"); + config.setParam("DatabaseUserName","utente"); + config.setParam("DatabasePassword","d4science"); + config.setParam("DatabaseURL","jdbc:postgresql://statistical-manager.d.d4science.org/testdb"); + config.setParam("DatabaseDriver","org.postgresql.Driver"); + config.setGcubeScope("/gcube/devsec/devVRE"); + + config.setParam("InputTable", "code_0b7c500bfaca49f2a0ab4fd3c1647074"); + config.setParam("VesselsIDColumn", "vessel_id"); + config.setParam("VesselsTimestampsColumn", "datetime"); + config.setParam("VesselsLatitudesColumn", "y"); + config.setParam("VesselsLongitudesColumn", "x"); + config.setParam("VesselsActivityHoursColumn", "activity_hours"); + config.setParam("VesselsActivityClassificationColumn", "activity_class_speed"); + + return config; + } + + +} diff --git a/src/main/java/org/gcube/dataanalysis/geo/utils/CSquareCodesConverter.java b/src/main/java/org/gcube/dataanalysis/geo/utils/CSquareCodesConverter.java index 461ae86..a29f85b 100644 --- a/src/main/java/org/gcube/dataanalysis/geo/utils/CSquareCodesConverter.java +++ b/src/main/java/org/gcube/dataanalysis/geo/utils/CSquareCodesConverter.java @@ -99,3 +99,4 @@ public class CSquareCodesConverter { } + diff --git a/src/main/java/org/gcube/dataanalysis/geo/utils/FAOOceanAreaConverter.java b/src/main/java/org/gcube/dataanalysis/geo/utils/FAOOceanAreaConverter.java index 8b3d98f..4aacfa2 100644 --- a/src/main/java/org/gcube/dataanalysis/geo/utils/FAOOceanAreaConverter.java +++ b/src/main/java/org/gcube/dataanalysis/geo/utils/FAOOceanAreaConverter.java @@ -87,11 +87,26 @@ public class FAOOceanAreaConverter { } } - String FaoOceanArea = quadrant+padLatitude(bestlat)+padLongitude(bestlon); - if (FaoOceanArea.length()!=6) + String FaoOceanArea = getResolutionChar(resolution)+quadrant+padLatitude(bestlat)+padLongitude(bestlon); + if (FaoOceanArea.length()!=7) return null; return FaoOceanArea; } + public String getResolutionChar(int resolution){ + if (resolution == 1) + return "5"; + else if (resolution == 5) + return "6"; + else if (resolution == 10) + return "7"; + else if (resolution == 20) + return "8"; + else if (resolution == 30) + return "9"; + else + return "0"; + } + } diff --git a/src/main/java/org/gcube/dataanalysis/geo/utils/GridCWPConverter.java b/src/main/java/org/gcube/dataanalysis/geo/utils/GridCWPConverter.java index d361aaf..79df5cf 100644 --- a/src/main/java/org/gcube/dataanalysis/geo/utils/GridCWPConverter.java +++ b/src/main/java/org/gcube/dataanalysis/geo/utils/GridCWPConverter.java @@ -11,20 +11,20 @@ public class GridCWPConverter { public float outlon; public float outlat; - public int gridresolution; + public float gridresolution; public void gridCodeToPair (String grid){ char resolution = grid.charAt(0); int quadrant = Integer.parseInt(""+grid.charAt(1)); float lat = Float.parseFloat(grid.substring(2,4)); float lon = Float.parseFloat(grid.substring(4)); - int Xr = getResolutionX(resolution); + float Xr = getResolutionX(resolution); // int Yr = getResolutionY(resolution); gridresolution = Xr; float latAdj = adjustLat(lat, quadrant); float lonAdj = adjustLon(lon, quadrant); - int resolutionY = getResolutionY(resolution); - int resolutionX = getResolutionX(resolution); + float resolutionY = getResolutionY(resolution); + float resolutionX = getResolutionX(resolution); float centerLat = getCenterLat(latAdj, resolutionY, quadrant); float centerLon = getCenterLon(lonAdj, resolutionX, quadrant); @@ -36,7 +36,7 @@ public class GridCWPConverter { } - public float getCenterLat(float lat, int resolutionY, int quadrant){ + public float getCenterLat(float lat, float resolutionY, int quadrant){ float halfres = (float) resolutionY/2f; if (quadrant == 1 || quadrant == 4) @@ -45,7 +45,7 @@ public class GridCWPConverter { return lat-halfres; } - public float getCenterLon(float lon, int resolutionX, int quadrant){ + public float getCenterLon(float lon, float resolutionX, int quadrant){ float halfres = (float) resolutionX/2f; if (quadrant == 1 || quadrant == 2) @@ -68,38 +68,55 @@ public class GridCWPConverter { return -1*lon; } - public int getResolutionY(char token){ + public float getResolutionY(char token){ if (token == '5') return 1; else if (token == '6') return 5; - else if (token == '1') - return 5; - else if (token == '2') + else if (token == '7') return 10; - else if (token == '3') - return 10; - else if (token == '4') + else if (token == '8') return 20; + else if (token == '9') + return 30; + else if (token == '0') + return 0; + else if (token == '4') + return 0.5f; + else if (token == '3') + return 0.5f; + else if (token == '2') + return 0.22f; + else if (token == '1') + return 0.17f; else return -1; } - public int getResolutionX(char token){ + public float getResolutionX(char token){ if (token == '5') return 1; else if (token == '6') return 5; - else if (token == '1') + else if (token == '7') return 10; - else if (token == '2') + else if (token == '8') return 20; - else if (token == '3') - return 10; + else if (token == '9') + return 30; + else if (token == '0') + return 0; else if (token == '4') - return 20; + return 1; + else if (token == '3') + return 0.5f; + else if (token == '2') + return 0.22f; + else if (token == '1') + return 0.17f; else return -1; } } + diff --git a/src/main/java/org/gcube/dataanalysis/geo/utils/VectorOperations.java b/src/main/java/org/gcube/dataanalysis/geo/utils/VectorOperations.java index 9ba2efc..799117a 100644 --- a/src/main/java/org/gcube/dataanalysis/geo/utils/VectorOperations.java +++ b/src/main/java/org/gcube/dataanalysis/geo/utils/VectorOperations.java @@ -269,3 +269,4 @@ public class VectorOperations { */ } } + diff --git a/src/main/java/org/gcube/dataanalysis/geo/vti/CSquare2Coordinates.java b/src/main/java/org/gcube/dataanalysis/geo/vti/CSquare2Coordinates.java index 9c58db1..b0c4e3c 100644 --- a/src/main/java/org/gcube/dataanalysis/geo/vti/CSquare2Coordinates.java +++ b/src/main/java/org/gcube/dataanalysis/geo/vti/CSquare2Coordinates.java @@ -13,7 +13,6 @@ import org.gcube.dataanalysis.geo.utils.CSquareCodesConverter; public class CSquare2Coordinates extends GridCWP2Coordinates{ - @Override protected void setInputParameters() { diff --git a/src/main/java/org/gcube/dataanalysis/geo/vti/EstimateFishingActivity.java b/src/main/java/org/gcube/dataanalysis/geo/vti/EstimateFishingActivity.java index 7c088d9..6ea9aa3 100644 --- a/src/main/java/org/gcube/dataanalysis/geo/vti/EstimateFishingActivity.java +++ b/src/main/java/org/gcube/dataanalysis/geo/vti/EstimateFishingActivity.java @@ -38,7 +38,7 @@ public class EstimateFishingActivity extends GridCWP2Coordinates{ ColumnType Dimension1 = new ColumnType(inputTableParameter, VesselsIDColumn, "A column containing (anonymised) unique vessels identifiers", "vessel_id", false); ColumnType Dimension2 = new ColumnType(inputTableParameter, VesselsSpeedsColumn, "The column containing vessels speeds", "speed", false); - ColumnType Dimension3 = new ColumnType(inputTableParameter, VesselsTimestampsColumn, "The column containing the time stamp of the vessels transmitted information", "datetime", false); + ColumnType Dimension3 = new ColumnType(inputTableParameter, VesselsTimestampsColumn, "The column containing the time stamp of the vessels transmitted information (preferred in the following format: MM/dd/yyyy HH:mm:ss a)", "datetime", false); ColumnType Dimension4 = new ColumnType(inputTableParameter, VesselsLatitudesColumn, "The column containing vessels latitudes", "y", false); ColumnType Dimension5 = new ColumnType(inputTableParameter, VesselsLongitudesColumn, "The column containing vessels longitudes", "x", false); @@ -70,7 +70,7 @@ public class EstimateFishingActivity extends GridCWP2Coordinates{ long t0 = System.currentTimeMillis(); String table = IOHelper.getInputParameter(config, inputTableParameter); - outTable = ("code_" + UUID.randomUUID()).replace("-", ""); + outTable = ("fish_" + UUID.randomUUID()).replace("-", ""); outTableLabel = IOHelper.getInputParameter(config, outputTableParameter); AnalysisLogger.getLogger().debug("EstimateFishingActivity: received parameters: " + config.getGeneralProperties()); @@ -87,14 +87,6 @@ public class EstimateFishingActivity extends GridCWP2Coordinates{ } } - public String selectInformationForTransformation (AlgorithmConfiguration config, String table, int limit, int offset){ - - String d = IOHelper.getInputParameter(config, CodeColumn); - - String select = "select *," + d + " as loforcs01 from " + table + " limit " + limit + " offset " + offset; - return select; - } - public void addInformationColumsToTable(String table) throws Exception{ AnalysisLogger.getLogger().debug("EstimateFishingActivity: initializing connection"); long t0 = System.currentTimeMillis(); @@ -240,3 +232,4 @@ public class EstimateFishingActivity extends GridCWP2Coordinates{ } } + diff --git a/src/main/java/org/gcube/dataanalysis/geo/vti/GridCWP2Coordinates.java b/src/main/java/org/gcube/dataanalysis/geo/vti/GridCWP2Coordinates.java index cd02d67..5903e60 100644 --- a/src/main/java/org/gcube/dataanalysis/geo/vti/GridCWP2Coordinates.java +++ b/src/main/java/org/gcube/dataanalysis/geo/vti/GridCWP2Coordinates.java @@ -230,3 +230,4 @@ public class GridCWP2Coordinates extends StandardLocalExternalAlgorithm{ } } + diff --git a/src/main/java/org/gcube/dataanalysis/geo/vti/vesselsprocessing/Bathymetry.java b/src/main/java/org/gcube/dataanalysis/geo/vti/vesselsprocessing/Bathymetry.java index 4a0b2f1..34633a4 100644 --- a/src/main/java/org/gcube/dataanalysis/geo/vti/vesselsprocessing/Bathymetry.java +++ b/src/main/java/org/gcube/dataanalysis/geo/vti/vesselsprocessing/Bathymetry.java @@ -8,6 +8,7 @@ public class Bathymetry { public static void init() throws Exception { bathymetryObj.open(); } + public static void close() throws Exception { bathymetryObj.close(); diff --git a/src/main/java/org/gcube/dataanalysis/geo/vti/vesselsprocessing/FishingHoursCalculator.java b/src/main/java/org/gcube/dataanalysis/geo/vti/vesselsprocessing/FishingHoursCalculator.java index 5261d21..67ed980 100644 --- a/src/main/java/org/gcube/dataanalysis/geo/vti/vesselsprocessing/FishingHoursCalculator.java +++ b/src/main/java/org/gcube/dataanalysis/geo/vti/vesselsprocessing/FishingHoursCalculator.java @@ -7,8 +7,7 @@ import org.gcube.contentmanagement.graphtools.utils.MathFunctions; public class FishingHoursCalculator { - - + public static double[] calculateFishingHours(String [] vesselIDsField,Date[] timeStamps){ int vNumber = vesselIDsField.length; double [] hours = new double[vNumber]; diff --git a/src/main/java/org/gcube/dataanalysis/geo/vti/vesselsprocessing/MonthlyFishingEffortCalculator.java b/src/main/java/org/gcube/dataanalysis/geo/vti/vesselsprocessing/MonthlyFishingEffortCalculator.java index e1a10f6..85537f8 100644 --- a/src/main/java/org/gcube/dataanalysis/geo/vti/vesselsprocessing/MonthlyFishingEffortCalculator.java +++ b/src/main/java/org/gcube/dataanalysis/geo/vti/vesselsprocessing/MonthlyFishingEffortCalculator.java @@ -22,10 +22,11 @@ public class MonthlyFishingEffortCalculator { return monthsDiff; } + // positional Object: x,y,date,hours private double minEffort; private double maxEffort; - + //x,y,date,hours,activity public Map calculateMonthlyFishingEffort(List rows, Date minDate, Date maxDate) { HashMap csquare2month = new HashMap(); @@ -36,13 +37,13 @@ public class MonthlyFishingEffortCalculator { for (int i = 0; i < numOfPoints; i++) { Object[] singleRow = (Object[]) rows.get(i); - double x = Float.parseFloat(""+singleRow[0]); - double y = Float.parseFloat(""+singleRow[1]); + double x = (Double) singleRow[0]; + double y = (Double) singleRow[1]; Date d = (Date) singleRow[2]; - double hours = (Float) singleRow[3]; - double speed = Double.parseDouble("" + singleRow[4]); + double hours = (Double) singleRow[3]; + String activity = ((String) singleRow[4]).toLowerCase(); - if ((speed >= 2) && (speed <= 6)) { + if (activity.equalsIgnoreCase("fishing")) { String csquare = CSquareCodesConverter.convertHalfDegree(x, y); double[] csquaremontheffort = csquaremonths.get(csquare); diff --git a/src/main/java/org/gcube/dataanalysis/geo/vti/vesselsprocessing/VTIBathymetry.java b/src/main/java/org/gcube/dataanalysis/geo/vti/vesselsprocessing/VTIBathymetry.java index d6f39e1..8b14829 100644 --- a/src/main/java/org/gcube/dataanalysis/geo/vti/vesselsprocessing/VTIBathymetry.java +++ b/src/main/java/org/gcube/dataanalysis/geo/vti/vesselsprocessing/VTIBathymetry.java @@ -37,6 +37,7 @@ public class VTIBathymetry { * If only one pair of coordinates is specified, debug information about the calculation is written. * @param args the command-line arguments */ + public static void main(String[] args) { int status = 0; VTIBathymetry bm = new VTIBathymetry(); diff --git a/src/main/java/org/gcube/dataanalysis/geo/vti/vesselsprocessing/VTIClassificator.java b/src/main/java/org/gcube/dataanalysis/geo/vti/vesselsprocessing/VTIClassificator.java index a68c9e4..60e7c40 100644 --- a/src/main/java/org/gcube/dataanalysis/geo/vti/vesselsprocessing/VTIClassificator.java +++ b/src/main/java/org/gcube/dataanalysis/geo/vti/vesselsprocessing/VTIClassificator.java @@ -19,6 +19,7 @@ public class VTIClassificator { return "Unclassified"; } + public static String bathymetryClassification(int classif){ if (classif==1)