-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Welcome to the IRDTunaAtlas wiki!
The package installation requires at least R 2.15 and installing the devtools package
install.packages("devtools")
Once the devtools package loaded, you can use the install_github as follows:
require("devtools")
install_github("IRDTunaAtlas", "jsubei")
Indicator I1 : Annual catches by ocean
Indicator I2 : Annual catches by gear
Indicator I3 : Catches by gear and by month
Indicator I4 : Catches by month and by ocean
Indicator I6 : Catches by 5x5 degrees
Indicator I7 : 5x5 degrees relative contribution to catches
Indicator I8 : Catches relative contribution over other species
Indicator I9 : Size frequencies by school type
Indicator I10 : Size frequencies by decade
Indicator I11 : Catches by country
For testing we use an 52North WPS server ( see http://52north.org/communities/geoprocessing/wps/index.html ). 52North WPS allow to execute R scripts ( see http://52north.org/communities/geoprocessing/wps/backends/52n-wps-r.html ) with special annotations ( see http://52north.org/communities/geoprocessing/wps/backends/52n-wps-r.html#R_scripts_and_WPS-annotations ).
We fisrt try the i1 indicator, so we write an interface between the WPS server and the R indicator process:
Interface R script
#52North WPS annotations
# wps.des: id = Atlas_i1_SpeciesByOcean, title = IRD tuna atlas indicator i1, abstract = Graph of species catches by ocean;
# wps.in: id = data_type, type = string, title = Data type (csv or WFS or MDSTServer), value = "WFS";
# wps.in: id = url, type = string, title = Data URL, value = "http://mdst-macroes.ird.fr:8080/constellation/WS/wfs/tuna_atlas";
# wps.in: id = layer, type = string, title = Data layer name, minOccurs = 0, maxOccurs = 1, value = "ns11:i1i2_mv";
# wps.in: id = mdst_query, type = string, title = MDSTServer query. Only used with MDSTServer data type, minOccurs = 0, maxOccurs = 1;
# wps.in: id = ogc_filter, type = string, title = OGC filter to apply on a WFS datasource. Only used with WFS data type, minOccurs = 0, maxOccurs = 1;
# wps.in: id = connection_type, type = string, title = Data connection type (local or remote), value = "remote";
# wps.in: id = datasetYearAttributeName, type = string, title = Year attribute name in the input dataset, value = "year";
# wps.in: id = datasetOceanAttributeName, type = string, title = Ocean attribute name in the input dataset, value = "ocean";
# wps.in: id = datasetSpeciesAttributeName, type = string, title = Species attribute name in the input dataset, value = "species";
# wps.in: id = datasetValueAttributeName, type = string, title = Value attribute name in the input dataset, value = "value";
# wps.out: id = result, type = string, title = List of result files path;
if(! require(IRDTunaAtlas)) {
stop("Missing IRDTunaAtlas library")
}
#read the input data
dataset <- readData(connectionType=connection_type,
dataType=data_type,
url=url,
layer=layer,
MDSTQuery=mdst_query,
ogcFilter=ogc_filter)
#do the mapping of dataset attributes names
dataset <- evaluateAndRenameAttributesNames(df=dataset, objList=ls())
#Build the indicator
resultDF <- Atlas_i1_SpeciesByOcean(df=dataset)
#Result as JSON array of files path
require(rjson)
result <- toJSON(resultDF)
The 52North WPS server automatically convert specials annotations of the previous interface R script to an conform DescribeProcess xml document ( see http://schemas.opengis.net/wps/1.0.0/wpsDescribeProcess_response.xsd )
<?xml version="1.0" encoding="UTF-8"?>
<wps:ProcessDescriptions xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlin="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsDescribeProcess_response.xsd" xml:lang="en-US" service="WPS" version="1.0.0">
<ProcessDescription statusSupported="true" storeSupported="true" wps:processVersion="">
<ows:Identifier>org.n52.wps.server.r.Atlas_i1_SpeciesByOcean</ows:Identifier>
<ows:Title>IRD tuna atlas indicator i1</ows:Title>
<ows:Abstract>Graph of species catches by ocean</ows:Abstract>
<ows:Metadata xlin:title="R Script" xlin:href="http://localhost:8080/wps/R/scripts/Atlas_i1_SpeciesByOcean.R"/>
<ows:Metadata xlin:title="R Session Info" xlin:href="http://localhost:8080/wps/R/sessioninfo.jsp"/>
<DataInputs>
<Input minOccurs="0" maxOccurs="1">
<ows:Identifier>data_type</ows:Identifier>
<ows:Title>Data type (csv or WFS or MDSTServer)</ows:Title>
<LiteralData>
<ows:DataType ows:reference="xs:string"/>
<ows:AnyValue/>
<DefaultValue>WFS</DefaultValue>
</LiteralData>
</Input>
<Input minOccurs="0" maxOccurs="1">
<ows:Identifier>url</ows:Identifier>
<ows:Title>Data URL</ows:Title>
<LiteralData>
<ows:DataType ows:reference="xs:string"/>
<ows:AnyValue/>
<DefaultValue>http://mdst-macroes.ird.fr:8080/constellation/WS/wfs/tuna_atlas</DefaultValue>
</LiteralData>
</Input>
<Input minOccurs="0" maxOccurs="1">
<ows:Identifier>layer</ows:Identifier>
<ows:Title>Data layer name</ows:Title>
<LiteralData>
<ows:DataType ows:reference="xs:string"/>
<ows:AnyValue/>
<DefaultValue>ns11:i1i2_mv</DefaultValue>
</LiteralData>
</Input>
<Input minOccurs="0" maxOccurs="1">
<ows:Identifier>mdst_query</ows:Identifier>
<ows:Title>MDSTServer query. Only used with MDSTServer data type</ows:Title>
<LiteralData>
<ows:DataType ows:reference="xs:string"/>
<ows:AnyValue/>
</LiteralData>
</Input>
<Input minOccurs="0" maxOccurs="1">
<ows:Identifier>ogc_filter</ows:Identifier>
<ows:Title>OGC filter to apply on a WFS datasource. Only used with WFS data type</ows:Title>
<LiteralData>
<ows:DataType ows:reference="xs:string"/>
<ows:AnyValue/>
</LiteralData>
</Input>
<Input minOccurs="0" maxOccurs="1">
<ows:Identifier>connection_type</ows:Identifier>
<ows:Title>Data connection type (local or remote)</ows:Title>
<LiteralData>
<ows:DataType ows:reference="xs:string"/>
<ows:AnyValue/>
<DefaultValue>remote</DefaultValue>
</LiteralData>
</Input>
<Input minOccurs="0" maxOccurs="1">
<ows:Identifier>datasetYearAttributeName</ows:Identifier>
<ows:Title>Year attribute name in the input dataset</ows:Title>
<LiteralData>
<ows:DataType ows:reference="xs:string"/>
<ows:AnyValue/>
<DefaultValue>year</DefaultValue>
</LiteralData>
</Input>
<Input minOccurs="0" maxOccurs="1">
<ows:Identifier>datasetOceanAttributeName</ows:Identifier>
<ows:Title>Ocean attribute name in the input dataset</ows:Title>
<LiteralData>
<ows:DataType ows:reference="xs:string"/>
<ows:AnyValue/>
<DefaultValue>ocean</DefaultValue>
</LiteralData>
</Input>
<Input minOccurs="0" maxOccurs="1">
<ows:Identifier>datasetSpeciesAttributeName</ows:Identifier>
<ows:Title>Species attribute name in the input dataset</ows:Title>
<LiteralData>
<ows:DataType ows:reference="xs:string"/>
<ows:AnyValue/>
<DefaultValue>species</DefaultValue>
</LiteralData>
</Input>
<Input minOccurs="0" maxOccurs="1">
<ows:Identifier>datasetValueAttributeName</ows:Identifier>
<ows:Title>Value attribute name in the input dataset</ows:Title>
<LiteralData>
<ows:DataType ows:reference="xs:string"/>
<ows:AnyValue/>
<DefaultValue>value</DefaultValue>
</LiteralData>
</Input>
</DataInputs>
<ProcessOutputs>
<Output>
<ows:Identifier>result</ows:Identifier>
<ows:Title>List of result files path</ows:Title>
<LiteralOutput>
<ows:DataType ows:reference="xs:string"/>
</LiteralOutput>
</Output>
<Output>
<ows:Identifier>sessionInfo</ows:Identifier>
<ows:Title>Information about the R session which has been used</ows:Title>
<ows:Abstract>Output of the sessionInfo()-method after R-script execution</ows:Abstract>
<ComplexOutput>
<Default>
<Format>
<MimeType>text/plain</MimeType>
<Encoding>UTF-8</Encoding>
</Format>
</Default>
<Supported>
<Format>
<MimeType>text/plain</MimeType>
<Encoding>UTF-8</Encoding>
</Format>
</Supported>
</ComplexOutput>
</Output>
<Output>
<ows:Identifier>warnings</ows:Identifier>
<ows:Title>Warnings from R</ows:Title>
<ows:Abstract>Output of the warnings()-method after R-script execution</ows:Abstract>
<ComplexOutput>
<Default>
<Format>
<MimeType>text/plain</MimeType>
<Encoding>UTF-8</Encoding>
</Format>
</Default>
<Supported>
<Format>
<MimeType>text/plain</MimeType>
<Encoding>UTF-8</Encoding>
</Format>
</Supported>
</ComplexOutput>
</Output>
</ProcessOutputs>
</ProcessDescription>
</wps:ProcessDescriptions>
So we could adress an "XML Execute Request" ( see http://schemas.opengis.net/wps/1.0.0/wpsExecute_request.xsd ) to the wps server:
<?xml version="1.0" encoding="UTF-8"?>
<wps:Execute version="1.0.0" service="WPS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.opengis.net/wps/1.0.0" xmlns:wfs="http://www.opengis.net/wfs" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:wcs="http://www.opengis.net/wcs/1.1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd">
<ows:Identifier>org.n52.wps.server.r.Atlas_i1_SpeciesByOcean</ows:Identifier>
<wps:DataInputs>
<wps:Input>
<ows:Identifier>connection_type</ows:Identifier>
<wps:Data>
<wps:LiteralData>remote</wps:LiteralData>
</wps:Data>
</wps:Input>
<wps:Input>
<ows:Identifier>data_type</ows:Identifier>
<wps:Data>
<wps:LiteralData>WFS</wps:LiteralData>
</wps:Data>
</wps:Input>
<wps:Input>
<ows:Identifier>url</ows:Identifier>
<wps:Data>
<wps:LiteralData>http://mdst-macroes.ird.fr:8080/constellation/WS/wfs/tuna_atlas</wps:LiteralData>
</wps:Data>
</wps:Input>
<wps:Input>
<ows:Identifier>layer</ows:Identifier>
<wps:Data>
<wps:LiteralData>ns11:i1i2_mv</wps:LiteralData>
</wps:Data>
</wps:Input>
</wps:DataInputs>
<wps:ResponseForm>
<wps:RawDataOutput>
<ows:Identifier>result</ows:Identifier>
</wps:RawDataOutput>
</wps:ResponseForm>
</wps:Execute>
So the server response is (here the script return an JSON array of output files) :
["/tmp/RtmpGcmit3/I1_Thunnus_alalunga_169b7873187d.png","/tmp/RtmpGcmit3/I1_Thunnus_obesus_169b5ee3ed48.png","/tmp/RtmpGcmit3/I1_Thunnus_thynnus_169b24fc2abf.png","/tmp/RtmpGcmit3/I1_Istiophoridae_169b63a85964.png","/tmp/RtmpGcmit3/I1_Makaira_indica_169b2b33699e.png","/tmp/RtmpGcmit3/I1_Makaira_nigricans_169b5fac4120.png","/tmp/RtmpGcmit3/I1_Tetrapturus_audax_169b52e67505.png","/tmp/RtmpGcmit3/I1_Thunnus_maccoyii_169b19e4e1df.png","/tmp/RtmpGcmit3/I1_Istiophorus_platypterus_169b14ed4e02.png","/tmp/RtmpGcmit3/I1_Katsuwonus_pelamis_169b35eba365.png","/tmp/RtmpGcmit3/I1_Tetrapturus_angustirostris_169b6b310dd4.png","/tmp/RtmpGcmit3/I1_Xiphias_gladius_169b224f01a2.png","/tmp/RtmpGcmit3/I1_Thunnus_albacares_169b2bf05afc.png","/tmp/RtmpGcmit3/I1_Thunnus_alalunga_169b7873187d.rdf","/tmp/RtmpGcmit3/I1_Thunnus_obesus_169b5ee3ed48.rdf","/tmp/RtmpGcmit3/I1_Thunnus_thynnus_169b24fc2abf.rdf","/tmp/RtmpGcmit3/I1_Istiophoridae_169b63a85964.rdf","/tmp/RtmpGcmit3/I1_Makaira_indica_169b2b33699e.rdf","/tmp/RtmpGcmit3/I1_Makaira_nigricans_169b5fac4120.rdf","/tmp/RtmpGcmit3/I1_Tetrapturus_audax_169b52e67505.rdf","/tmp/RtmpGcmit3/I1_Thunnus_maccoyii_169b19e4e1df.rdf","/tmp/RtmpGcmit3/I1_Istiophorus_platypterus_169b14ed4e02.rdf","/tmp/RtmpGcmit3/I1_Katsuwonus_pelamis_169b35eba365.rdf","/tmp/RtmpGcmit3/I1_Tetrapturus_angustirostris_169b6b310dd4.rdf","/tmp/RtmpGcmit3/I1_Xiphias_gladius_169b224f01a2.rdf","/tmp/RtmpGcmit3/I1_Thunnus_albacares_169b2bf05afc.rdf"]
Now we try with an remote csv file: http://mdst-macroes.ird.fr/atlas_i1i2.csv
So we set the inputs as:
connection_type=remote data_type=csv url=http://mdst-macroes.ird.fr/atlas_i1i2.csv
<?xml version="1.0" encoding="UTF-8"?>
<wps:Execute version="1.0.0" service="WPS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.opengis.net/wps/1.0.0" xmlns:wfs="http://www.opengis.net/wfs" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:wcs="http://www.opengis.net/wcs/1.1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd">
<ows:Identifier>org.n52.wps.server.r.Atlas_i1_SpeciesByOcean</ows:Identifier>
<wps:DataInputs>
<wps:Input>
<ows:Identifier>connection_type</ows:Identifier>
<wps:Data>
<wps:LiteralData>remote</wps:LiteralData>
</wps:Data>
</wps:Input>
<wps:Input>
<ows:Identifier>data_type</ows:Identifier>
<wps:Data>
<wps:LiteralData>csv</wps:LiteralData>
</wps:Data>
</wps:Input>
<wps:Input>
<ows:Identifier>url</ows:Identifier>
<wps:Data>
<wps:LiteralData>http://mdst-macroes.ird.fr/atlas_i1i2.csv</wps:LiteralData>
</wps:Data>
</wps:Input>
</wps:DataInputs>
<wps:ResponseForm>
<wps:RawDataOutput>
<ows:Identifier>result</ows:Identifier>
</wps:RawDataOutput>
</wps:ResponseForm>
</wps:Execute>