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 db.site.lat.lon function and replace all usages with query.site #3308

Merged
merged 3 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion modules/data.atmosphere/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions modules/data.atmosphere/NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 3 additions & 23 deletions modules/data.atmosphere/R/met.process.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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

#################################################################################################################################

Expand Down
19 changes: 0 additions & 19 deletions modules/data.atmosphere/man/db.site.lat.lon.Rd

This file was deleted.

6 changes: 3 additions & 3 deletions modules/data.land/inst/LoadPalEONsites.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
Loading