From 7c2a323a1e319415f3cd0848bddec72fba38e179 Mon Sep 17 00:00:00 2001 From: Abhinav Pandey Date: Wed, 19 Jun 2024 19:14:46 +0530 Subject: [PATCH 1/3] Remove db.site.lat.lon function and replace usages with query.site to retrieve the lat and lon Signed-off-by: Abhinav Pandey --- base/db/R/query.site.R | 2 +- modules/data.atmosphere/NAMESPACE | 1 - modules/data.atmosphere/R/met.process.R | 26 +++---------------- .../data.atmosphere/man/db.site.lat.lon.Rd | 19 -------------- modules/data.land/inst/LoadPalEONsites.R | 6 ++--- 5 files changed, 7 insertions(+), 47 deletions(-) delete mode 100644 modules/data.atmosphere/man/db.site.lat.lon.Rd diff --git a/base/db/R/query.site.R b/base/db/R/query.site.R index 666a43b8a7d..2e456c404f0 100644 --- a/base/db/R/query.site.R +++ b/base/db/R/query.site.R @@ -1,4 +1,4 @@ -##' Given site_id, return site table +=##' Given site_id, return site table ##' ##' @param con : database connection ##' @param site.id The id of the site diff --git a/modules/data.atmosphere/NAMESPACE b/modules/data.atmosphere/NAMESPACE index ad08797ea15..4b5e9c9b34e 100644 --- a/modules/data.atmosphere/NAMESPACE +++ b/modules/data.atmosphere/NAMESPACE @@ -14,7 +14,6 @@ export(cfmet.downscale.time) export(check_met_input_file) export(closest_xy) export(cos_solar_zenith_angle) -export(db.site.lat.lon) export(debias.met) export(debias.met.regression) export(download.Ameriflux) diff --git a/modules/data.atmosphere/R/met.process.R b/modules/data.atmosphere/R/met.process.R index c2e253586d9..8e1408b3887 100644 --- a/modules/data.atmosphere/R/met.process.R +++ b/modules/data.atmosphere/R/met.process.R @@ -159,9 +159,10 @@ met.process <- function(site, input_met, start_date, end_date, model, } # setup site database number, lat, lon and name and copy for format.vars if new input + latlon <- PEcAn.DB::query.site(site$id, con = con)[c("lat", "lon")] new.site <- data.frame(id = as.numeric(site$id), - lat = db.site.lat.lon(site$id, con = con)$lat, - lon = db.site.lat.lon(site$id, con = con)$lon) + lat = latlon$lat, + lon = latlon$lon) str_ns <- paste0(new.site$id %/% 1e+09, "-", new.site$id %% 1e+09) if (is.null(format.vars$lat)) { @@ -401,27 +402,6 @@ met.process <- function(site, input_met, start_date, end_date, model, return(input_met) # Returns an updated $met entry for the settings object. } # met.process -################################################################################################################################# - -##' Look up lat/lon from siteid -##' -##' @export -##' @param site.id BeTY ID of site to look up -##' @param con database connection -##' @author Betsy Cowdery -db.site.lat.lon <- function(site.id, con) { - site <- PEcAn.DB::db.query(paste("SELECT id, ST_X(ST_CENTROID(geometry)) AS lon, ST_Y(ST_CENTROID(geometry)) AS lat FROM sites WHERE id =", - site.id), con) - if (nrow(site) == 0) { - PEcAn.logger::logger.error("Site not found") - return(NULL) - } - if (!(is.na(site$lat)) && !(is.na(site$lat))) { - return(list(lat = site$lat, lon = site$lon)) - } else { - PEcAn.logger::logger.severe("We should not be here!") - } -} # db.site.lat.lon ################################################################################################################################# diff --git a/modules/data.atmosphere/man/db.site.lat.lon.Rd b/modules/data.atmosphere/man/db.site.lat.lon.Rd deleted file mode 100644 index 9a2cfed78f9..00000000000 --- a/modules/data.atmosphere/man/db.site.lat.lon.Rd +++ /dev/null @@ -1,19 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/met.process.R -\name{db.site.lat.lon} -\alias{db.site.lat.lon} -\title{Look up lat/lon from siteid} -\usage{ -db.site.lat.lon(site.id, con) -} -\arguments{ -\item{site.id}{BeTY ID of site to look up} - -\item{con}{database connection} -} -\description{ -Look up lat/lon from siteid -} -\author{ -Betsy Cowdery -} diff --git a/modules/data.land/inst/LoadPalEONsites.R b/modules/data.land/inst/LoadPalEONsites.R index 9cb07162aab..3c010bc7ccc 100644 --- a/modules/data.land/inst/LoadPalEONsites.R +++ b/modules/data.land/inst/LoadPalEONsites.R @@ -164,10 +164,10 @@ for(i in seq_along(paleon.sitegroups)){ sitename <- db.query(paste0("SELECT sitename from sites where id =",site_id),con) str_ns <- paste0(site_id %/% 1e+09, "-", site_id %% 1e+09) outfile <- paste0("PalEONregional_CF_site_", str_ns) - + latlon <- PEcAn.DB::query.site(site$id, con = con)[c("lat", "lon")] site.info <- rbind(site.info,data.frame(id = site_id, - lat = db.site.lat.lon(site_id, con = con)$lat, - lon = db.site.lat.lon(site_id, con = con)$lon, + lat = latlon$lat, + lon = latlon$lon, str_ns = str_ns, outfile = outfile)) } From 36a5af9e929a304322cffcf6cdb2220d289e7d95 Mon Sep 17 00:00:00 2001 From: Abhinav Pandey Date: Wed, 19 Jun 2024 19:18:57 +0530 Subject: [PATCH 2/3] Remove redundant section Signed-off-by: Abhinav Pandey --- base/db/R/query.site.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/db/R/query.site.R b/base/db/R/query.site.R index 2e456c404f0..666a43b8a7d 100644 --- a/base/db/R/query.site.R +++ b/base/db/R/query.site.R @@ -1,4 +1,4 @@ -=##' Given site_id, return site table +##' Given site_id, return site table ##' ##' @param con : database connection ##' @param site.id The id of the site From 9b1b976999741d9631e94e585c4a0ead889cdefd Mon Sep 17 00:00:00 2001 From: Abhinav Pandey Date: Fri, 21 Jun 2024 00:15:10 +0530 Subject: [PATCH 3/3] Update NEWS.md to keep a record Signed-off-by: Abhinav Pandey --- modules/data.atmosphere/NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/data.atmosphere/NEWS.md b/modules/data.atmosphere/NEWS.md index dcfb553cb25..c9410bb86e8 100644 --- a/modules/data.atmosphere/NEWS.md +++ b/modules/data.atmosphere/NEWS.md @@ -24,6 +24,7 @@ ## Removed * Helper function `robustly` has moved to package PEcAn.utils [@meetagrawal, #3096] +* Helper function `db.site.lat.lon` has been removed. Users should use `PEcAn.DB::query.site(id, con)[c("lat", "lon")]` instead [@Sweetdevil144, #3308] # PEcAn.data.atmosphere 1.7.1