Management of the Bio-Oracle and ASC layers

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-analysis/EcologicalEngineGeoSpatialExtension@81692 82a268e6-3cf1-43bd-a215-b396298e98cf
master
Gianpaolo Coro 11 years ago
parent 6ec736a82e
commit ed0f54443d

Binary file not shown.

2166
ph.asc

File diff suppressed because one or more lines are too long

@ -81,7 +81,7 @@
<artifactId>common-utils-encryption</artifactId>
<version>[1.0.2-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<dependency>
<groupId>org.gcube.externals</groupId>
<artifactId>geo-utils-custom-opendap</artifactId>
<version>2.2.0</version>

@ -60,7 +60,7 @@ public class MapsComparator extends DataAnalysis {
@Override
public String getDescription() {
return "An algorithm for comparing two OGC/NetCDF maps in seamless way to the user";
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.";
}
@Override
@ -161,7 +161,9 @@ public class MapsComparator extends DataAnalysis {
if (resolution == 0)
resolution = 0.5d;
// I added the following control to limit the amount of calculations
if (resolution<0.01)
if (resolution<0.5 && resolution>0.01)
resolution = 0.5d;
else if (resolution<0.01)
resolution = 0.01d;
AnalysisLogger.getLogger().debug("MapsComparator: Evaluation Indeed at Resolution: " + resolution);

@ -0,0 +1,673 @@
package org.gcube.dataanalysis.geo.batch;
import java.text.DateFormat;
import java.util.Date;
import org.gcube.dataanalysis.geo.meta.GenericLayerMetadata;
import org.opengis.metadata.identification.TopicCategory;
import com.ibm.icu.text.SimpleDateFormat;
public class BioOracleMetadataInsertDev {
static String geonetworkurl = "http://geoserver-dev2.d4science-ii.research-infrastructures.eu/geonetwork/";
// static String geonetworkurl = "http://geoserver-last.d4science-ii.research-infrastructures.eu/geonetwork/";
/*
static String geonetworkurl = "http://geonetwork.d4science.org/geonetwork/";
static String geoserverurl = "http://geoserver.d4science-ii.research-infrastructures.eu/geoserver";
*/
//static String geoserverurl = "http://geoserver-dev.d4science-ii.research-infrastructures.eu/geoserver";
static String user = "admin";
static String password = "admin";
public static void main(String[] args) throws Exception{
calcite();
chlorophyllMax();
chlorophyllMean();
chlorophyllMin();
chlorophyllRange();
cloudMax();
cloudMean();
cloudMin();
diffuseattenuationMax();
diffuseattenuationMean();
diffuseattenuationMin();
dissox();
nitrateMean();
parmax();
parmean();
ph();
phosphate();
salinity();
silicate();
sstmax();
sstmean();
sstmin();
sstrange();
}
private static void calcite() throws Exception{
GenericLayerMetadata metadataInserter = new GenericLayerMetadata();
metadataInserter.setGeonetworkUrl(geonetworkurl);
metadataInserter.setGeonetworkUser(user);
metadataInserter.setGeonetworkPwd(password);
metadataInserter.setTitle("Bio-Oracle Calcite Concentration (Mean)");
metadataInserter.setCategoryTypes("_"+TopicCategory.ENVIRONMENT.name()+"_");
metadataInserter.setResolution(0.083);
metadataInserter.setAbstractField("Mean Calcite concentration (mol/m^3). Aggregated between [2002-2009]. From Bio-Oracle: Tyberghein L., Verbruggen H., Pauly K., Troupin C., Mineur F. & De Clerck O. Bio-ORACLE: a global environmental dataset for marine species distribution modeling. Global Ecology and Biogeography. Hosted on the D4Science Thredds Catalog: http://thredds.research-infrastructures.eu/thredds/catalog/public/netcdf/catalog.xml");
metadataInserter.setCustomTopics("Mean Calcite concentration","D4Science","i-Marine","Bio-Oracle","Thredds","2D");
metadataInserter.setAuthor("D4Science");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy");
Date datestart = formatter.parse("2002");
Date dateend = formatter.parse("2009");
metadataInserter.setStartDate(datestart);
metadataInserter.setEndDate(dateend);
String [] urls = {"http://thredds.research-infrastructures.eu/thredds/fileServer/public/netcdf/calcite.asc"};
String [] protocols = {"HTTP"};
metadataInserter.customMetaDataInsert(urls,protocols);
}
private static void chlorophyllMax() throws Exception{
GenericLayerMetadata metadataInserter = new GenericLayerMetadata();
metadataInserter.setGeonetworkUrl(geonetworkurl);
metadataInserter.setGeonetworkUser(user);
metadataInserter.setGeonetworkPwd(password);
metadataInserter.setTitle("Bio-Oracle Chlorophyll A Concentration (Max)");
metadataInserter.setCategoryTypes("_"+TopicCategory.ENVIRONMENT.name()+"_"+TopicCategory.OCEANS.name()+"_");
metadataInserter.setResolution(0.083);
metadataInserter.setAbstractField("Maximum Chlorophyll A Concentration (mg/m^3). Aggregated between [2002-2009]. From Bio-Oracle: Tyberghein L., Verbruggen H., Pauly K., Troupin C., Mineur F. & De Clerck O. Bio-ORACLE: a global environmental dataset for marine species distribution modeling. Global Ecology and Biogeography. Hosted on the D4Science Thredds Catalog: http://thredds.research-infrastructures.eu/thredds/catalog/public/netcdf/catalog.xml");
metadataInserter.setCustomTopics("Maximum Chlorophyll A Concentration","Chlorophyll","D4Science","i-Marine","Bio-Oracle","Thredds","2D");
metadataInserter.setAuthor("D4Science");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy");
Date datestart = formatter.parse("2002");
Date dateend = formatter.parse("2009");
metadataInserter.setStartDate(datestart);
metadataInserter.setEndDate(dateend);
String [] urls = {"http://thredds.research-infrastructures.eu/thredds/fileServer/public/netcdf/chlomax.asc"};
String [] protocols = {"HTTP"};
metadataInserter.customMetaDataInsert(urls,protocols);
}
private static void chlorophyllMean() throws Exception{
GenericLayerMetadata metadataInserter = new GenericLayerMetadata();
metadataInserter.setGeonetworkUrl(geonetworkurl);
metadataInserter.setGeonetworkUser(user);
metadataInserter.setGeonetworkPwd(password);
metadataInserter.setTitle("Bio-Oracle Chlorophyll A Concentration (Mean)");
metadataInserter.setCategoryTypes("_"+TopicCategory.ENVIRONMENT.name()+"_"+TopicCategory.OCEANS.name()+"_");
metadataInserter.setResolution(0.083);
metadataInserter.setAbstractField("Mean Chlorophyll A Concentration (mg/m^3). Aggregated between [2002-2009]. From Bio-Oracle: Tyberghein L., Verbruggen H., Pauly K., Troupin C., Mineur F. & De Clerck O. Bio-ORACLE: a global environmental dataset for marine species distribution modeling. Global Ecology and Biogeography. Hosted on the D4Science Thredds Catalog: http://thredds.research-infrastructures.eu/thredds/catalog/public/netcdf/catalog.xml");
metadataInserter.setCustomTopics("Mean Chlorophyll A Concentration","Chlorophyll","D4Science","i-Marine","Bio-Oracle","Thredds","2D");
metadataInserter.setAuthor("D4Science");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy");
Date datestart = formatter.parse("2002");
Date dateend = formatter.parse("2009");
metadataInserter.setStartDate(datestart);
metadataInserter.setEndDate(dateend);
String [] urls = {"http://thredds.research-infrastructures.eu/thredds/fileServer/public/netcdf/chlomean.asc"};
String [] protocols = {"HTTP"};
metadataInserter.customMetaDataInsert(urls,protocols);
}
private static void chlorophyllMin() throws Exception{
GenericLayerMetadata metadataInserter = new GenericLayerMetadata();
metadataInserter.setGeonetworkUrl(geonetworkurl);
metadataInserter.setGeonetworkUser(user);
metadataInserter.setGeonetworkPwd(password);
metadataInserter.setTitle("Bio-Oracle Chlorophyll A Concentration (Min)");
metadataInserter.setCategoryTypes("_"+TopicCategory.ENVIRONMENT.name()+"_"+TopicCategory.OCEANS.name()+"_");
metadataInserter.setResolution(0.083);
metadataInserter.setAbstractField("Minimum Chlorophyll A Concentration (mg/m^3). Aggregated between [2002-2009]. From Bio-Oracle: Tyberghein L., Verbruggen H., Pauly K., Troupin C., Mineur F. & De Clerck O. Bio-ORACLE: a global environmental dataset for marine species distribution modeling. Global Ecology and Biogeography. Hosted on the D4Science Thredds Catalog: http://thredds.research-infrastructures.eu/thredds/catalog/public/netcdf/catalog.xml");
metadataInserter.setCustomTopics("Minimum Chlorophyll A Concentration","Chlorophyll","D4Science","i-Marine","Bio-Oracle","Thredds","2D");
metadataInserter.setAuthor("D4Science");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy");
Date datestart = formatter.parse("2002");
Date dateend = formatter.parse("2009");
metadataInserter.setStartDate(datestart);
metadataInserter.setEndDate(dateend);
String [] urls = {"http://thredds.research-infrastructures.eu/thredds/fileServer/public/netcdf/chlomin.asc"};
String [] protocols = {"HTTP"};
metadataInserter.customMetaDataInsert(urls,protocols);
}
private static void chlorophyllRange() throws Exception{
GenericLayerMetadata metadataInserter = new GenericLayerMetadata();
metadataInserter.setGeonetworkUrl(geonetworkurl);
metadataInserter.setGeonetworkUser(user);
metadataInserter.setGeonetworkPwd(password);
metadataInserter.setTitle("Bio-Oracle Chlorophyll A Concentration (Range)");
metadataInserter.setCategoryTypes("_"+TopicCategory.ENVIRONMENT.name()+"_"+TopicCategory.OCEANS.name()+"_");
metadataInserter.setResolution(0.083);
metadataInserter.setAbstractField("Range Chlorophyll A Concentration (mg/m^3). Aggregated between [2002-2009]. From Bio-Oracle: Tyberghein L., Verbruggen H., Pauly K., Troupin C., Mineur F. & De Clerck O. Bio-ORACLE: a global environmental dataset for marine species distribution modeling. Global Ecology and Biogeography. Hosted on the D4Science Thredds Catalog: http://thredds.research-infrastructures.eu/thredds/catalog/public/netcdf/catalog.xml");
metadataInserter.setCustomTopics("Range Chlorophyll A Concentration","Chlorophyll","D4Science","i-Marine","Bio-Oracle","Thredds","2D");
metadataInserter.setAuthor("D4Science");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy");
Date datestart = formatter.parse("2002");
Date dateend = formatter.parse("2009");
metadataInserter.setStartDate(datestart);
metadataInserter.setEndDate(dateend);
String [] urls = {"http://thredds.research-infrastructures.eu/thredds/fileServer/public/netcdf/chlorange.asc"};
String [] protocols = {"HTTP"};
metadataInserter.customMetaDataInsert(urls,protocols);
}
private static void cloudMax() throws Exception{
GenericLayerMetadata metadataInserter = new GenericLayerMetadata();
metadataInserter.setGeonetworkUrl(geonetworkurl);
metadataInserter.setGeonetworkUser(user);
metadataInserter.setGeonetworkPwd(password);
metadataInserter.setTitle("Bio-Oracle Cloud Fraction (Max)");
metadataInserter.setCategoryTypes("_"+TopicCategory.CLIMATOLOGY_METEOROLOGY_ATMOSPHERE.name()+"_");
metadataInserter.setResolution(0.083);
metadataInserter.setAbstractField("Maximum Cloud Fraction (percentage). Aggregated between [2005-2010]. From Bio-Oracle: Tyberghein L., Verbruggen H., Pauly K., Troupin C., Mineur F. & De Clerck O. Bio-ORACLE: a global environmental dataset for marine species distribution modeling. Global Ecology and Biogeography. Hosted on the D4Science Thredds Catalog: http://thredds.research-infrastructures.eu/thredds/catalog/public/netcdf/catalog.xml");
metadataInserter.setCustomTopics("Maximum Cloud Fraction","Cloud Fraction","D4Science","i-Marine","Bio-Oracle","Thredds","2D");
metadataInserter.setAuthor("D4Science");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy");
Date datestart = formatter.parse("2005");
Date dateend = formatter.parse("2010");
metadataInserter.setStartDate(datestart);
metadataInserter.setEndDate(dateend);
String [] urls = {"http://thredds.research-infrastructures.eu/thredds/fileServer/public/netcdf/cloudmax.asc"};
String [] protocols = {"HTTP"};
metadataInserter.customMetaDataInsert(urls,protocols);
}
private static void cloudMin() throws Exception{
GenericLayerMetadata metadataInserter = new GenericLayerMetadata();
metadataInserter.setGeonetworkUrl(geonetworkurl);
metadataInserter.setGeonetworkUser(user);
metadataInserter.setGeonetworkPwd(password);
metadataInserter.setTitle("Bio-Oracle Cloud Fraction (Min)");
metadataInserter.setCategoryTypes("_"+TopicCategory.CLIMATOLOGY_METEOROLOGY_ATMOSPHERE.name()+"_");
metadataInserter.setResolution(0.083);
metadataInserter.setAbstractField("Minimum Cloud Fraction (percentage). Aggregated between [2005-2010]. From Bio-Oracle: Tyberghein L., Verbruggen H., Pauly K., Troupin C., Mineur F. & De Clerck O. Bio-ORACLE: a global environmental dataset for marine species distribution modeling. Global Ecology and Biogeography. Hosted on the D4Science Thredds Catalog: http://thredds.research-infrastructures.eu/thredds/catalog/public/netcdf/catalog.xml");
metadataInserter.setCustomTopics("Minimum Cloud Fraction","Cloud Fraction","D4Science","i-Marine","Bio-Oracle","Thredds","2D");
metadataInserter.setAuthor("D4Science");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy");
Date datestart = formatter.parse("2005");
Date dateend = formatter.parse("2010");
metadataInserter.setStartDate(datestart);
metadataInserter.setEndDate(dateend);
String [] urls = {"http://thredds.research-infrastructures.eu/thredds/fileServer/public/netcdf/cloudmin.asc"};
String [] protocols = {"HTTP"};
metadataInserter.customMetaDataInsert(urls,protocols);
}
private static void cloudMean() throws Exception{
GenericLayerMetadata metadataInserter = new GenericLayerMetadata();
metadataInserter.setGeonetworkUrl(geonetworkurl);
metadataInserter.setGeonetworkUser(user);
metadataInserter.setGeonetworkPwd(password);
metadataInserter.setTitle("Bio-Oracle Cloud Fraction (Mean)");
metadataInserter.setCategoryTypes("_"+TopicCategory.CLIMATOLOGY_METEOROLOGY_ATMOSPHERE.name()+"_");
metadataInserter.setResolution(0.083);
metadataInserter.setAbstractField("Mean Cloud Fraction (percentage). Aggregated between [2005-2010]. From Bio-Oracle: Tyberghein L., Verbruggen H., Pauly K., Troupin C., Mineur F. & De Clerck O. Bio-ORACLE: a global environmental dataset for marine species distribution modeling. Global Ecology and Biogeography. Hosted on the D4Science Thredds Catalog: http://thredds.research-infrastructures.eu/thredds/catalog/public/netcdf/catalog.xml");
metadataInserter.setCustomTopics("Mean Cloud Fraction","Cloud Fraction","D4Science","i-Marine","Bio-Oracle","Thredds","2D");
metadataInserter.setAuthor("D4Science");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy");
Date datestart = formatter.parse("2005");
Date dateend = formatter.parse("2010");
metadataInserter.setStartDate(datestart);
metadataInserter.setEndDate(dateend);
String [] urls = {"http://thredds.research-infrastructures.eu/thredds/fileServer/public/netcdf/cloudmean.asc"};
String [] protocols = {"HTTP"};
metadataInserter.customMetaDataInsert(urls,protocols);
}
private static void diffuseattenuationMax() throws Exception{
GenericLayerMetadata metadataInserter = new GenericLayerMetadata();
metadataInserter.setGeonetworkUrl(geonetworkurl);
metadataInserter.setGeonetworkUser(user);
metadataInserter.setGeonetworkPwd(password);
metadataInserter.setTitle("Bio-Oracle Diffuse Attenuation Coefficient at 490mm (Max)");
metadataInserter.setCategoryTypes("_"+TopicCategory.ENVIRONMENT.name()+"_");
metadataInserter.setResolution(0.083);
metadataInserter.setAbstractField("Maximum Diffuse Attenuation Coefficient at 490mm (m^-1). Aggregated between [2002-2009]. From Bio-Oracle: Tyberghein L., Verbruggen H., Pauly K., Troupin C., Mineur F. & De Clerck O. Bio-ORACLE: a global environmental dataset for marine species distribution modeling. Global Ecology and Biogeography. Hosted on the D4Science Thredds Catalog: http://thredds.research-infrastructures.eu/thredds/catalog/public/netcdf/catalog.xml");
metadataInserter.setCustomTopics("Maximum Diffuse Attenuation Coefficient","Diffuse Attenuation Coefficient","D4Science","i-Marine","Bio-Oracle","Thredds","2D");
metadataInserter.setAuthor("D4Science");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy");
Date datestart = formatter.parse("2002");
Date dateend = formatter.parse("2009");
metadataInserter.setStartDate(datestart);
metadataInserter.setEndDate(dateend);
String [] urls = {"http://thredds.research-infrastructures.eu/thredds/fileServer/public/netcdf/damax.asc"};
String [] protocols = {"HTTP"};
metadataInserter.customMetaDataInsert(urls,protocols);
}
private static void diffuseattenuationMean() throws Exception{
GenericLayerMetadata metadataInserter = new GenericLayerMetadata();
metadataInserter.setGeonetworkUrl(geonetworkurl);
metadataInserter.setGeonetworkUser(user);
metadataInserter.setGeonetworkPwd(password);
metadataInserter.setTitle("Bio-Oracle Diffuse Attenuation Coefficient at 490mm (Mean)");
metadataInserter.setCategoryTypes("_"+TopicCategory.ENVIRONMENT.name()+"_");
metadataInserter.setResolution(0.083);
metadataInserter.setAbstractField("Mean Diffuse Attenuation Coefficient at 490mm (m^-1). Aggregated between [2002-2009]. From Bio-Oracle: Tyberghein L., Verbruggen H., Pauly K., Troupin C., Mineur F. & De Clerck O. Bio-ORACLE: a global environmental dataset for marine species distribution modeling. Global Ecology and Biogeography. Hosted on the D4Science Thredds Catalog: http://thredds.research-infrastructures.eu/thredds/catalog/public/netcdf/catalog.xml");
metadataInserter.setCustomTopics("Mean Diffuse Attenuation Coefficient","Diffuse Attenuation Coefficient","D4Science","i-Marine","Bio-Oracle","Thredds","2D");
metadataInserter.setAuthor("D4Science");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy");
Date datestart = formatter.parse("2002");
Date dateend = formatter.parse("2009");
metadataInserter.setStartDate(datestart);
metadataInserter.setEndDate(dateend);
String [] urls = {"http://thredds.research-infrastructures.eu/thredds/fileServer/public/netcdf/damean.asc"};
String [] protocols = {"HTTP"};
metadataInserter.customMetaDataInsert(urls,protocols);
}
private static void diffuseattenuationMin() throws Exception{
GenericLayerMetadata metadataInserter = new GenericLayerMetadata();
metadataInserter.setGeonetworkUrl(geonetworkurl);
metadataInserter.setGeonetworkUser(user);
metadataInserter.setGeonetworkPwd(password);
metadataInserter.setTitle("Bio-Oracle Diffuse Attenuation Coefficient at 490mm (Min)");
metadataInserter.setCategoryTypes("_"+TopicCategory.ENVIRONMENT.name()+"_");
metadataInserter.setResolution(0.083);
metadataInserter.setAbstractField("Minimum Diffuse Attenuation Coefficient at 490mm (m^-1). Aggregated between [2002-2009]. From Bio-Oracle: Tyberghein L., Verbruggen H., Pauly K., Troupin C., Mineur F. & De Clerck O. Bio-ORACLE: a global environmental dataset for marine species distribution modeling. Global Ecology and Biogeography. Hosted on the D4Science Thredds Catalog: http://thredds.research-infrastructures.eu/thredds/catalog/public/netcdf/catalog.xml");
metadataInserter.setCustomTopics("Minimum Diffuse Attenuation Coefficient","Diffuse Attenuation Coefficient","D4Science","i-Marine","Bio-Oracle","Thredds","2D");
metadataInserter.setAuthor("D4Science");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy");
Date datestart = formatter.parse("2002");
Date dateend = formatter.parse("2009");
metadataInserter.setStartDate(datestart);
metadataInserter.setEndDate(dateend);
String [] urls = {"http://thredds.research-infrastructures.eu/thredds/fileServer/public/netcdf/damin.asc"};
String [] protocols = {"HTTP"};
metadataInserter.customMetaDataInsert(urls,protocols);
}
private static void dissox() throws Exception{
GenericLayerMetadata metadataInserter = new GenericLayerMetadata();
metadataInserter.setGeonetworkUrl(geonetworkurl);
metadataInserter.setGeonetworkUser(user);
metadataInserter.setGeonetworkPwd(password);
metadataInserter.setTitle("Bio-Oracle Dissolved Oxygen Concentration (Mean)");
metadataInserter.setCategoryTypes("_"+TopicCategory.ENVIRONMENT.name()+"_"+TopicCategory.OCEANS.name()+"_");
metadataInserter.setResolution(0.083);
metadataInserter.setAbstractField("Mean Dissolved Oxygen Concentration (ml/l). Aggregated between [1898-2009]. From Bio-Oracle: Tyberghein L., Verbruggen H., Pauly K., Troupin C., Mineur F. & De Clerck O. Bio-ORACLE: a global environmental dataset for marine species distribution modeling. Global Ecology and Biogeography. Hosted on the D4Science Thredds Catalog: http://thredds.research-infrastructures.eu/thredds/catalog/public/netcdf/catalog.xml");
metadataInserter.setCustomTopics("Mean Dissolved Oxygen Concentration","Dissolved Oxygen Concentration","D4Science","i-Marine","Bio-Oracle","Thredds","2D");
metadataInserter.setAuthor("D4Science");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy");
Date datestart = formatter.parse("1898");
Date dateend = formatter.parse("2009");
metadataInserter.setStartDate(datestart);
metadataInserter.setEndDate(dateend);
String [] urls = {"http://thredds.research-infrastructures.eu/thredds/fileServer/public/netcdf/dissox.asc"};
String [] protocols = {"HTTP"};
metadataInserter.customMetaDataInsert(urls,protocols);
}
private static void nitrateMean() throws Exception{
GenericLayerMetadata metadataInserter = new GenericLayerMetadata();
metadataInserter.setGeonetworkUrl(geonetworkurl);
metadataInserter.setGeonetworkUser(user);
metadataInserter.setGeonetworkPwd(password);
metadataInserter.setTitle("Bio-Oracle Nitrate (Mean)");
metadataInserter.setCategoryTypes("_"+TopicCategory.ENVIRONMENT.name()+"_");
metadataInserter.setResolution(0.083);
metadataInserter.setAbstractField("Mean Nitrate (umol/l). Aggregated between [1928-2008]. From Bio-Oracle: Tyberghein L., Verbruggen H., Pauly K., Troupin C., Mineur F. & De Clerck O. Bio-ORACLE: a global environmental dataset for marine species distribution modeling. Global Ecology and Biogeography. Hosted on the D4Science Thredds Catalog: http://thredds.research-infrastructures.eu/thredds/catalog/public/netcdf/catalog.xml");
metadataInserter.setCustomTopics("Mean Nitrate","Nitrate","D4Science","i-Marine","Bio-Oracle","Thredds","2D");
metadataInserter.setAuthor("D4Science");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy");
Date datestart = formatter.parse("1928");
Date dateend = formatter.parse("2008");
metadataInserter.setStartDate(datestart);
metadataInserter.setEndDate(dateend);
String [] urls = {"http://thredds.research-infrastructures.eu/thredds/fileServer/public/netcdf/nitrate.asc"};
String [] protocols = {"HTTP"};
metadataInserter.customMetaDataInsert(urls,protocols);
}
private static void parmax() throws Exception{
GenericLayerMetadata metadataInserter = new GenericLayerMetadata();
metadataInserter.setGeonetworkUrl(geonetworkurl);
metadataInserter.setGeonetworkUser(user);
metadataInserter.setGeonetworkPwd(password);
metadataInserter.setTitle("Bio-Oracle Photosynthetically Available Radiation (Max)");
metadataInserter.setCategoryTypes("_"+TopicCategory.ENVIRONMENT.name()+"_");
metadataInserter.setResolution(0.083);
metadataInserter.setAbstractField("Maximum Photosynthetically Available Radiation (Einstein/m^2/day). Aggregated between [1997-2009]. From Bio-Oracle: Tyberghein L., Verbruggen H., Pauly K., Troupin C., Mineur F. & De Clerck O. Bio-ORACLE: a global environmental dataset for marine species distribution modeling. Global Ecology and Biogeography. Hosted on the D4Science Thredds Catalog: http://thredds.research-infrastructures.eu/thredds/catalog/public/netcdf/catalog.xml");
metadataInserter.setCustomTopics("Maximum Photosynthetically Available Radiation","Photosynthetically Available Radiation","D4Science","i-Marine","Bio-Oracle","Thredds","2D");
metadataInserter.setAuthor("D4Science");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy");
Date datestart = formatter.parse("1997");
Date dateend = formatter.parse("2009");
metadataInserter.setStartDate(datestart);
metadataInserter.setEndDate(dateend);
String [] urls = {"http://thredds.research-infrastructures.eu/thredds/fileServer/public/netcdf/parmax.asc"};
String [] protocols = {"HTTP"};
metadataInserter.customMetaDataInsert(urls,protocols);
}
private static void parmean() throws Exception{
GenericLayerMetadata metadataInserter = new GenericLayerMetadata();
metadataInserter.setGeonetworkUrl(geonetworkurl);
metadataInserter.setGeonetworkUser(user);
metadataInserter.setGeonetworkPwd(password);
metadataInserter.setTitle("Bio-Oracle Photosynthetically Available Radiation (Mean)");
metadataInserter.setCategoryTypes("_"+TopicCategory.ENVIRONMENT.name()+"_");
metadataInserter.setResolution(0.083);
metadataInserter.setAbstractField("Mean Photosynthetically Available Radiation (Einstein/m^2/day). Aggregated between [1997-2009]. From Bio-Oracle: Tyberghein L., Verbruggen H., Pauly K., Troupin C., Mineur F. & De Clerck O. Bio-ORACLE: a global environmental dataset for marine species distribution modeling. Global Ecology and Biogeography. Hosted on the D4Science Thredds Catalog: http://thredds.research-infrastructures.eu/thredds/catalog/public/netcdf/catalog.xml");
metadataInserter.setCustomTopics("Mean Photosynthetically Available Radiation","Photosynthetically Available Radiation","D4Science","i-Marine","Bio-Oracle","Thredds","2D");
metadataInserter.setAuthor("D4Science");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy");
Date datestart = formatter.parse("1997");
Date dateend = formatter.parse("2009");
metadataInserter.setStartDate(datestart);
metadataInserter.setEndDate(dateend);
String [] urls = {"http://thredds.research-infrastructures.eu/thredds/fileServer/public/netcdf/parmean.asc"};
String [] protocols = {"HTTP"};
metadataInserter.customMetaDataInsert(urls,protocols);
}
private static void ph() throws Exception{
GenericLayerMetadata metadataInserter = new GenericLayerMetadata();
metadataInserter.setGeonetworkUrl(geonetworkurl);
metadataInserter.setGeonetworkUser(user);
metadataInserter.setGeonetworkPwd(password);
metadataInserter.setTitle("Bio-Oracle Ph (Mean)");
metadataInserter.setCategoryTypes("_"+TopicCategory.ENVIRONMENT.name()+"_"+TopicCategory.OCEANS.name()+"_");
metadataInserter.setResolution(0.083);
metadataInserter.setAbstractField("Mean Ph (unitless). Aggregated between [1910-2007]. From Bio-Oracle: Tyberghein L., Verbruggen H., Pauly K., Troupin C., Mineur F. & De Clerck O. Bio-ORACLE: a global environmental dataset for marine species distribution modeling. Global Ecology and Biogeography. Hosted on the D4Science Thredds Catalog: http://thredds.research-infrastructures.eu/thredds/catalog/public/netcdf/catalog.xml");
metadataInserter.setCustomTopics("Mean Ph","Ph","D4Science","i-Marine","Bio-Oracle","Thredds","2D");
metadataInserter.setAuthor("D4Science");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy");
Date datestart = formatter.parse("1910");
Date dateend = formatter.parse("2007");
metadataInserter.setStartDate(datestart);
metadataInserter.setEndDate(dateend);
String [] urls = {"http://thredds.research-infrastructures.eu/thredds/fileServer/public/netcdf/ph.asc"};
String [] protocols = {"HTTP"};
metadataInserter.customMetaDataInsert(urls,protocols);
}
private static void phosphate() throws Exception{
GenericLayerMetadata metadataInserter = new GenericLayerMetadata();
metadataInserter.setGeonetworkUrl(geonetworkurl);
metadataInserter.setGeonetworkUser(user);
metadataInserter.setGeonetworkPwd(password);
metadataInserter.setTitle("Bio-Oracle Phosphate (Mean)");
metadataInserter.setCategoryTypes("_"+TopicCategory.ENVIRONMENT.name()+"_");
metadataInserter.setResolution(0.083);
metadataInserter.setAbstractField("Mean Phosphate (umol/l). Aggregated between [1922-1986]. From Bio-Oracle: Tyberghein L., Verbruggen H., Pauly K., Troupin C., Mineur F. & De Clerck O. Bio-ORACLE: a global environmental dataset for marine species distribution modeling. Global Ecology and Biogeography. Hosted on the D4Science Thredds Catalog: http://thredds.research-infrastructures.eu/thredds/catalog/public/netcdf/catalog.xml");
metadataInserter.setCustomTopics("Mean Phosphate","Phosphate","D4Science","i-Marine","Bio-Oracle","Thredds","2D");
metadataInserter.setAuthor("D4Science");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy");
Date datestart = formatter.parse("1922");
Date dateend = formatter.parse("1986");
metadataInserter.setStartDate(datestart);
metadataInserter.setEndDate(dateend);
String [] urls = {"http://thredds.research-infrastructures.eu/thredds/fileServer/public/netcdf/phosphate.asc"};
String [] protocols = {"HTTP"};
metadataInserter.customMetaDataInsert(urls,protocols);
}
private static void salinity() throws Exception{
GenericLayerMetadata metadataInserter = new GenericLayerMetadata();
metadataInserter.setGeonetworkUrl(geonetworkurl);
metadataInserter.setGeonetworkUser(user);
metadataInserter.setGeonetworkPwd(password);
metadataInserter.setTitle("Bio-Oracle Salinity (Mean)");
metadataInserter.setCategoryTypes("_"+TopicCategory.ENVIRONMENT.name()+"_"+TopicCategory.OCEANS.name()+"_");
metadataInserter.setResolution(0.083);
metadataInserter.setAbstractField("Mean Salinity (PSS). Aggregated between [1961-2009]. From Bio-Oracle: Tyberghein L., Verbruggen H., Pauly K., Troupin C., Mineur F. & De Clerck O. Bio-ORACLE: a global environmental dataset for marine species distribution modeling. Global Ecology and Biogeography. Hosted on the D4Science Thredds Catalog: http://thredds.research-infrastructures.eu/thredds/catalog/public/netcdf/catalog.xml");
metadataInserter.setCustomTopics("Mean Salinity","Salinity","D4Science","i-Marine","Bio-Oracle","Thredds","2D");
metadataInserter.setAuthor("D4Science");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy");
Date datestart = formatter.parse("1961");
Date dateend = formatter.parse("2009");
metadataInserter.setStartDate(datestart);
metadataInserter.setEndDate(dateend);
String [] urls = {"http://thredds.research-infrastructures.eu/thredds/fileServer/public/netcdf/salinity.asc"};
String [] protocols = {"HTTP"};
metadataInserter.customMetaDataInsert(urls,protocols);
}
private static void silicate() throws Exception{
GenericLayerMetadata metadataInserter = new GenericLayerMetadata();
metadataInserter.setGeonetworkUrl(geonetworkurl);
metadataInserter.setGeonetworkUser(user);
metadataInserter.setGeonetworkPwd(password);
metadataInserter.setTitle("Bio-Oracle Silicate (Mean)");
metadataInserter.setCategoryTypes("_"+TopicCategory.ENVIRONMENT.name()+"_");
metadataInserter.setResolution(0.083);
metadataInserter.setAbstractField("Mean Silicate (umol/l). Aggregated between [1930-2008]. From Bio-Oracle: Tyberghein L., Verbruggen H., Pauly K., Troupin C., Mineur F. & De Clerck O. Bio-ORACLE: a global environmental dataset for marine species distribution modeling. Global Ecology and Biogeography. Hosted on the D4Science Thredds Catalog: http://thredds.research-infrastructures.eu/thredds/catalog/public/netcdf/catalog.xml");
metadataInserter.setCustomTopics("Mean Silicate","Silicate","D4Science","i-Marine","Bio-Oracle","Thredds","2D");
metadataInserter.setAuthor("D4Science");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy");
Date datestart = formatter.parse("1930");
Date dateend = formatter.parse("2008");
metadataInserter.setStartDate(datestart);
metadataInserter.setEndDate(dateend);
String [] urls = {"http://thredds.research-infrastructures.eu/thredds/fileServer/public/netcdf/silicate.asc"};
String [] protocols = {"HTTP"};
metadataInserter.customMetaDataInsert(urls,protocols);
}
private static void sstmax() throws Exception{
GenericLayerMetadata metadataInserter = new GenericLayerMetadata();
metadataInserter.setGeonetworkUrl(geonetworkurl);
metadataInserter.setGeonetworkUser(user);
metadataInserter.setGeonetworkPwd(password);
metadataInserter.setTitle("Bio-Oracle Sea Surface Temperature (Max)");
metadataInserter.setCategoryTypes("_"+TopicCategory.ENVIRONMENT.name()+"_"+TopicCategory.OCEANS.name()+"_");
metadataInserter.setResolution(0.083);
metadataInserter.setAbstractField("Maximum Sea Surface Temperature (°C). Aggregated between [2002-2009]. From Bio-Oracle: Tyberghein L., Verbruggen H., Pauly K., Troupin C., Mineur F. & De Clerck O. Bio-ORACLE: a global environmental dataset for marine species distribution modeling. Global Ecology and Biogeography. Hosted on the D4Science Thredds Catalog: http://thredds.research-infrastructures.eu/thredds/catalog/public/netcdf/catalog.xml");
metadataInserter.setCustomTopics("Maximum Sea Surface Temperature","Sea Surface Temperature","D4Science","i-Marine","Bio-Oracle","Thredds","2D");
metadataInserter.setAuthor("D4Science");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy");
Date datestart = formatter.parse("2002");
Date dateend = formatter.parse("2009");
metadataInserter.setStartDate(datestart);
metadataInserter.setEndDate(dateend);
String [] urls = {"http://thredds.research-infrastructures.eu/thredds/fileServer/public/netcdf/sstmax.asc"};
String [] protocols = {"HTTP"};
metadataInserter.customMetaDataInsert(urls,protocols);
}
private static void sstmean() throws Exception{
GenericLayerMetadata metadataInserter = new GenericLayerMetadata();
metadataInserter.setGeonetworkUrl(geonetworkurl);
metadataInserter.setGeonetworkUser(user);
metadataInserter.setGeonetworkPwd(password);
metadataInserter.setTitle("Bio-Oracle Sea Surface Temperature (Mean)");
metadataInserter.setCategoryTypes("_"+TopicCategory.ENVIRONMENT.name()+"_"+TopicCategory.OCEANS.name()+"_");
metadataInserter.setResolution(0.083);
metadataInserter.setAbstractField("Mean Sea Surface Temperature (°C). Aggregated between [2002-2009]. From Bio-Oracle: Tyberghein L., Verbruggen H., Pauly K., Troupin C., Mineur F. & De Clerck O. Bio-ORACLE: a global environmental dataset for marine species distribution modeling. Global Ecology and Biogeography. Hosted on the D4Science Thredds Catalog: http://thredds.research-infrastructures.eu/thredds/catalog/public/netcdf/catalog.xml");
metadataInserter.setCustomTopics("Mean Sea Surface Temperature","Sea Surface Temperature","D4Science","i-Marine","Bio-Oracle","Thredds","2D");
metadataInserter.setAuthor("D4Science");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy");
Date datestart = formatter.parse("2002");
Date dateend = formatter.parse("2009");
metadataInserter.setStartDate(datestart);
metadataInserter.setEndDate(dateend);
String [] urls = {"http://thredds.research-infrastructures.eu/thredds/fileServer/public/netcdf/sstmean.asc"};
String [] protocols = {"HTTP"};
metadataInserter.customMetaDataInsert(urls,protocols);
}
private static void sstmin() throws Exception{
GenericLayerMetadata metadataInserter = new GenericLayerMetadata();
metadataInserter.setGeonetworkUrl(geonetworkurl);
metadataInserter.setGeonetworkUser(user);
metadataInserter.setGeonetworkPwd(password);
metadataInserter.setTitle("Bio-Oracle Sea Surface Temperature (Min)");
metadataInserter.setCategoryTypes("_"+TopicCategory.ENVIRONMENT.name()+"_"+TopicCategory.OCEANS.name()+"_");
metadataInserter.setResolution(0.083);
metadataInserter.setAbstractField("Minimum Sea Surface Temperature (°C). Aggregated between [2002-2009]. From Bio-Oracle: Tyberghein L., Verbruggen H., Pauly K., Troupin C., Mineur F. & De Clerck O. Bio-ORACLE: a global environmental dataset for marine species distribution modeling. Global Ecology and Biogeography. Hosted on the D4Science Thredds Catalog: http://thredds.research-infrastructures.eu/thredds/catalog/public/netcdf/catalog.xml");
metadataInserter.setCustomTopics("Minimum Sea Surface Temperature","Sea Surface Temperature","D4Science","i-Marine","Bio-Oracle","Thredds","2D");
metadataInserter.setAuthor("D4Science");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy");
Date datestart = formatter.parse("2002");
Date dateend = formatter.parse("2009");
metadataInserter.setStartDate(datestart);
metadataInserter.setEndDate(dateend);
String [] urls = {"http://thredds.research-infrastructures.eu/thredds/fileServer/public/netcdf/sstmin.asc"};
String [] protocols = {"HTTP"};
metadataInserter.customMetaDataInsert(urls,protocols);
}
private static void sstrange() throws Exception{
GenericLayerMetadata metadataInserter = new GenericLayerMetadata();
metadataInserter.setGeonetworkUrl(geonetworkurl);
metadataInserter.setGeonetworkUser(user);
metadataInserter.setGeonetworkPwd(password);
metadataInserter.setTitle("Bio-Oracle Sea Surface Temperature (Range)");
metadataInserter.setCategoryTypes("_"+TopicCategory.ENVIRONMENT.name()+"_"+TopicCategory.OCEANS.name()+"_");
metadataInserter.setResolution(0.083);
metadataInserter.setAbstractField("Range Sea Surface Temperature (°C). Aggregated between [2002-2009]. From Bio-Oracle: Tyberghein L., Verbruggen H., Pauly K., Troupin C., Mineur F. & De Clerck O. Bio-ORACLE: a global environmental dataset for marine species distribution modeling. Global Ecology and Biogeography. Hosted on the D4Science Thredds Catalog: http://thredds.research-infrastructures.eu/thredds/catalog/public/netcdf/catalog.xml");
metadataInserter.setCustomTopics("Range Sea Surface Temperature","Sea Surface Temperature","D4Science","i-Marine","Bio-Oracle","Thredds","2D");
metadataInserter.setAuthor("D4Science");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy");
Date datestart = formatter.parse("2002");
Date dateend = formatter.parse("2009");
metadataInserter.setStartDate(datestart);
metadataInserter.setEndDate(dateend);
String [] urls = {"http://thredds.research-infrastructures.eu/thredds/fileServer/public/netcdf/sstrange.asc"};
String [] protocols = {"HTTP"};
metadataInserter.customMetaDataInsert(urls,protocols);
}
}

@ -144,6 +144,10 @@ public class FeaturesManager {
return innerlayername;
}
public String getHttpLink(Metadata meta) {
return searchInUrl(meta, "http");
}
public String getWFSLink(Metadata meta) {
return searchInUrl(meta, "service=wfs");
}
@ -194,7 +198,12 @@ public class FeaturesManager {
public boolean isThreddsFile(Metadata meta) {
return (getOpenDapLink(meta) != null);
}
public boolean isAscFile(Metadata meta) {
String httplink = getHttpLink(meta);
return (httplink!=null && (httplink.endsWith(".asc")||httplink.endsWith(".ASC")));
}
public GeoNetworkReader initGeoNetworkReader() throws Exception {
AnalysisLogger.getLogger().debug("Features Manager: configuring GeoNetwork");
if (scope!=null)

@ -11,6 +11,7 @@ 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.AscDataExplorer;
import org.gcube.dataanalysis.geo.utils.EnvDataExplorer;
import org.gcube.dataanalysis.geo.utils.FeaturedPolygon;
import org.gcube.dataanalysis.geo.utils.ThreddsDataExplorer;
@ -98,7 +99,16 @@ public class GeoIntersector {
featuresSets.add(features);
}
*/
} else {
}
else if (featurer.isAscFile(meta)){
AnalysisLogger.getLogger().debug("managing ASC File");
String remoteFile = featurer.getHttpLink(meta);
AscDataExplorer asc = new AscDataExplorer(remoteFile);
features = asc.retrieveDataFromAsc(triplets);
AnalysisLogger.getLogger().debug("ASC File managed");
}
else {
AnalysisLogger.getLogger().debug("found a Geo Layer with reference " + layerTitle + " and layer name " + layer);
// AnalysisLogger.getLogger().debug("Taking point: (" + x + "," + y + ")");
List<FeaturedPolygon> featuresInTime = new ArrayList<FeaturedPolygon>();

@ -33,6 +33,7 @@ public class TestLayersRetrieval {
for (Metadata meta:metae){
Identification id = meta.getIdentificationInfo().iterator().next();
String title = id.getCitation().getTitle().toString();
String abstractF = id.getAbstract().toString();
DefaultDataIdentification did = (DefaultDataIdentification) id;
double resolution = MathFunctions.roundDecimal(did.getSpatialResolutions().iterator().next().getDistance(),3);
@ -45,7 +46,31 @@ public class TestLayersRetrieval {
unit = ss.substring(ss.indexOf(":")+1);
}
}
String[] elements = parseTitle(title);
String[] elements =null;
if (title.contains("Bio-Oracle"))
{
elements = new String[4];
elements[0]=title;
elements[1]=abstractF.substring(abstractF.indexOf("Aggregated"),abstractF.lastIndexOf("]")+1);
elements[2]="2D";
unit = abstractF.substring(abstractF.indexOf("(")+1,abstractF.lastIndexOf(")"));
elements[3]=abstractF;
}
else if (title.contains("GEBCO"))
{
elements = new String[4];
elements[0]=title;
elements[1]="2008";
elements[2]="3D";
unit = "m";
elements[3]=abstractF;
}
else if (title.contains("WorldClimBio")||title.contains("Etna")||title.contains("OpenModeller"))
{
continue;
}
else
elements = parseTitle(title);
String entry = elements[0]+d+elements[1]+d+elements[2]+d+unit+d+resolution+d+elements[3];
if (!table.contains(entry)){
table.add(entry);
@ -68,6 +93,7 @@ public class TestLayersRetrieval {
}
public static String[] parseTitle(String title){
// System.out.println("Parsing Title:"+title);
String timerange = title.substring(title.indexOf("["),title.lastIndexOf("]")+1);
// timerange = timerange.replace("] to [", " ; ");
// System.out.println(timerange);

@ -0,0 +1,46 @@
package org.gcube.dataanalysis.geo.test.maps;
import java.util.List;
import org.gcube.dataanalysis.ecoengine.configuration.AlgorithmConfiguration;
import org.gcube.dataanalysis.ecoengine.interfaces.ComputationalAgent;
import org.gcube.dataanalysis.ecoengine.interfaces.Evaluator;
import org.gcube.dataanalysis.ecoengine.processing.factories.EvaluatorsFactory;
import org.gcube.dataanalysis.ecoengine.test.regression.Regressor;
public class TestMapsComparisonASCFiles {
/**
* example of parallel processing on a single machine the procedure will generate a new table for a distribution on suitable species
*
*/
public static void main(String[] args) throws Exception {
List<ComputationalAgent> evaluators = EvaluatorsFactory.getEvaluators(testConfig1());
evaluators.get(0).init();
Regressor.process(evaluators.get(0));
evaluators = null;
}
private static AlgorithmConfiguration testConfig1() {
AlgorithmConfiguration config = Regressor.getConfig();
config.setNumberOfResources(1);
config.setConfigPath("./cfg");
config.setPersistencePath("./");
config.setAgent("MAPS_COMPARISON");
config.setParam("DatabaseUserName","gcube");
config.setParam("DatabasePassword","d4science2");
config.setParam("DatabaseURL","jdbc:postgresql://localhost/testdb");
config.setParam("DatabaseDriver","org.postgresql.Driver");
config.setParam("Layer_1","Bio-Oracle Chlorophyll A Concentration (Mean)");
config.setParam("Layer_2","Bio-Oracle Chlorophyll A Concentration (Max)");
config.setParam("ValuesComparisonThreshold",""+0.1);
config.setParam("Z","0");
config.setGcubeScope("/gcube");
return config;
}
}

@ -0,0 +1,162 @@
package org.gcube.dataanalysis.geo.utils;
import java.util.ArrayList;
import java.util.List;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
import org.gcube.dataanalysis.ecoengine.utils.Tuple;
public class AscDataExplorer {
public double xOrigin;
public double yOrigin;
public int ncolumns;
public int nrows;
public double cellsize;
AscRaster ascFile;
public AscDataExplorer(String file) throws Exception{
AnalysisLogger.getLogger().debug("Managing Asc File: "+file);
AscRasterReader reader = new AscRasterReader();
int i=0;
while(i<10){
try{
ascFile = reader.readRaster(file);
break;
}catch(Exception e){
AnalysisLogger.getLogger().debug("Error in reading remote file: "+file);
}
i++;
}
if (i==10)
throw new Exception("Reading Timeout for the file "+file);
xOrigin=ascFile.getXll();
yOrigin=ascFile.getYll();
ncolumns = ascFile.getCols();
nrows = ascFile.getRows();
cellsize = ascFile.getCellsize();
AnalysisLogger.getLogger().debug("Origin: "+xOrigin+","+yOrigin);
AnalysisLogger.getLogger().debug("Cellsize: "+cellsize);
AnalysisLogger.getLogger().debug("Rows: "+nrows+" Cols:"+ncolumns);
}
public int longitude2Index (double longitude){
return (int)Math.round((longitude-xOrigin)/cellsize);
}
public int latitude2Index (double latitude){
return (int) Math.round((latitude-yOrigin)/cellsize);
}
public List<Double> retrieveDataFromAsc( List<Tuple<Double>> triplets){
List<Double> values = new ArrayList<Double>();
for (Tuple<Double> triplet:triplets){
double x = triplet.getElements().get(0);
double y = triplet.getElements().get(1);
int j = longitude2Index(x);
int i = latitude2Index(y);
if (j>ncolumns){
AnalysisLogger.getLogger().debug("Warning: Column Overflow: adjusting!");
AnalysisLogger.getLogger().debug("Overflow: y:"+y+","+"x:"+x);
AnalysisLogger.getLogger().debug("Overflow: iy:"+i+","+"jx:"+j);
j=ncolumns;
}
if (i>nrows){
AnalysisLogger.getLogger().debug("Warning: Row Overflow: adjusting!");
AnalysisLogger.getLogger().debug("Overflow: y:"+y+","+"x:"+x);
AnalysisLogger.getLogger().debug("Overflow: iy:"+i+","+"jx:"+j);
i=nrows;
}
//AnalysisLogger.getLogger().debug("y:"+y+","+"x:"+x);
//AnalysisLogger.getLogger().debug("iy:"+i+","+"jx:"+j);
double value = ascFile.getValue(i, j);
values.add(value);
}
return values;
}
public static void testReaders() throws Exception {
/*
// File file = new File("http://thredds.d4science.org/thredds/fileServer/public/netcdf/sstrange.tiff");
File file = new File("sstrange.tiff");
AbstractGridFormat format = new GeoTiffFormat();
StringBuilder buffer = new StringBuilder();
buffer.append(file.getAbsolutePath()).append("\n");
// Object o = file.toURI().toURL();
Object o = file;
if (format.accepts(o)) {
buffer.append("ACCEPTED").append("\n");
// getting a reader
GeoTiffReader reader = new GeoTiffReader(o, new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE));
if (reader != null) {
// reading the coverage
GridCoverage2D coverage = (GridCoverage2D) reader.read(null);
buffer.append("CRS: ").append(coverage.getCoordinateReferenceSystem2D().toWKT()).append("\n");
buffer.append("GG: ").append(coverage.getGridGeometry().toString()).append("\n");
// display metadata
IIOMetadataDumper iIOMetadataDumper = new IIOMetadataDumper(((GeoTiffReader) reader).getMetadata().getRootNode());
buffer.append("TIFF metadata: ").append(iIOMetadataDumper.getMetadata()).append("\n");
coverage.show();
// PlanarImage.wrapRenderedImage(coverage.getRenderedImage()).getTiles();
}
else
buffer.append("NOT ACCEPTED").append("\n");
}
*/
/*
GeoTiff gt = new GeoTiff("sstrange.tiff");
gt.read();
System.out.println(gt.showInfo());
gt.close();
*/
// GridDataset gds = ucar.nc2.dt.grid.GridDataset.open("sstrange.tiff");
// List<GridDatatype> gridTypes = gds.getGrids();
// GridDatatype grid = gds.findGridDatatype(gdt.getName());
// GridCoordSystem gcs = grid.getCoordinateSystem();
AscRasterReader reader = new AscRasterReader();
AscRaster r1 = reader.readRaster( "ph.asc" );
System.out.println("center:"+r1.getXll()+","+r1.getYll());
System.out.println("cols:"+r1.getCols());
System.out.println("data:"+r1.getValue(1, 1));
}
/*
public void testBandNames() throws Exception {
final File file = TestData.file(GeoTiffReaderTest.class, "wind.tiff");
assertNotNull(file);
final AbstractGridFormat format = new GeoTiffFormat();
GridCoverage2D coverage = format.getReader(file).read(null);
String band1Name = coverage.getSampleDimension(0).getDescription().toString();
String band2Name = coverage.getSampleDimension(1).getDescription().toString();
assertEquals("Band1", band1Name);
assertEquals("Band2", band2Name);
}
*/
public static void main(String[] args) throws Exception {
AscDataExplorer ade = new AscDataExplorer("http://thredds.d4science.org/thredds/fileServer/public/netcdf/ph.asc");
List<Tuple<Double>> triplets = new ArrayList<Tuple<Double>>();
triplets.add(new Tuple<Double>(-180d,-90d));
triplets.add(new Tuple<Double>(0d,0d));
triplets.add(new Tuple<Double>(180d,90d));
List<Double> values = ade.retrieveDataFromAsc(triplets);
for (Double value:values){
AnalysisLogger.getLogger().debug("val:"+value);
}
}
}

@ -0,0 +1,260 @@
package org.gcube.dataanalysis.geo.utils;
import java.util.Arrays;
/**
* Represents my best guess at the ESRI ASCII raster format. I couldn't find
* any sensible documentation, so it supports the following features:
* <ul>
* <li>cellsize, xll and xll are stored as doubles, and largely ignored
* <li>NDATA has a string representation (as it is typically read in from an
* ascii string) and is internally represented as Double.NaN, as this is safer and
* easier to deal with than the -9999 found in most rasters.
* </ul>
* @author dmrust
*
*/
public class AscRaster
{
protected double[][] data;
protected double xll;
protected double yll;
protected double cellsize;
protected int cols;
protected int rows;
protected String NDATA;
public static final String DEFAULT_NODATA = "-9999";
public void print()
{
System.out.println( "Rows: " + rows + " cols: " + cols + " cellsize " + cellsize );
for( double[] row : data )
{
for( double val : row )
System.out.print( val + " " );
System.out.println( "" );
}
}
/**
* Creates an empty raster
*/
public AscRaster()
{
}
/**
* Creates a raster from the given data
* @param cellsize
* @param xll
* @param yll
*/
public AscRaster( double cellsize, double xll, double yll )
{
this();
setCellsize( cellsize );
setXll( xll );
setYll( yll );
}
/**
* Creates a raster from the given data
* @param data
* @param cellsize
* @param xll
* @param yll
*/
public AscRaster( double[][] data, double cellsize, double xll, double yll )
{
this(cellsize, xll, yll);
setData( data );
}
/**
* Creates a raster from the given data
* @param data
* @param cellsize
* @param xll
* @param yll
*/
public AscRaster( int[][] data, double cellsize, double xll, double yll )
{
this(cellsize, xll, yll);
setData( data );
}
public static AscRaster getTempRaster( double[][] data, double xll, double yll, double size )
{
return getTempRaster( data, xll, yll, size, DEFAULT_NODATA );
}
public static AscRaster getTempRaster( double[][] data, double xll, double yll, double size, String ndata )
{
AscRaster a = new AscRaster();
a.data = data;
a.xll = xll;
a.yll = yll;
a.cellsize = size;
a.NDATA = ndata;
a.rows = data.length;
a.cols = data[0].length;
return a;
}
/**
* Sets the parameters of this raster (rows, columns, corner, cellsize, NDATA etc)
* to be the same as the other raster. This includes initialising the data array
* with NDATAs
* @param other
*/
public void init( AscRaster other )
{
xll = other.xll;
yll = other.yll;
cellsize = other.cellsize;
NDATA = other.NDATA;
setSize( other.getRows(), other.getCols() );
}
/**
* Initialises the Raster to Double.NaN (i.e. NDATA)
*/
public void initData()
{
initData( Double.NaN );
}
/**
* Initialises the raster so the entire data array contains 'value'
* @param value
*/
public void initData( double value )
{
data = new double[rows][];
for( int i = 0; i < rows; i++ )
{
data[i] = new double[cols];
Arrays.fill( data[i], value );
}
}
/**
* Returns the underlying data array - NOTE: this is *NOT* a copy, if you
* change it, you change the data
* @return the data array
*/
public double[][] getData()
{
return data;
}
public void setValue( int row, int column, double value )
{
if( row < rows && column < cols )
data[row][column] = value;
}
public double getValue( int row, int column )
{
if( row < rows && column < cols )
return data[row][column];
return Double.NaN;
}
/**
* Copies the given data into the underlying data array. Also updates the number of rows and columns.
* @param data
*/
public void setData( double[][] data )
{
rows = data.length;
cols = data[0].length;
initData();
for( int i = 0; i < rows; i++ )
for( int j = 0; j < cols; j++ )
this.data[i][j] = data[i][j];
}
/**
* Copies the given data into the underlying data array. Also updates the number of rows and columns.
* @param data
*/
public void setData( int[][] data )
{
rows = data.length;
cols = data[0].length;
initData();
for( int i = 0; i < rows; i++ )
for( int j = 0; j < cols; j++ )
this.data[i][j] = data[i][j];
}
public double getXll()
{
return xll;
}
public void setXll( double xll )
{
this.xll = xll;
}
public double getYll()
{
return yll;
}
public void setYll( double yll )
{
this.yll = yll;
}
public double getCellsize()
{
return cellsize;
}
public void setCellsize( double cellsize )
{
this.cellsize = cellsize;
}
public int getCols()
{
return cols;
}
public int getRows()
{
return rows;
}
/**
* Sets the size of the raster, and also initialises the array
* with NDATA
* @param nrows
* @param columns
*/
public void setSize( int nrows, int columns )
{
this.rows = nrows;
this.cols = columns;
initData();
}
public String getNDATA()
{
return NDATA;
}
public void setNDATA( String nDATA )
{
NDATA = nDATA;
}
}

@ -0,0 +1,122 @@
package org.gcube.dataanalysis.geo.utils;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* A class which reads an ESRI ASCII raster file into a Raster
* @author dmrust
*
*/
public class AscRasterReader
{
String noData = AscRaster.DEFAULT_NODATA;
Pattern header = Pattern.compile( "^(\\w+)\\s+(-?\\d+(.\\d+)?)");
public static void main( String[] args ) throws IOException
{
AscRasterReader rt = new AscRasterReader();
rt.readRaster( "data/test.asc" );
}
/**
* The most useful method - reads a raster file, and returns a Raster object.
*
* Throws standard IOExceptions associated with opening and reading files, and
* RuntimeExceptions if there are problems with the file format
* @param filename
* @return the Raster object read in from the file
* @throws IOException
*/
public AscRaster readRaster( String filename ) throws IOException, RuntimeException
{
AscRaster raster = new AscRaster();
BufferedReader input = null;
URLConnection urlConn =null;
if (filename.startsWith("http")){
URL fileurl = new URL(filename);
urlConn = fileurl.openConnection();
urlConn.setConnectTimeout(60000);
urlConn.setReadTimeout(60000);
urlConn.setAllowUserInteraction(false);
urlConn.setDoOutput(true);
input = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
}
else
input = new BufferedReader( new FileReader( filename ) );
while( input.ready() )
{
String line = input.readLine();
Matcher headMatch = header.matcher( line );
//Match all the heads
if( headMatch.matches() )
{
String head = headMatch.group( 1 );
String value = headMatch.group( 2 );
if( head.equalsIgnoreCase( "nrows" ) )
raster.rows = Integer.parseInt( value );
else if ( head.equalsIgnoreCase( "ncols" ) )
raster.cols = Integer.parseInt( value );
else if ( head.equalsIgnoreCase( "xllcorner" ) )
raster.xll = Double.parseDouble( value );
else if ( head.equalsIgnoreCase( "yllcorner" ) )
raster.yll = Double.parseDouble( value );
else if ( head.equalsIgnoreCase( "NODATA_value" ) )
raster.NDATA = value;
else if ( head.equals( "cellsize" ) )
raster.cellsize = Double.parseDouble( value );
else
System.out.println( "Unknown setting: " + line );
}
else if( line.matches( "^-?\\d+.*" ))
{
//System.out.println( "Processing data section");
//Check that data is set up!
//Start processing numbers!
int row = 0;
double[][] data = new double[raster.rows][];
while( true )
{
//System.out.println( "Got data row: " + line );
String[] inData = line.split( "\\s+" );
double[] numData = new double[raster.cols];
if( inData.length != numData.length ) throw new RuntimeException( "Wrong number of columns: Expected " +
raster.cols + " got " + inData.length + " for line \n" + line );
for( int col = 0; col < raster.cols; col ++ )
{
if( inData[col].equals( noData )) numData[col] = Double.NaN;
else numData[col] = Double.parseDouble( inData[col] );
}
data[row] = numData;
//Ugly backward input structure...
if( input.ready() ) line = input.readLine();
else break;
row++;
}
if( row != raster.rows - 1)
throw new RuntimeException( "Wrong number of rows: expected " + raster.rows + " got " + (row+1) );
raster.data = data;
}
else
{
if( line.length() >= 0 && ! line.matches( "^\\s*$" ))
System.out.println( "Unknown line: " + line);
}
}
if (input!=null){
input.close();
if (urlConn!=null && urlConn.getInputStream()!=null)
urlConn.getInputStream().close();
}
return raster;
}
}

File diff suppressed because one or more lines are too long

Binary file not shown.
Loading…
Cancel
Save