# HG changeset patch # User ecology # Date 1704709945 0 # Node ID d07fcc660f3c21540c7cfb8d0427a89694119e4c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/interpolation commit 450e4496f243d6e94d5238358873bbc014fe2f08 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 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 @@ + + based on Inverse Distance Weighting (IDW) + + r-getopt + r-tmap + r-raster + r-gstat + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 10.32614/RJ-2018-009 + 10.18637/jss.v084.i06 + 10.32614/RJ-2016-014 + + 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 @@ -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 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 @@ -0,0 +1,1005 @@ +{ + "type": "FeatureCollection", + "generator": "overpass-ide", + "copyright": "The data included in this document is from www.openstreetmap.org. The data is made available under ODbL.", + "timestamp": "2023-04-03T13:52:54Z", + "features": [ + { + "type": "Feature", + "properties": { + "@id": "relation/13763746", + "basin": "retention", + "boat": "permissive", + "intermittent": "no", + "maxdepth": "2", + "name": "Aasee", + "name:de": "Aasee", + "name:ru": "Аазе", + "natural": "water", + "salt": "no", + "tidal": "no", + "type": "multipolygon", + "water": "lake", + "website": "https://www.aaseepark.de/", + "wikidata": "Q303434", + "wikipedia": "de:Aasee (Münster)" + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + 7.6157143, + 51.9575375 + ], + [ + 7.6156899, + 51.9575098 + ], + [ + 7.6156437, + 51.9574789 + ], + [ + 7.6155894, + 51.9574596 + ], + [ + 7.6155282, + 51.9574454 + ], + [ + 7.6154684, + 51.957442 + ], + [ + 7.61547, + 51.9574267 + ], + [ + 7.6153516, + 51.9574452 + ], + [ + 7.6150165, + 51.9574975 + ], + [ + 7.6144566, + 51.9575722 + ], + [ + 7.6140497, + 51.9576357 + ], + [ + 7.6140325, + 51.9576375 + ], + [ + 7.6137887, + 51.9575415 + ], + [ + 7.6137702, + 51.957534 + ], + [ + 7.6136789, + 51.9574934 + ], + [ + 7.6135826, + 51.9574529 + ], + [ + 7.6135624, + 51.9574451 + ], + [ + 7.61325, + 51.9573207 + ], + [ + 7.613635, + 51.9569508 + ], + [ + 7.6135427, + 51.9569147 + ], + [ + 7.6133267, + 51.9568258 + ], + [ + 7.6129474, + 51.9566682 + ], + [ + 7.6128337, + 51.9566612 + ], + [ + 7.6126224, + 51.9567523 + ], + [ + 7.6122592, + 51.9565908 + ], + [ + 7.6114629, + 51.9561736 + ], + [ + 7.6111883, + 51.9560139 + ], + [ + 7.6108376, + 51.9557374 + ], + [ + 7.6104902, + 51.9554314 + ], + [ + 7.6097663, + 51.9548186 + ], + [ + 7.6090255, + 51.9544084 + ], + [ + 7.6085691, + 51.9541575 + ], + [ + 7.6077852, + 51.9538539 + ], + [ + 7.6072813, + 51.9537208 + ], + [ + 7.6070219, + 51.9536531 + ], + [ + 7.6065993, + 51.9535351 + ], + [ + 7.6063773, + 51.9534273 + ], + [ + 7.6063313, + 51.9532758 + ], + [ + 7.6064002, + 51.9530737 + ], + [ + 7.6064111, + 51.953043 + ], + [ + 7.6064591, + 51.9529027 + ], + [ + 7.6064958, + 51.952723 + ], + [ + 7.605888, + 51.952033 + ], + [ + 7.6051625, + 51.9513376 + ], + [ + 7.6050829, + 51.9511976 + ], + [ + 7.6050181, + 51.9509884 + ], + [ + 7.6049689, + 51.9509501 + ], + [ + 7.6049926, + 51.9509334 + ], + [ + 7.6049849, + 51.9509059 + ], + [ + 7.6049557, + 51.9508896 + ], + [ + 7.6049117, + 51.9508924 + ], + [ + 7.6049065, + 51.9508958 + ], + [ + 7.6047928, + 51.950838 + ], + [ + 7.6044526, + 51.9506713 + ], + [ + 7.6043361, + 51.9506161 + ], + [ + 7.6043436, + 51.9506115 + ], + [ + 7.6043367, + 51.9505837 + ], + [ + 7.6043054, + 51.9505694 + ], + [ + 7.6042678, + 51.9505709 + ], + [ + 7.60401, + 51.9504637 + ], + [ + 7.6039242, + 51.9504179 + ], + [ + 7.6033388, + 51.9501498 + ], + [ + 7.6023831, + 51.9497316 + ], + [ + 7.6017059, + 51.9494198 + ], + [ + 7.6011086, + 51.9491001 + ], + [ + 7.6010159, + 51.9490371 + ], + [ + 7.6004458, + 51.9487102 + ], + [ + 7.6002128, + 51.9485289 + ], + [ + 7.5994473, + 51.9478286 + ], + [ + 7.5989795, + 51.9475082 + ], + [ + 7.5986546, + 51.94738 + ], + [ + 7.598455, + 51.9473125 + ], + [ + 7.5982306, + 51.947238 + ], + [ + 7.5977041, + 51.9471398 + ], + [ + 7.5972518, + 51.9470083 + ], + [ + 7.5970196, + 51.9469421 + ], + [ + 7.5966395, + 51.9468367 + ], + [ + 7.5964178, + 51.946763 + ], + [ + 7.5962854, + 51.9466985 + ], + [ + 7.5960278, + 51.9466378 + ], + [ + 7.5956327, + 51.9465936 + ], + [ + 7.595134, + 51.9466886 + ], + [ + 7.5947954, + 51.9467989 + ], + [ + 7.5947197, + 51.9467027 + ], + [ + 7.5949604, + 51.9466382 + ], + [ + 7.5959862, + 51.9464213 + ], + [ + 7.5963137, + 51.9463488 + ], + [ + 7.5965106, + 51.9462893 + ], + [ + 7.5966614, + 51.946242 + ], + [ + 7.5967846, + 51.9461205 + ], + [ + 7.5968693, + 51.9460448 + ], + [ + 7.5969206, + 51.9459707 + ], + [ + 7.5969925, + 51.9457894 + ], + [ + 7.597047, + 51.9456504 + ], + [ + 7.5969808, + 51.9455649 + ], + [ + 7.5968523, + 51.9452093 + ], + [ + 7.5967061, + 51.9449838 + ], + [ + 7.596629, + 51.9448199 + ], + [ + 7.5964492, + 51.9446228 + ], + [ + 7.5959501, + 51.9442418 + ], + [ + 7.5956478, + 51.9440491 + ], + [ + 7.5952201, + 51.9438003 + ], + [ + 7.5947827, + 51.9434989 + ], + [ + 7.5946879, + 51.9433567 + ], + [ + 7.5946199, + 51.9432144 + ], + [ + 7.5946079, + 51.9430666 + ], + [ + 7.5948367, + 51.9427246 + ], + [ + 7.5949039, + 51.9425438 + ], + [ + 7.5948704, + 51.9424859 + ], + [ + 7.5947985, + 51.942362 + ], + [ + 7.5947094, + 51.9423014 + ], + [ + 7.594597, + 51.9422539 + ], + [ + 7.5945319, + 51.9422224 + ], + [ + 7.5944882, + 51.9421823 + ], + [ + 7.5945221, + 51.9421465 + ], + [ + 7.5945513, + 51.9421157 + ], + [ + 7.5946042, + 51.942115 + ], + [ + 7.5946072, + 51.9421312 + ], + [ + 7.5946124, + 51.9421558 + ], + [ + 7.5946199, + 51.9421617 + ], + [ + 7.5949053, + 51.9421196 + ], + [ + 7.5950468, + 51.9422059 + ], + [ + 7.5952113, + 51.9424227 + ], + [ + 7.5955127, + 51.9425852 + ], + [ + 7.5961801, + 51.9427417 + ], + [ + 7.5969764, + 51.9429528 + ], + [ + 7.5972824, + 51.9430848 + ], + [ + 7.597347, + 51.9431126 + ], + [ + 7.5977841, + 51.943302 + ], + [ + 7.5979961, + 51.9434344 + ], + [ + 7.59846, + 51.9437213 + ], + [ + 7.5989534, + 51.9440323 + ], + [ + 7.5990934, + 51.9441721 + ], + [ + 7.5993623, + 51.9444406 + ], + [ + 7.5996662, + 51.9449117 + ], + [ + 7.6004722, + 51.9462518 + ], + [ + 7.6007637, + 51.9465093 + ], + [ + 7.6008701, + 51.9466034 + ], + [ + 7.6009127, + 51.9466413 + ], + [ + 7.6018003, + 51.9474261 + ], + [ + 7.6030034, + 51.9483324 + ], + [ + 7.6044316, + 51.9492287 + ], + [ + 7.604536, + 51.9492936 + ], + [ + 7.6052133, + 51.9497625 + ], + [ + 7.6053944, + 51.9498478 + ], + [ + 7.6054423, + 51.9498779 + ], + [ + 7.6058453, + 51.9501057 + ], + [ + 7.6059466, + 51.950228 + ], + [ + 7.6059819, + 51.9502849 + ], + [ + 7.6059834, + 51.9503352 + ], + [ + 7.6062293, + 51.9506171 + ], + [ + 7.6074594, + 51.9514869 + ], + [ + 7.6078902, + 51.9518081 + ], + [ + 7.6099172, + 51.9532409 + ], + [ + 7.6109726, + 51.9538047 + ], + [ + 7.6119448, + 51.954136 + ], + [ + 7.6143249, + 51.9548004 + ], + [ + 7.6152884, + 51.9551533 + ], + [ + 7.6165375, + 51.9557334 + ], + [ + 7.6167369, + 51.955835 + ], + [ + 7.6170599, + 51.956024 + ], + [ + 7.6177713, + 51.9564231 + ], + [ + 7.6177874, + 51.9564359 + ], + [ + 7.6178055, + 51.9564537 + ], + [ + 7.617813, + 51.9564667 + ], + [ + 7.6178236, + 51.956507 + ], + [ + 7.6178277, + 51.9565756 + ], + [ + 7.6178238, + 51.9566778 + ], + [ + 7.617771, + 51.9566982 + ], + [ + 7.6177165, + 51.9567225 + ], + [ + 7.6176628, + 51.9567597 + ], + [ + 7.6176262, + 51.9568057 + ], + [ + 7.617605, + 51.9568712 + ], + [ + 7.6176197, + 51.9569319 + ], + [ + 7.6176625, + 51.9569827 + ], + [ + 7.6176985, + 51.9570028 + ], + [ + 7.6175904, + 51.9571503 + ], + [ + 7.617547, + 51.9571898 + ], + [ + 7.6174866, + 51.9572278 + ], + [ + 7.6164876, + 51.9573997 + ], + [ + 7.6164517, + 51.957396 + ], + [ + 7.6164097, + 51.95741 + ], + [ + 7.6163641, + 51.9574088 + ], + [ + 7.616277, + 51.9574325 + ], + [ + 7.6161141, + 51.9574454 + ], + [ + 7.6160064, + 51.9574668 + ], + [ + 7.6159705, + 51.957492 + ], + [ + 7.6159568, + 51.9575542 + ], + [ + 7.6159585, + 51.9576016 + ], + [ + 7.616063, + 51.957932 + ], + [ + 7.6160797, + 51.9580152 + ], + [ + 7.6160683, + 51.9581391 + ], + [ + 7.616022, + 51.9583578 + ], + [ + 7.6159424, + 51.9585832 + ], + [ + 7.6158718, + 51.9586977 + ], + [ + 7.6158347, + 51.9587501 + ], + [ + 7.6157778, + 51.9588118 + ], + [ + 7.6152391, + 51.9594326 + ], + [ + 7.6149129, + 51.9597959 + ], + [ + 7.6147119, + 51.9600104 + ], + [ + 7.6145594, + 51.9601642 + ], + [ + 7.6145116, + 51.9601984 + ], + [ + 7.6144869, + 51.9602312 + ], + [ + 7.6144524, + 51.9602633 + ], + [ + 7.6144448, + 51.9603026 + ], + [ + 7.6144463, + 51.9603363 + ], + [ + 7.614457, + 51.9603751 + ], + [ + 7.6144479, + 51.9603924 + ], + [ + 7.6144152, + 51.9603975 + ], + [ + 7.6144099, + 51.9604078 + ], + [ + 7.6144243, + 51.96042 + ], + [ + 7.6144441, + 51.9604246 + ], + [ + 7.6144828, + 51.9604139 + ], + [ + 7.6145283, + 51.9604139 + ], + [ + 7.6145632, + 51.9604286 + ], + [ + 7.6145436, + 51.9604482 + ], + [ + 7.6145237, + 51.9604681 + ], + [ + 7.6144782, + 51.9604686 + ], + [ + 7.6144281, + 51.9604625 + ], + [ + 7.6143462, + 51.9604443 + ], + [ + 7.6143007, + 51.9604251 + ], + [ + 7.6142848, + 51.9603821 + ], + [ + 7.6142817, + 51.9603381 + ], + [ + 7.6142855, + 51.9602778 + ], + [ + 7.6143007, + 51.9602091 + ], + [ + 7.6143027, + 51.9601915 + ], + [ + 7.6144259, + 51.9600058 + ], + [ + 7.6146717, + 51.9596963 + ], + [ + 7.6150047, + 51.9593232 + ], + [ + 7.6152209, + 51.9590633 + ], + [ + 7.6154728, + 51.9587777 + ], + [ + 7.6156344, + 51.9585888 + ], + [ + 7.6157057, + 51.9584906 + ], + [ + 7.6157467, + 51.958391 + ], + [ + 7.6157838, + 51.9582657 + ], + [ + 7.6158066, + 51.9581442 + ], + [ + 7.6158142, + 51.957867 + ], + [ + 7.6158043, + 51.9578557 + ], + [ + 7.6157937, + 51.9578389 + ], + [ + 7.6157853, + 51.9578123 + ], + [ + 7.6157512, + 51.9575958 + ], + [ + 7.6157143, + 51.9575375 + ] + ] + ] + }, + "id": "relation/13763746" + } + ] +} \ No newline at end of file diff -r 000000000000 -r d07fcc660f3c test-data/run_idw_interpolation_test_output.png Binary file test-data/run_idw_interpolation_test_output.png has changed