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

Scan metadata updates #357

Merged
merged 19 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
33 changes: 20 additions & 13 deletions R/fetchSCAN.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ fetchSCAN <- function(site.code = NULL, year = NULL, report = 'SCAN', timeseries

# add metadata from cached table in soilDB
m <- SCAN_site_metadata(site.code)

# why do this?
brownag marked this conversation as resolved.
Show resolved Hide resolved
site.code <- m$Site

# all possible combinations of site codes and year | single report and timeseries type
Expand Down Expand Up @@ -161,25 +163,30 @@ fetchSCAN <- function(site.code = NULL, year = NULL, report = 'SCAN', timeseries

site.i <- as.character(i$sitenum)
year.i <- as.character(i$year)
m.i <- m[which(m$Site == site.i), ]

# if no data, return an empty skeleton data.frame
if (is.null(d)) {
res <- data.frame(Site = integer(0),
Date = as.Date(numeric(0),
origin = "1970-01-01"),
Time = character(0),
water_year = numeric(0),
water_day = integer(0),
value = numeric(0),
depth = numeric(0),
sensor.id = integer(0),
row.names = NULL,
stringsAsFactors = FALSE)
res <- data.frame(
Site = integer(0),
Date = as.Date(numeric(0),
origin = "1970-01-01"),
Time = character(0),
water_year = numeric(0),
water_day = integer(0),
value = numeric(0),
depth = numeric(0),
sensor.id = integer(0),
datetime = as.POSIXct(character(0)),
row.names = NULL,
stringsAsFactors = FALSE
)
} else {
res <- .formatSCAN_soil_sensor_suites(
d,
code = sensor.i,
meta = m,
hourlyFlag = timeseries == 'Hourly'
meta = m.i,
hourlyFlag = (timeseries == 'Hourly')
)
}

Expand Down
11 changes: 10 additions & 1 deletion tests/testthat/test-fetchSCAN.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ test_that("fetchSCAN() works", {
# standard request
expect_true(inherits(x, 'list'))

# completely empty request for valid site
# completely empty request for valid site (bogus year)
y <<- fetchSCAN(site.code = 2072, year = 1800)

# multiple sites / years
z <<- fetchSCAN(site.code = c(356, 2072), year = c(2015, 2016))

})

test_that("fetchSCAN() returns the right kind of data", {
Expand All @@ -41,6 +44,12 @@ test_that("fetchSCAN() returns the right kind of data", {
expect_true(inherits(x$SMS, 'data.frame'))
expect_true(ncol(x$SMS) == 9)

# empty results should have the same data type and dimensions
expect_true(inherits(y, 'list'))
expect_equal(nrow(y$metadata), 1)

expect_true(inherits(y$STO, 'data.frame'))
expect_true(ncol(y$STO) == 9)
expect_true(inherits(y$SMS, 'data.frame'))
expect_true(ncol(y$SMS) == 9)
})
Loading