Skip to content

Commit

Permalink
fix warnings/notes in data.remote package
Browse files Browse the repository at this point in the history
  • Loading branch information
moki1202 committed Sep 18, 2023
1 parent ce327b9 commit 0e84cc8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
18 changes: 9 additions & 9 deletions modules/data.remote/R/NLCD.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ download.NLCD <- function(outdir, year = 2011, con = NULL) {
## before downloading, check if the file already exists on this host
if (!is.null(con)) {
library(PEcAn.DB)
chk <- dbfile.check(type = "Input", id = input.id, con = con)
chk <- PEcAn.DB::dbfile.check(type = "Input", id = input.id, con = con)
if (nrow(chk) > 0) {
machines <- db.query(paste("SELECT * from machines where id in (",
machines <- PEcAn.DB::db.query(paste("SELECT * from machines where id in (",
paste(chk$machine_id, sep = ","), ")"), con)
if (PEcAn.remote::fqdn() %in% machines$hostname) {
## record already exists on this host
Expand All @@ -49,7 +49,7 @@ download.NLCD <- function(outdir, year = 2011, con = NULL) {
prefix <- table(sapply(strsplit(dir(data_dir), ".", fixed = TRUE), function(x) { x[1] }))
prefix <- names(which.max(prefix))
site.id <- 1000000676
return(dbfile.insert(data_dir, in.prefix = prefix, type = "Input", input.id, con,
return(PEcAn.DB::dbfile.insert(data_dir, in.prefix = prefix, type = "Input", input.id, con,
reuse = TRUE))
}
return(data_dir)
Expand Down Expand Up @@ -80,9 +80,9 @@ extract_NLCD <- function(buffer, coords, data_dir = NULL, con = NULL, year = 201
} else {
print(paste("Year not yet supported: ", year))
}
chk <- dbfile.check(type = "Input", id = input.id, con = con)
chk <- PEcAn.DB::dbfile.check(type = "Input", id = input.id, con = con)
if (nrow(chk) > 0) {
machines <- db.query(paste("SELECT * from machines where id in (",
machines <- PEcAn.DB::db.query(paste("SELECT * from machines where id in (",
paste(chk$machine_id, sep = ","), ")"), con)
if (PEcAn.remote::fqdn() %in% machines$hostname) {
## record already exists on this host
Expand All @@ -104,14 +104,14 @@ extract_NLCD <- function(buffer, coords, data_dir = NULL, con = NULL, year = 201
print(paste("File not found:", filename))
return(NULL)
}
nlcd <- raster(filename)
nlcd <- raster::raster(filename)

# transform points
sites <- SpatialPoints(coords = coords, proj4string = CRS("+proj=longlat +datum=WGS84"))
sites <- spTransform(sites, crs(nlcd))
sites <- sp::SpatialPoints(coords = coords, proj4string = sp::CRS("+proj=longlat +datum=WGS84"))
sites <- sp::spTransform(sites, raster::crs(nlcd))

# extract
sum.raw <- table(extract(nlcd, sites, buffer = buffer))
sum.raw <- table(raster::extract(nlcd, sites, buffer = buffer))
summ <- prop.table(sum.raw)
mydf <- data.frame(cover = names(summ), percent = as.vector(summ), count = as.vector(sum.raw))

Expand Down
2 changes: 1 addition & 1 deletion modules/data.remote/R/call_MODIS.R
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ call_MODIS <- function(var, product,
fname <- paste(site_info$site_id[i], "/", product, "_", band, "_", start_date, "-", end_date, "_unfiltered.csv", sep = "")
}
fname <- file.path(outdir, fname)
write.csv(site, fname, row.names = FALSE)
utils::write.csv(site, fname, row.names = FALSE)
}

}
Expand Down
6 changes: 3 additions & 3 deletions modules/data.remote/R/download.thredds.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ download.thredds.AGB <- function(outdir = NULL, site_ids, run_parallel = FALSE,
# option to save output dataset to directory for user.
if (!(is.null(outdir)))
{
write.csv(output, file = paste0(outdir, "THREDDS_", sub("^([^.]*).*", "\\1",basename(files[1])), "_site_", site, ".csv"), row.names = FALSE)
utils::write.csv(output, file = paste0(outdir, "THREDDS_", sub("^([^.]*).*", "\\1",basename(files[1])), "_site_", site, ".csv"), row.names = FALSE)
}

return(output)
Expand All @@ -86,8 +86,8 @@ download.thredds.AGB <- function(outdir = NULL, site_ids, run_parallel = FALSE,
PEcAn.logger::logger.info(paste0("Running in parallel with: ", ncores))
cl = parallel::makeCluster(ncores)
doParallel::registerDoParallel(cl)
data = foreach(i = seq_along(mylat), .combine = rbind) %dopar% get_data(i)
stopCluster(cl)
data = foreach::foreach(i = seq_along(mylat), .combine = rbind) %dopar% get_data(i)
parallel::stopCluster(cl)

} else {
# setup sequential run
Expand Down

0 comments on commit 0e84cc8

Please sign in to comment.