Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove rgdal and maptools from data.atmosphere #3228

Merged
merged 12 commits into from
Nov 6, 2023
3 changes: 2 additions & 1 deletion modules/data.atmosphere/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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,
2 changes: 1 addition & 1 deletion modules/data.atmosphere/NAMESPACE
Original file line number Diff line number Diff line change
@@ -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)
29 changes: 17 additions & 12 deletions modules/data.atmosphere/R/GEFS_helper_functions.R
Original file line number Diff line number Diff line change
@@ -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]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if you want to access these by index, for now I used the fullnames

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]
}
}
}
4 changes: 2 additions & 2 deletions modules/data.atmosphere/R/download.NARR_site.R
Original file line number Diff line number Diff line change
@@ -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