-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from CRC-FONDA/dev
Adressing review suggestions for Version 1.0.0
- Loading branch information
Showing
49 changed files
with
3,349 additions
and
544 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ testing/ | |
testing* | ||
*.pyc | ||
null/ | ||
.nf-test* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,46 @@ | ||
#!/usr/bin/env Rscript | ||
|
||
args = commandArgs(trailingOnly=TRUE) | ||
## Originally written by Felix Kummer and released under the MIT license. | ||
## See git repository (https://github.com/nf-core/rangeland) for full license text. | ||
|
||
# Script for merging bottom of atmosphere (boa) .tif raster files. | ||
# This can improve the performance of downstream tasks. | ||
|
||
if (length(args) < 3) { | ||
stop("\nthis program needs at least 3 inputs\n1: output filename\n2-*: input files", call.=FALSE) | ||
} | ||
|
||
fout <- args[1] | ||
finp <- args[2:length(args)] | ||
nf <- length(finp) | ||
|
||
require(raster) | ||
|
||
|
||
img <- brick(finp[1]) | ||
nc <- ncell(img) | ||
nb <- nbands(img) | ||
require(terra) | ||
|
||
args <- commandArgs(trailingOnly = TRUE) | ||
|
||
sum <- matrix(0, nc, nb) | ||
num <- matrix(0, nc, nb) | ||
|
||
for (i in 1:nf){ | ||
|
||
data <- brick(finp[i])[] | ||
|
||
num <- num + !is.na(data) | ||
|
||
data[is.na(data)] <- 0 | ||
sum <- sum + data | ||
|
||
if (length(args) < 3) { | ||
stop("\nError: this program needs at least 3 inputs\n1: output filename\n2-*: input files", call.=FALSE) | ||
} | ||
|
||
mean <- sum/num | ||
img[] <- mean | ||
|
||
fout <- args[1] | ||
finp <- args[2:length(args)] | ||
|
||
writeRaster(img, filename = fout, format = "GTiff", datatype = "INT2S", | ||
options = c("INTERLEAVE=BAND", "COMPRESS=LZW", "PREDICTOR=2", | ||
"NUM_THREADS=ALL_CPUS", "BIGTIFF=YES", | ||
sprintf("BLOCKXSIZE=%s", img@file@blockcols[1]), | ||
sprintf("BLOCKYSIZE=%s", img@file@blockrows[1]))) | ||
# Load input rasters | ||
rasters <- lapply(finp, rast) | ||
|
||
# Calculate the sum of non-NA values across all rasters | ||
sum_rasters <- Reduce("+", lapply(rasters, function(x) { | ||
x[is.na(x)] <- 0 | ||
return(x) | ||
})) | ||
|
||
# Calculate the number of values non-NA values for each cell | ||
count_rasters <- Reduce("+", lapply(rasters, function(x) { | ||
return(!is.na(x)) | ||
})) | ||
|
||
# Calculate the mean raster | ||
mean_raster <- sum_rasters / count_rasters | ||
|
||
# Write the mean raster | ||
writeRaster(mean_raster, | ||
filename = fout, | ||
datatype = "INT2S", | ||
filetype = "GTiff", | ||
gdal = c("COMPRESS=LZW", "PREDICTOR=2", | ||
"NUM_THREADS=ALL_CPUS", "BIGTIFF=YES", | ||
sprintf("BLOCKXSIZE=%s", ncol(mean_raster)), | ||
sprintf("BLOCKYSIZE=%s", nrow(mean_raster)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,41 @@ | ||
#!/usr/bin/env Rscript | ||
|
||
args = commandArgs(trailingOnly=TRUE) | ||
## Originally written by Felix Kummer and released under the MIT license. | ||
## See git repository (https://github.com/nf-core/rangeland) for full license text. | ||
|
||
# Script for merging quality information (qai) .tif raster files. | ||
# This can improve the performance of downstream tasks. | ||
|
||
if (length(args) < 3) { | ||
stop("\nthis program needs at least 3 inputs\n1: output filename\n2-*: input files", call.=FALSE) | ||
} | ||
|
||
fout <- args[1] | ||
finp <- args[2:length(args)] | ||
nf <- length(finp) | ||
|
||
require(raster) | ||
|
||
|
||
img <- raster(finp[1]) | ||
nc <- ncell(img) | ||
require(terra) | ||
|
||
args <- commandArgs(trailingOnly = TRUE) | ||
|
||
last <- rep(1, nc) | ||
|
||
for (i in 1:nf){ | ||
|
||
data <- raster(finp[i])[] | ||
|
||
last[!is.na(data)] <- data[!is.na(data)] | ||
|
||
if (length(args) < 3) { | ||
stop("\nError: this program needs at least 3 inputs\n1: output filename\n2-*: input files", call.=FALSE) | ||
} | ||
|
||
img[] <- last | ||
|
||
fout <- args[1] | ||
finp <- args[2:length(args)] | ||
|
||
writeRaster(img, filename = fout, format = "GTiff", datatype = "INT2S", | ||
options = c("INTERLEAVE=BAND", "COMPRESS=LZW", "PREDICTOR=2", | ||
"NUM_THREADS=ALL_CPUS", "BIGTIFF=YES", | ||
sprintf("BLOCKXSIZE=%s", img@file@blockcols[1]), | ||
sprintf("BLOCKYSIZE=%s", img@file@blockrows[1]))) | ||
# load raster files into single SpatRaster | ||
rasters <- rast(finp) | ||
|
||
# Merge rasters by maintaining the last non-NA value | ||
merged_raster <- app(rasters, function(x) { | ||
non_na_values <- na.omit(x) | ||
if (length(non_na_values) == 0) { | ||
return(1) | ||
} | ||
return(tail(non_na_values, 1)[1]) | ||
}) | ||
|
||
# Write merged raster | ||
writeRaster(merged_raster, | ||
filename = fout, | ||
filetype = "GTiff", | ||
datatype = "INT2S", | ||
gdal = c("INTERLEAVE=BAND", "COMPRESS=LZW", "PREDICTOR=2", | ||
"NUM_THREADS=ALL_CPUS", "BIGTIFF=YES", | ||
sprintf("BLOCKXSIZE=%s", ncol(merged_raster)), | ||
sprintf("BLOCKYSIZE=%s", nrow(merged_raster)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.