Skip to main content
added 4 characters in body
Source Link
library("raster")
library("maps")
library("rgeos")
library("grid")
library("ncdf4")
library("maptools")
library("mapdata")
library("rgdal")
library("lattice")
library("Kendall")
#
files = list.files(path="/my/path/.../", pattern="*.nc", full.names = T, recursive = T)
#
rast = stack()
trend_rast = stack()
trend_rast_mask = raster()
#
for (i in 1:length(files)) {
  print(files[i])
  rast = raster::stack(files[i])
  print(class(rast))
  file_name = print(files[i])
  trend_rast = raster.kendall(rast, intercept = F, p.value = T, confidence = F, tau = T)
  names(trend_rast) = c("slope","p.value","tau")
  trend_rast_sen = trend_rast[[1]]
  writeRaster(trend_rast_sen, paste("/my/output/.../", file_name, "_SEN_SLOPE", ".nc", sep=""), format="CDF", overwrite=TRUE)
}
library("raster")
library("maps")
library("rgeos")
library("grid")
library("ncdf4")
library("maptools")
library("mapdata")
library("rgdal")
library("lattice")
library("Kendall")
#
files = list.files(path="/my/path/.../", pattern="*.nc", full.names = T, recursive = T)
#
rast = stack()
trend_rast = stack()
trend_rast_mask = raster()
#
for (i in 1:length(files)) {
  print(files[i])
  rast = raster::stack(files[i])
  print(class(rast))
  file_name = print(files[i])
  trend_rast = raster.kendall(rast, intercept = F, p.value = T, confidence = F, tau = T)
  names(trend_rast) = c("slope","p.value","tau")
  trend_rast_sen = trend_rast[[1]]
  writeRaster(trend_rast_sen, paste("/my/output/", file_name, "_SEN_SLOPE", ".nc", sep=""), format="CDF", overwrite=TRUE)
}
library("raster")
library("maps")
library("rgeos")
library("grid")
library("ncdf4")
library("maptools")
library("mapdata")
library("rgdal")
library("lattice")
library("Kendall")
#
files = list.files(path="/my/path/.../", pattern="*.nc", full.names = T, recursive = T)
#
rast = stack()
trend_rast = stack()
trend_rast_mask = raster()
#
for (i in 1:length(files)) {
  print(files[i])
  rast = raster::stack(files[i])
  print(class(rast))
  file_name = print(files[i])
  trend_rast = raster.kendall(rast, intercept = F, p.value = T, confidence = F, tau = T)
  names(trend_rast) = c("slope","p.value","tau")
  trend_rast_sen = trend_rast[[1]]
  writeRaster(trend_rast_sen, paste("/my/output/.../", file_name, "_SEN_SLOPE", ".nc", sep=""), format="CDF", overwrite=TRUE)
}
added 175 characters in body
Source Link
library("raster")
library("maps")
library("rgeos")
library("grid")
library("ncdf4")
library("maptools")
library("mapdata")
library("rgdal")
library("lattice")
library("Kendall")
#
files = list.files(path="/my/path/.../", pattern="*.nc", full.names = T, recursive = T)
#
rast = stack()
trend_rast = stack()
mask_points = 
trend_rast_mask = raster()
#
for (i in 1:length(files)) {
  print(files[i])
  rast = raster::stack(files[i])
  print(class(rast))
  file_name = print(files[i])
  trend_rast = raster.kendall(rast, intercept = F, p.value = T, confidence = F, tau = T)
  names(trend_rast) = c("slope","p.value","tau")
  trend_rast_sen = trend_rast[[1]]
  writeRaster(trend_rast_sen, paste("/my/output/", file_name, "_SEN_SLOPE", ".nc", sep=""), format="CDF", overwrite=TRUE)
}
files = list.files(path="/my/path/.../", pattern="*.nc", full.names = T, recursive = T)
#
rast = stack()
trend_rast = stack()
mask_points = 
trend_rast_mask = raster()
#
for (i in 1:length(files)) {
  print(files[i])
  rast = raster::stack(files[i])
  print(class(rast))
  file_name = print(files[i])
  trend_rast = raster.kendall(rast, intercept = F, p.value = T, confidence = F, tau = T)
  names(trend_rast) = c("slope","p.value","tau")
  trend_rast_sen = trend_rast[[1]]
  writeRaster(trend_rast_sen, paste("/my/output/", file_name, "_SEN_SLOPE", ".nc", sep=""), format="CDF", overwrite=TRUE)
}
library("raster")
library("maps")
library("rgeos")
library("grid")
library("ncdf4")
library("maptools")
library("mapdata")
library("rgdal")
library("lattice")
library("Kendall")
#
files = list.files(path="/my/path/.../", pattern="*.nc", full.names = T, recursive = T)
#
rast = stack()
trend_rast = stack()
trend_rast_mask = raster()
#
for (i in 1:length(files)) {
  print(files[i])
  rast = raster::stack(files[i])
  print(class(rast))
  file_name = print(files[i])
  trend_rast = raster.kendall(rast, intercept = F, p.value = T, confidence = F, tau = T)
  names(trend_rast) = c("slope","p.value","tau")
  trend_rast_sen = trend_rast[[1]]
  writeRaster(trend_rast_sen, paste("/my/output/", file_name, "_SEN_SLOPE", ".nc", sep=""), format="CDF", overwrite=TRUE)
}
added 685 characters in body
Source Link

I am reading the netcdf files in R as a raster stack and the code worked fine for all datasets with resolutions up to 0.05 x 0.05, however in this one, results are messy and I am wondering if its something that has to do with memory. A sample .nc file that I use can be found here.

files = list.files(path="/my/path/.../", pattern="*.nc", full.names = T, recursive = T)
#
rast = stack()
trend_rast = stack()
mask_points = 
trend_rast_mask = raster()
#
for (i in 1:length(files)) {
  print(files[i])
  rast = raster::stack(files[i])
  print(class(rast))
  file_name = print(files[i])
  trend_rast = raster.kendall(rast, intercept = F, p.value = T, confidence = F, tau = T)
  names(trend_rast) = c("slope","p.value","tau")
  trend_rast_sen = trend_rast[[1]]
  writeRaster(trend_rast_sen, paste("/my/output/", file_name, "_SEN_SLOPE", ".nc", sep=""), format="CDF", overwrite=TRUE)
}

I am reading the netcdf files in R as a raster stack and the code worked fine for all datasets with resolutions up to 0.05 x 0.05, however in this one results are messy and I am wondering if its something that has to do with memory.

I am reading the netcdf files in R as a raster stack and the code worked fine for all datasets with resolutions up to 0.05 x 0.05, however in this one, results are messy and I am wondering if its something that has to do with memory. A sample .nc file that I use can be found here.

files = list.files(path="/my/path/.../", pattern="*.nc", full.names = T, recursive = T)
#
rast = stack()
trend_rast = stack()
mask_points = 
trend_rast_mask = raster()
#
for (i in 1:length(files)) {
  print(files[i])
  rast = raster::stack(files[i])
  print(class(rast))
  file_name = print(files[i])
  trend_rast = raster.kendall(rast, intercept = F, p.value = T, confidence = F, tau = T)
  names(trend_rast) = c("slope","p.value","tau")
  trend_rast_sen = trend_rast[[1]]
  writeRaster(trend_rast_sen, paste("/my/output/", file_name, "_SEN_SLOPE", ".nc", sep=""), format="CDF", overwrite=TRUE)
}
deleted 6 characters in body
Source Link
Loading
deleted 103 characters in body
Source Link
Loading
Source Link
Loading