From 202f656a1e8d2a49ef0310f75f2e69322706437b Mon Sep 17 00:00:00 2001 From: istfer Date: Wed, 1 Nov 2023 11:34:12 +0200 Subject: [PATCH 1/9] changed rgdal function to terra in GEFS_helpers --- .../data.atmosphere/R/GEFS_helper_functions.R | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/modules/data.atmosphere/R/GEFS_helper_functions.R b/modules/data.atmosphere/R/GEFS_helper_functions.R index 99b0a4db6e6..c63768daf11 100644 --- a/modules/data.atmosphere/R/GEFS_helper_functions.R +++ b/modules/data.atmosphere/R/GEFS_helper_functions.R @@ -243,25 +243,30 @@ process_gridded_noaa_download <- function(lat_list, for(hr in 1:length(curr_hours)){ file_name <- paste0(base_filename2, curr_hours[hr]) + grib_file_name <- paste0(working_directory,"/", file_name,".grib") - if(file.exists(paste0(working_directory,"/", file_name,".grib"))){ - grib <- rgdal::readGDAL(paste0(working_directory,"/", file_name,".grib"), silent = TRUE) - lat_lon <- sp::coordinates(grib) + if(file.exists(grib_file_name)){ + grib_data <- terra::rast(grib_file_name) + + ## Convert to data frame + grib_data_df <- terra::as.data.frame(grib_data, xy=TRUE) + lat_lon <- grib_data_df[, c("x", "y")] + for(s in 1:length(site_id)){ index <- which(lat_lon[,2] == lats[s] & lat_lon[,1] == lons[s]) - pressfc[s, hr] <- grib$band1[index] - tmp2m[s, hr] <- grib$band2[index] - rh2m[s, hr] <- grib$band3[index] - ugrd10m[s, hr] <- grib$band4[index] - vgrd10m[s, hr] <- grib$band5[index] + pressfc[s, hr] <- grib_data_df$`SFC=Ground or water surface; Pressure [Pa]`[index] + tmp2m[s, hr] <- grib_data_df$`2[m] HTGL=Specified height level above ground; Temperature [C]`[index] + rh2m[s, hr] <- grib_data_df$`2[m] HTGL=Specified height level above ground; Relative humidity [%]`[index] + ugrd10m[s, hr] <- grib_data_df$`10[m] HTGL=Specified height level above ground; u-component of wind [m/s]`[index] + vgrd10m[s, hr] <- grib_data_df$`10[m] HTGL=Specified height level above ground; v-component of wind [m/s]`[index] if(curr_hours[hr] != "000"){ - apcpsfc[s, hr] <- grib$band6[index] - tcdcclm[s, hr] <- grib$band7[index] - dswrfsfc[s, hr] <- grib$band8[index] - dlwrfsfc[s, hr] <- grib$band9[index] + apcpsfc[s, hr] <- grib_data_df$`SFC=Ground or water surface; 03 hr Total precipitation [kg/(m^2)]`[index] + tcdcclm[s, hr] <- grib_data_df$`RESERVED(10) (Reserved); Total cloud cover [%]`[index] + dswrfsfc[s, hr] <- grib_data_df$`SFC=Ground or water surface; Downward Short-Wave Rad. Flux [W/(m^2)]`[index] + dlwrfsfc[s, hr] <- grib_data_df$`SFC=Ground or water surface; Downward Long-Wave Rad. Flux [W/(m^2)]`[index] } } } From a5c65a6a177eb9a9d480529f459448e5ba2ae8ef Mon Sep 17 00:00:00 2001 From: istfer Date: Wed, 1 Nov 2023 11:59:03 +0200 Subject: [PATCH 2/9] replace rgdal with sf --- modules/data.atmosphere/R/download.NARR_site.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/data.atmosphere/R/download.NARR_site.R b/modules/data.atmosphere/R/download.NARR_site.R index 7ecfbca6bae..703546874e2 100644 --- a/modules/data.atmosphere/R/download.NARR_site.R +++ b/modules/data.atmosphere/R/download.NARR_site.R @@ -465,9 +465,9 @@ latlon2narr <- function(nc, lat.in, lon.in) { #' @inheritParams get_NARR_thredds #' @return `sp::SpatialPoints` object containing transformed x and y #' coordinates, in km, which should match NARR coordinates -#' @importFrom rgdal checkCRSArgs +#' @importFrom sf st_crs # ^not used directly here, but needed by sp::CRS. - # sp lists rgdal in Suggests rather than Imports, + # sp lists sf in Suggests rather than Imports, # so importing it here to ensure it's available at run time #' @author Alexey Shiklomanov #' @export From f5756af4e69d80f7c8f215b7644c1ece96386777 Mon Sep 17 00:00:00 2001 From: istfer Date: Wed, 1 Nov 2023 12:02:54 +0200 Subject: [PATCH 3/9] roxygenize --- modules/data.atmosphere/DESCRIPTION | 3 ++- modules/data.atmosphere/NAMESPACE | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/data.atmosphere/DESCRIPTION b/modules/data.atmosphere/DESCRIPTION index a29287049c5..9b9d5706e3a 100644 --- a/modules/data.atmosphere/DESCRIPTION +++ b/modules/data.atmosphere/DESCRIPTION @@ -49,10 +49,11 @@ Imports: raster, REddyProc, reshape2, - rgdal, rlang (>= 0.2.0), + sf, sp, stringr (>= 1.1.0), + terra, testthat (>= 2.0.0), tibble, tidyr, diff --git a/modules/data.atmosphere/NAMESPACE b/modules/data.atmosphere/NAMESPACE index 7183782887f..9dd14faa440 100644 --- a/modules/data.atmosphere/NAMESPACE +++ b/modules/data.atmosphere/NAMESPACE @@ -113,5 +113,5 @@ export(write_noaa_gefs_netcdf) import(dplyr) import(tidyselect) importFrom(magrittr,"%>%") -importFrom(rgdal,checkCRSArgs) importFrom(rlang,.data) +importFrom(sf,st_crs) From 9624d3d4946c775f5e5180c8ecb81647ce9cb95f Mon Sep 17 00:00:00 2001 From: istfer Date: Wed, 1 Nov 2023 12:20:06 +0200 Subject: [PATCH 4/9] change maptools to suntools --- modules/data.atmosphere/DESCRIPTION | 2 +- .../R/met_temporal_downscale.Gaussian_ensemble.R | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/data.atmosphere/DESCRIPTION b/modules/data.atmosphere/DESCRIPTION index 9b9d5706e3a..b07be4c42d9 100644 --- a/modules/data.atmosphere/DESCRIPTION +++ b/modules/data.atmosphere/DESCRIPTION @@ -36,7 +36,6 @@ Imports: jsonlite, lubridate (>= 1.6.0), magrittr, - maptools, MASS, mgcv, ncdf4 (>= 1.15), @@ -53,6 +52,7 @@ Imports: sf, sp, stringr (>= 1.1.0), + suntools, terra, testthat (>= 2.0.0), tibble, diff --git a/modules/data.atmosphere/R/met_temporal_downscale.Gaussian_ensemble.R b/modules/data.atmosphere/R/met_temporal_downscale.Gaussian_ensemble.R index 1082ffb60e3..a241d1fbe5f 100644 --- a/modules/data.atmosphere/R/met_temporal_downscale.Gaussian_ensemble.R +++ b/modules/data.atmosphere/R/met_temporal_downscale.Gaussian_ensemble.R @@ -216,11 +216,11 @@ met_temporal_downscale.Gaussian_ensemble <- function(in.path, in.prefix, outfold day <- as.POSIXct(sprintf("%s 12:00:00", date), tz = tz) sequence <- seq(from = day, length.out = span, by = "days") - sunrise <- maptools::sunriset(lon.lat, sequence, direction = "sunrise", + sunrise <- suntools::sunriset(lon.lat, sequence, direction = "sunrise", POSIXct.out = TRUE) - sunset <- maptools::sunriset(lon.lat, sequence, direction = "sunset", + sunset <- suntools::sunriset(lon.lat, sequence, direction = "sunset", POSIXct.out = TRUE) - solar_noon <- maptools::solarnoon(lon.lat, sequence, POSIXct.out = TRUE) + solar_noon <- suntools::solarnoon(lon.lat, sequence, POSIXct.out = TRUE) data.frame(date = as.Date(sunrise$time), sunrise = as.numeric(format(sunrise$time, "%H%M")), solarnoon = as.numeric(format(solar_noon$time, "%H%M")), From c3221122c313f79b3ca41f9aa63ae1bfc9d7255b Mon Sep 17 00:00:00 2001 From: istfer Date: Wed, 1 Nov 2023 12:29:43 +0200 Subject: [PATCH 5/9] add suntools remove maptools --- docker/depends/pecan.depends.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/depends/pecan.depends.R b/docker/depends/pecan.depends.R index c208e5e5525..69728e55fbc 100644 --- a/docker/depends/pecan.depends.R +++ b/docker/depends/pecan.depends.R @@ -76,7 +76,6 @@ wanted <- c( 'magic', 'magrittr', 'maps', -'maptools', 'markdown', 'MASS', 'Matrix', @@ -130,6 +129,7 @@ wanted <- c( 'stats', 'stringi', 'stringr', +'suntools', 'swfscMisc', 'terra', 'testthat', From 00a12222c8e5a6eab8ad7ebfb3e4ab7a73065de9 Mon Sep 17 00:00:00 2001 From: istfer Date: Fri, 3 Nov 2023 09:07:22 +0200 Subject: [PATCH 6/9] generate dependencies --- docker/depends/pecan.depends.R | 1 - 1 file changed, 1 deletion(-) diff --git a/docker/depends/pecan.depends.R b/docker/depends/pecan.depends.R index 69728e55fbc..5b03d7297e5 100644 --- a/docker/depends/pecan.depends.R +++ b/docker/depends/pecan.depends.R @@ -112,7 +112,6 @@ wanted <- c( 'reshape', 'reshape2', 'reticulate', -'rgdal', 'rjags', 'rjson', 'rlang', From a4c7e14697afc172710a235b31a25e9e4c663c11 Mon Sep 17 00:00:00 2001 From: istfer Date: Sun, 5 Nov 2023 09:32:13 +0200 Subject: [PATCH 7/9] remote install suntools --- docker/depends/pecan.depends.R | 2 +- modules/data.atmosphere/DESCRIPTION | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/depends/pecan.depends.R b/docker/depends/pecan.depends.R index 5b03d7297e5..3e292529a6b 100644 --- a/docker/depends/pecan.depends.R +++ b/docker/depends/pecan.depends.R @@ -9,6 +9,7 @@ Sys.setenv(RLIB = rlib) # install remotes first in case packages are references in dependencies remotes::install_github(c( +'adokter/suntools', 'araiho/linkages_package', 'chuhousen/amerifluxr', 'ebimodeling/biocro@0.951', @@ -128,7 +129,6 @@ wanted <- c( 'stats', 'stringi', 'stringr', -'suntools', 'swfscMisc', 'terra', 'testthat', diff --git a/modules/data.atmosphere/DESCRIPTION b/modules/data.atmosphere/DESCRIPTION index b07be4c42d9..8f0482e9e41 100644 --- a/modules/data.atmosphere/DESCRIPTION +++ b/modules/data.atmosphere/DESCRIPTION @@ -52,7 +52,6 @@ Imports: sf, sp, stringr (>= 1.1.0), - suntools, terra, testthat (>= 2.0.0), tibble, @@ -70,6 +69,7 @@ Suggests: progress, reticulate Remotes: + github::adokter/suntools, github::chuhousen/amerifluxr, github::ropensci/geonames, github::ropensci/nneo From ad8adce78cccd7b5b457f96f475eb5d488972920 Mon Sep 17 00:00:00 2001 From: istfer Date: Sun, 5 Nov 2023 09:52:49 +0200 Subject: [PATCH 8/9] working with CI --- docker/depends/pecan.depends.R | 1 + modules/data.atmosphere/DESCRIPTION | 1 + 2 files changed, 2 insertions(+) diff --git a/docker/depends/pecan.depends.R b/docker/depends/pecan.depends.R index 3e292529a6b..e49b8fb72fb 100644 --- a/docker/depends/pecan.depends.R +++ b/docker/depends/pecan.depends.R @@ -129,6 +129,7 @@ wanted <- c( 'stats', 'stringi', 'stringr', +'suntools', 'swfscMisc', 'terra', 'testthat', diff --git a/modules/data.atmosphere/DESCRIPTION b/modules/data.atmosphere/DESCRIPTION index 8f0482e9e41..097a134349e 100644 --- a/modules/data.atmosphere/DESCRIPTION +++ b/modules/data.atmosphere/DESCRIPTION @@ -52,6 +52,7 @@ Imports: sf, sp, stringr (>= 1.1.0), + suntools, terra, testthat (>= 2.0.0), tibble, From 6900a0f40410792c6aa11a1579e480691a15e2b6 Mon Sep 17 00:00:00 2001 From: istfer Date: Sun, 5 Nov 2023 10:09:52 +0200 Subject: [PATCH 9/9] rcheck ref --- modules/data.atmosphere/tests/Rcheck_reference.log | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/data.atmosphere/tests/Rcheck_reference.log b/modules/data.atmosphere/tests/Rcheck_reference.log index 1f7a42f6634..be30baa7ac2 100644 --- a/modules/data.atmosphere/tests/Rcheck_reference.log +++ b/modules/data.atmosphere/tests/Rcheck_reference.log @@ -76,13 +76,13 @@ Found the following (possibly) invalid URLs: The Date field is over a month old. * checking package namespace information ... OK * checking package dependencies ... WARNING -Imports includes 39 non-default packages. +Imports includes 40 non-default packages. Importing from so many packages makes the package vulnerable to any of them becoming unavailable. Move as many as possible to Suggests and use conditionally. * checking package dependencies ... NOTE -Imports includes 39 non-default packages. +Imports includes 40 non-default packages. Importing from so many packages makes the package vulnerable to any of them becoming unavailable. Move as many as possible to Suggests and use conditionally.