Next changeset 1:b4b9edf9ea27 (2024-03-12) |
Commit message:
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/interpolation commit 450e4496f243d6e94d5238358873bbc014fe2f08 |
added:
run_idw_interpolation.R run_idw_interpolation.xml test-data/run_idw_interpolation_test_input1.csv test-data/run_idw_interpolation_test_input2.geojson test-data/run_idw_interpolation_test_output.png |
b |
diff -r 000000000000 -r d07fcc660f3c run_idw_interpolation.R --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/run_idw_interpolation.R Mon Jan 08 10:32:25 2024 +0000 |
[ |
@@ -0,0 +1,100 @@ +library("getopt") +library("sf") +library("tmap") +library("RColorBrewer") +library("raster") +library("gstat") + +args = commandArgs(trailingOnly=TRUE) +option_specification = matrix(c( + 'observationsCsv', 'i1', 1, 'character', + 'latitudeColumn', 'i2', 1, 'double', + 'longitudeColumn', 'i3', 1, 'double', + 'observationsColumn', 'i4', 1, 'double', + 'studyArea', 'i5', 1, 'character', + 'idwPower', 'i6', 1, 'double', + 'samplePoints', 'i7', 1, 'double', + 'sampleType', 'i8', 1, 'character', + 'legendLabel', 'i9', 1, 'character', + 'legendPosition', 'i10', 1, 'character', + 'numberClasses', 'i11', 1, 'double', + 'dotSize', 'i12', 1, 'double', + 'colorType', 'i13', 1, 'character', + 'testCase', 'i14', 1, 'character', + 'outputData', 'o', 2, 'character' +), byrow=TRUE, ncol=4); +options = getopt(option_specification); + +obsData <- read.csv(file=options$observationsCsv, sep = ',', header = TRUE) +latitudeColumn <- options$latitudeColumn +longitudeColumn <- options$longitudeColumn +observationsColumn <- options$observationsColumn +studyArea <- options$studyArea +idwPower <- options$idwPower +samplePoints <- options$samplePoints +sampleType <- options$sampleType +legendLabel <- options$legendLabel +legendPosition <- options$legendPosition +numberClasses <- options$numberClasses +dotSize <- options$dotSize +colorType <- options$colorType +testCase <- options$testCase + +#cat("\n observationsCsv", options$observationsCsv) +cat("\n latitudeColumn", latitudeColumn) +cat("\n longitudeColumn", longitudeColumn) +cat("\n observationsColumn", observationsColumn) +#cat("\n studyArea", studyArea) +cat("\n idwPower", idwPower) +cat("\n samplePoints", samplePoints) +cat("\n sampleType", sampleType) +cat("\n legendLabel", legendLabel) +cat("\n legendposition", legendPosition) +cat("\n numberClasses", numberClasses) +cat("\n dotSize", dotSize) +cat("\n colorType", colorType) +cat("\n testCase", testCase) +#cat("\n outputData: ", options$outputData) + +coordinates(obsData) <- c(colnames(obsData)[longitudeColumn], colnames(obsData)[latitudeColumn]) +sf_obsData <- as_Spatial(st_as_sf(obsData)) + +polygon <- as_Spatial(st_read(studyArea)) +sf_obsData@bbox<-polygon@bbox + +runInterpolation <- function(points, values, interpolation_power, sample_points, sample_type){ + if (testCase == "true") { + cat("\n set seed!") + set.seed(123) + } + grd <- as.data.frame(spsample(points, sample_type, n=sample_points)) + names(grd) <- c("X", "Y") + coordinates(grd) <- c("X", "Y") + gridded(grd) <- TRUE + fullgrid(grd) <- TRUE + + proj4string(points) <- proj4string(points) + proj4string(grd) <- proj4string(points) + return(gstat::idw(values ~ 1, points, newdata=grd, idp=interpolation_power)) +} + +plotInterpolationMap <- function(raster, points, legend_label){ + plot <- tm_shape(raster) + + tm_raster(n=numberClasses,palette = rev(brewer.pal(7, colorType)), auto.palette.mapping = FALSE, + title=legend_label) + + tm_shape(points) + tm_dots(size=dotSize) + + tm_legend(legend.outside=legendPosition) + return(plot) +} + +sf_obsData.idw <- runInterpolation(sf_obsData, obsData$measurement, idwPower, samplePoints, sampleType) + +raster_object <- raster(sf_obsData.idw) +raster_object.mask <- mask(raster_object, polygon) + +idw <- plotInterpolationMap(raster_object.mask, sf_obsData, legendLabel) +idw + +png(options$outputData) +idw +dev.off() \ No newline at end of file |
b |
diff -r 000000000000 -r d07fcc660f3c run_idw_interpolation.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/run_idw_interpolation.xml Mon Jan 08 10:32:25 2024 +0000 |
[ |
@@ -0,0 +1,102 @@ +<tool id="interpolation_run_idw_interpolation" name="Run interpolation" version="1.0" profile="22.05"> + <description>based on Inverse Distance Weighting (IDW)</description> + <requirements> + <requirement type="package" version="1.20.4">r-getopt</requirement> + <requirement type="package" version="3.3_4">r-tmap</requirement> + <requirement type="package" version="3.6_26">r-raster</requirement> + <requirement type="package" version="2.1_1">r-gstat</requirement> + </requirements> + <command detect_errors='exit_code'><![CDATA[ + Rscript '$__tool_directory__/run_idw_interpolation.R' + --observationsCsv '$observations_csv' + --latitudeColumn '$latitude_column' + --longitudeColumn '$longitude_column' + --observationsColumn '$observations_column' + --studyArea '$study_area' + --idwPower '$idw_power' + --samplePoints '$sample_points' + --sampleType '$sample_type' + --legendLabel '$legend_label' + --legendPosition '$legend_position' + --numberClasses '$number_classes' + --dotSize '$dot_size' + --colorType '$color_type' + --testCase '$test_case' + --outputData '$output' + ]]></command> + <inputs> + <param type="data" format="csv" name="observations_csv" label="Select the .csv file including the observations"/> + <param type="data" format="geojson" name="study_area" label="Select the .geojson containing the study area"/> + <param name="latitude_column" type="data_column" data_ref="observations_csv" label="In which column are the latitude coordinates?"/> + <param name="longitude_column" type="data_column" data_ref="observations_csv" label="In which column are the longitude coordinates?"/> + <param name="observations_column" type="data_column" data_ref="observations_csv" label="In which column are the observation values?"/> + <param value="2" min="0.1" max="5" type="float" name="idw_power" label="Select the interpolation power of the IDW method"/> + <param value="50000" min="1000" max="100000" type="integer" name="sample_points" label="Select the number of sample points"/> + <param type="select" name="sample_type" label="Select a sample type"> + <option value="regular">Regular</option> + <option value="random">Random</option> + <option value="stratified">Stratified</option> + <option value="nonaligned">Nonaligned</option> + </param> + <param type="text" name="legend_label" label="Enter a label for the legend"/> + <param type="select" name="legend_position" label="Should the legend be displayed inside or outside the frame?"> + <option value="false">Inside</option> + <option value="true">Outside</option> + </param> + <param value="0.2" min="0.1" max="2" type="float" name="dot_size" label="Select the dot size of the points shown on the map"/> + <param value="10" min="1" max="100" type="integer" name="number_classes" label="Number of classes" help="Note: Not all values are possible. tmap tries to generate a number of classes which are as close to the indicated value as possible"/> + <param type="select" name="color_type" label="Select a color palette"> + <option value="RdBu">RdBu</option> + <option value="Blues">Blues</option> + <option value="BuGn">BuGn</option> + <option value="BuPu">BuPu</option> + <option value="GnBu">GnBu</option> + <option value="Greens">Greens</option> + <option value="Greys">Greys</option> + <option value="Oranges">Oranges</option> + <option value="OrRd">OrRd</option> + <option value="PuBu">PuBu</option> + <option value="PuBuGn ">PuBuGn</option> + <option value="PuRd">PuRd</option> + <option value="Purples">Purples</option> + <option value="RdPu">RdPu</option> + <option value="Reds">Reds</option> + <option value="YlGn">YlGn</option> + <option value="YlGnBu">YlGnBu</option> + <option value="YlOrBr">YlOrBr</option> + <option value="YlOrRd">YlOrRd</option> + </param> + <param type="boolean" name="test_case" label="Should a seed be set?" truevalue="true" falsevalue="false" /> + </inputs> + <outputs> + <data name="output" format="png" /> + </outputs> + <tests> + <!-- Run test with: planemo test - -biocontainers plotInterpolationMap.xml - -test_output=plotInterpolationMap.html --> + <test> + <param name="observations_csv" value="run_idw_interpolation_test_input1.csv"/> + <param name="latitude_column" value="3"/> + <param name="longitude_column" value="4"/> + <param name="observations_column" value="5"/> + <param name="study_area" value="run_idw_interpolation_test_input2.geojson"/> + <param name="idw_power" value="2"/> + <param name="sample_points" value="50000"/> + <param name="sample_type" value="regular"/> + <param name="legend_label" value="Legend"/> + <param name="legend_position" value="false"/> + <param name="number_classes" value="10"/> + <param name="dot_size" value="1"/> + <param name="color_type" value="RdBu"/> + <param name="test_case" value="true"/> + <output name="output" file="run_idw_interpolation_test_output.png" compare="sim_size" delta_frac="0.1"/> + </test> + </tests> + <help><![CDATA[ + IDW stands for Inverse Distance Weighting. The .csv file contains the observations and the .geojson file the study area. The plot is stored as a .png file. + ]]></help> + <citations> + <citation type="doi">10.32614/RJ-2018-009</citation> + <citation type="doi">10.18637/jss.v084.i06</citation> + <citation type="doi">10.32614/RJ-2016-014</citation> + </citations> +</tool> |
b |
diff -r 000000000000 -r d07fcc660f3c test-data/run_idw_interpolation_test_input1.csv --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/run_idw_interpolation_test_input1.csv Mon Jan 08 10:32:25 2024 +0000 |
b |
@@ -0,0 +1,11 @@ +sensor_id,attribute,latitude,longitude,measurement,accuracy,unit,date,quality_level,data_processing +1,waterTemp,51.95690094,7.61361456,10.428,0.002,celsius,03.04.2023 10:00,checked,adjusted +2,waterTemp,51.9558893,7.616701107,10.181,0.1,celsius,03.04.2023 10:00,checked,adjusted +3,waterTemp,51.95355062,7.606799142,11.653,0.1,celsius,03.04.2023 10:00,checked,raw +4,waterTemp,51.95258302,7.608679928,10.619,0.002,celsius,03.04.2023 10:00,unchecked,adjusted +5,waterTemp,51.95078585,7.604339653,10.124,0.002,celsius,03.04.2023 10:00,checked,adjusted +6,waterTemp,51.94994044,7.605288084,10.834,0.1,celsius,03.04.2023 10:00,checked,raw +7,waterTemp,51.94679837,7.596725189,11.244,0.002,celsius,03.04.2023 10:00,checked,adjusted +8,waterTemp,51.94552117,7.600045848,20.575,0.002,celsius,03.04.2023 10:00,unchecked,raw +9,waterTemp,51.94244725,7.594818813,10.669,0.002,celsius,03.04.2023 10:00,checked,adjusted +10,waterTemp,51.94294707,7.597031164,10.702,0.1,celsius,03.04.2023 10:00,checked,adjusted |
b |
diff -r 000000000000 -r d07fcc660f3c test-data/run_idw_interpolation_test_input2.geojson --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/run_idw_interpolation_test_input2.geojson Mon Jan 08 10:32:25 2024 +0000 |
[ |
b'@@ -0,0 +1,1005 @@\n+{\n+ "type": "FeatureCollection",\n+ "generator": "overpass-ide",\n+ "copyright": "The data included in this document is from www.openstreetmap.org. The data is made available under ODbL.",\n+ "timestamp": "2023-04-03T13:52:54Z",\n+ "features": [\n+ {\n+ "type": "Feature",\n+ "properties": {\n+ "@id": "relation/13763746",\n+ "basin": "retention",\n+ "boat": "permissive",\n+ "intermittent": "no",\n+ "maxdepth": "2",\n+ "name": "Aasee",\n+ "name:de": "Aasee",\n+ "name:ru": "\xd0\x90\xd0\xb0\xd0\xb7\xd0\xb5",\n+ "natural": "water",\n+ "salt": "no",\n+ "tidal": "no",\n+ "type": "multipolygon",\n+ "water": "lake",\n+ "website": "https://www.aaseepark.de/",\n+ "wikidata": "Q303434",\n+ "wikipedia": "de:Aasee (M\xc3\xbcnster)"\n+ },\n+ "geometry": {\n+ "type": "Polygon",\n+ "coordinates": [\n+ [\n+ [\n+ 7.6157143,\n+ 51.9575375\n+ ],\n+ [\n+ 7.6156899,\n+ 51.9575098\n+ ],\n+ [\n+ 7.6156437,\n+ 51.9574789\n+ ],\n+ [\n+ 7.6155894,\n+ 51.9574596\n+ ],\n+ [\n+ 7.6155282,\n+ 51.9574454\n+ ],\n+ [\n+ 7.6154684,\n+ 51.957442\n+ ],\n+ [\n+ 7.61547,\n+ 51.9574267\n+ ],\n+ [\n+ 7.6153516,\n+ 51.9574452\n+ ],\n+ [\n+ 7.6150165,\n+ 51.9574975\n+ ],\n+ [\n+ 7.6144566,\n+ 51.9575722\n+ ],\n+ [\n+ 7.6140497,\n+ 51.9576357\n+ ],\n+ [\n+ 7.6140325,\n+ 51.9576375\n+ ],\n+ [\n+ 7.6137887,\n+ 51.9575415\n+ ],\n+ [\n+ 7.6137702,\n+ 51.957534\n+ ],\n+ [\n+ 7.6136789,\n+ 51.9574934\n+ ],\n+ [\n+ 7.6135826,\n+ 51.9574529\n+ ],\n+ [\n+ 7.6135624,\n+ 51.9574451\n+ ],\n+ [\n+ 7.61325,\n+ 51.9573207\n+ ],\n+ [\n+ 7.613635,\n+ 51.9569508\n+ ],\n+ [\n+ 7.6135427,\n+ 51.9569147\n+ ],\n+ [\n+ 7.6133267,\n+ 51.9568258\n+ ],\n+ [\n+ 7.6129474,\n+ 51.9566682\n+ ],\n+ [\n+ 7.6128337,\n+ 51.9566612\n+ ],\n+ [\n+ 7.6126224,\n+ 51.9567523\n+ ],\n+ [\n+ 7.6122592,\n+ 51.9565908\n+ ],\n+ [\n+ 7.6114629,\n+ 51.9561736\n+ ],\n+ [\n+ 7.6111883,\n+ 51.9560139\n+ ],\n+ [\n+ 7.6108376,\n+ 51.9557374\n+ ],\n+ [\n+ 7.6104902,\n+ 51.9554314\n+ ],\n+ [\n+ 7.6097663,\n+ 51.9548186\n+ ],\n+ [\n+ 7.6090255,\n+ 51.9544084\n+ ],\n+ [\n+ 7.6085691,\n+ 51.9541575\n+ ],\n+ [\n+ 7.6077852,\n+ 51.9538539\n+ ],\n+ [\n+ 7.6072813,\n+ 51.9537208\n+ ],\n+ [\n+ 7.6070219,\n+ 51.9536531\n+ ],\n+ [\n+ 7.6065993,\n+ 51.9535351\n+ ],\n+ [\n+ 7.6063773,\n+ 51.9534273\n+ ],\n+ '..b' [\n+ 7.6158347,\n+ 51.9587501\n+ ],\n+ [\n+ 7.6157778,\n+ 51.9588118\n+ ],\n+ [\n+ 7.6152391,\n+ 51.9594326\n+ ],\n+ [\n+ 7.6149129,\n+ 51.9597959\n+ ],\n+ [\n+ 7.6147119,\n+ 51.9600104\n+ ],\n+ [\n+ 7.6145594,\n+ 51.9601642\n+ ],\n+ [\n+ 7.6145116,\n+ 51.9601984\n+ ],\n+ [\n+ 7.6144869,\n+ 51.9602312\n+ ],\n+ [\n+ 7.6144524,\n+ 51.9602633\n+ ],\n+ [\n+ 7.6144448,\n+ 51.9603026\n+ ],\n+ [\n+ 7.6144463,\n+ 51.9603363\n+ ],\n+ [\n+ 7.614457,\n+ 51.9603751\n+ ],\n+ [\n+ 7.6144479,\n+ 51.9603924\n+ ],\n+ [\n+ 7.6144152,\n+ 51.9603975\n+ ],\n+ [\n+ 7.6144099,\n+ 51.9604078\n+ ],\n+ [\n+ 7.6144243,\n+ 51.96042\n+ ],\n+ [\n+ 7.6144441,\n+ 51.9604246\n+ ],\n+ [\n+ 7.6144828,\n+ 51.9604139\n+ ],\n+ [\n+ 7.6145283,\n+ 51.9604139\n+ ],\n+ [\n+ 7.6145632,\n+ 51.9604286\n+ ],\n+ [\n+ 7.6145436,\n+ 51.9604482\n+ ],\n+ [\n+ 7.6145237,\n+ 51.9604681\n+ ],\n+ [\n+ 7.6144782,\n+ 51.9604686\n+ ],\n+ [\n+ 7.6144281,\n+ 51.9604625\n+ ],\n+ [\n+ 7.6143462,\n+ 51.9604443\n+ ],\n+ [\n+ 7.6143007,\n+ 51.9604251\n+ ],\n+ [\n+ 7.6142848,\n+ 51.9603821\n+ ],\n+ [\n+ 7.6142817,\n+ 51.9603381\n+ ],\n+ [\n+ 7.6142855,\n+ 51.9602778\n+ ],\n+ [\n+ 7.6143007,\n+ 51.9602091\n+ ],\n+ [\n+ 7.6143027,\n+ 51.9601915\n+ ],\n+ [\n+ 7.6144259,\n+ 51.9600058\n+ ],\n+ [\n+ 7.6146717,\n+ 51.9596963\n+ ],\n+ [\n+ 7.6150047,\n+ 51.9593232\n+ ],\n+ [\n+ 7.6152209,\n+ 51.9590633\n+ ],\n+ [\n+ 7.6154728,\n+ 51.9587777\n+ ],\n+ [\n+ 7.6156344,\n+ 51.9585888\n+ ],\n+ [\n+ 7.6157057,\n+ 51.9584906\n+ ],\n+ [\n+ 7.6157467,\n+ 51.958391\n+ ],\n+ [\n+ 7.6157838,\n+ 51.9582657\n+ ],\n+ [\n+ 7.6158066,\n+ 51.9581442\n+ ],\n+ [\n+ 7.6158142,\n+ 51.957867\n+ ],\n+ [\n+ 7.6158043,\n+ 51.9578557\n+ ],\n+ [\n+ 7.6157937,\n+ 51.9578389\n+ ],\n+ [\n+ 7.6157853,\n+ 51.9578123\n+ ],\n+ [\n+ 7.6157512,\n+ 51.9575958\n+ ],\n+ [\n+ 7.6157143,\n+ 51.9575375\n+ ]\n+ ]\n+ ]\n+ },\n+ "id": "relation/13763746"\n+ }\n+ ]\n+}\n\\ No newline at end of file\n' |
b |
diff -r 000000000000 -r d07fcc660f3c test-data/run_idw_interpolation_test_output.png |
b |
Binary file test-data/run_idw_interpolation_test_output.png has changed |