-
Notifications
You must be signed in to change notification settings - Fork 241
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
fix met2CF.csv tests #202
Comments
The file modules/data.atmosphere/inst/extdata/urbana_daily_test.nc has the wrong start_date
This issue is stale because it has been open 365 days with no activity. |
Not only is there code commented out in met2CF.csv.R, but there's not actually any valid |
It's been too long of this being open. Maybe we can add more test cases like : library(ncdf4)
# Mock data
in.path <- "modules/data.atmosphere/tests/testthat/data"
in.file <- "test.met2CF.csv.csv"
outfolder <- tempdir()
lat <- 42 + 47 / 60 + 30 / 6000
lon <- 76 + 7 / 60 + 20 / 6000
# Define start_date and end_date
start_date <- as.Date("2024-01-01")
end_date <- as.Date("2024-12-31")
test_that("met2CF.csv handles inputs correctly", {
# Test that function runs without errors
expect_silent(PEcAn.data.atmosphere::met2CF.csv(in.path, in.file, outfolder, start_date, end_date, format, lat, lon))
# Test that output directory contains the expected file
expect_true(file.exists(file.path(outfolder, paste0(gsub(".csv", "", in.file), ".nc"))))
# Test that the output file is a valid netCDF file
nc_file <- nc_open(file.path(outfolder, paste0(gsub(".csv", "", in.file), ".nc")))
expect_true(!is.null(nc_file))
nc_close(nc_file)
})
Diving more into this test file for now. |
Take a look at this article on "test hygiene" and consider using |
Current test file : https://github.com/Sweetdevil144/pecan/blob/develop/modules/data.atmosphere/tests/testthat/test.met2CF.csv.R I think the format required has been changed since last times. Can anyone suggest approach for this error ? > test_file('modules/data.atmosphere/tests/testthat/test.met2CF.csv.R')
══ Testing test.met2CF.csv.R ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
[ FAIL 0 | WARN 0 | SKIP 0 | PASS 0 ]2024-05-07 15:46:45.777093 ERROR [test.met2CF.csv.R#39: PEcAn.data.atmosphere::met2CF.csv] :
datetime column is not specified in format
[ FAIL 1 | WARN 0 | SKIP 0 | PASS 0 ]
── Error (test.met2CF.csv.R:39:8): met2CF.csv function works correctly ─────────
Error in `PEcAn.data.atmosphere::met2CF.csv(in.path = in.path, in.prefix = in.file,
outfolder = outfolder, format = format, lat = lat, lon = lon,
start_date = start_date, end_date = end_date)`: object 'alldatetime' not found
Backtrace:
▆
1. └─PEcAn.data.atmosphere::met2CF.csv(...) at test.met2CF.csv.R:39:8
2. └─lubridate::year(alldatetime)
[ FAIL 1 | WARN 0 | SKIP 0 | PASS 0 ] |
@Sweetdevil144 I recommend running the function line-by-line to figure out the source of the error. Also, I agree that the format in the test appears out-of-date. As the function itself says, the format comes from query.format.vars so I'd check what variables that function returns, as well as the |
Thanks for suggestions @mdietze . That helped. I've been trying to get an estimate of what start_date <- "2000-01-01"
end_date <- "2000-12-31"
# OR
start_date <- as.Date("2004-01-01")
end_date <- as.Date("2004-12-31") However, these specific timestamps give following errors :
I also tried printing the print(paste("Date range in data:", min(alldatetime), "to", max(alldatetime))) Any Suggestions? |
One thing I can't get my head around is as follow:
if (datetime_units == "") {
datetime_units <- "%Y%m%d%H%M" #assume ISO convention
} Hence we get following values of alldatetime is = NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
NA NA NA NA NA
where datetime_units = %Y%m%d%H%M
Error in `PEcAn.logger::logger.severe("\n\nData does not contain output after start_date or before end_date.")`:
Data does not contain output after start_date or before end_date. Is the format specified in |
The default format has to stay ISO. If you're passing in data with a different time format, which the function allows, and are getting an error that suggests that either the format information is being passed in wrong or there's a bug in how that format information is being read and applied. |
Okay. So the issue was caused due to an improper format. Seems I made some blunders while setting formats. Suites Prepared !! |
Commented out test in
data.atmosphere/tests/testthat/test.met2CF.csv.R
These should be revised, extended, and fixed
The text was updated successfully, but these errors were encountered: