Commit 7d98a345 authored by Dan Baston's avatar Dan Baston

Make wsim_merge support ID-based data

parent bd13b395
......@@ -383,6 +383,40 @@ test_that("wsim_merge fails if input datasets are not congruent", {
file.remove(input_2)
})
test_that("wsim_merge works with ID-based data", {
input_1 <- tempfile(fileext='.nc')
input_2 <- tempfile(fileext='.nc')
output <- tempfile(fileext='.nc')
ids <- 5:16
wsim.io::write_vars_to_cdf(list(a=runif(12)), ids=ids, filename=input_1)
wsim.io::write_vars_to_cdf(list(b=runif(12)), ids=ids, filename=input_2)
return_code <- system2('./wsim_merge.R', args=c(
'--input', input_1,
'--input', input_2,
'--output', output
))
expect_equal(0, return_code)
# Different extent
wsim.io::write_vars_to_cdf(list(a=runif(12)), ids=ids, filename=input_1)
wsim.io::write_vars_to_cdf(list(b=runif(12)), ids=(1+ids), filename=input_2)
return_code <- system2('./wsim_merge.R', args=c(
'--input', input_1,
'--input', input_2,
'--output', output
))
expect_equal(1, return_code)
file.remove(input_1)
file.remove(input_2)
})
test_that("wsim_integrate doesn't propagage nonstandard _FillValue values", {
input <- paste0(tempfile(), '.nc')
output <- paste0(tempfile(), '.nc')
......
......@@ -31,6 +31,7 @@ main <- function(raw_args) {
combined <- list(
attrs= list(),
extent= NULL,
ids= NULL,
data= list()
)
......@@ -40,12 +41,13 @@ main <- function(raw_args) {
if (length(combined$data) == 0) {
v <- wsim.io::read_vars(input)
combined$extent <- v$extent
combined$ids <- v$ids
} else {
v <- wsim.io::read_vars(input,
expect.extent=combined$extent,
expect.ids=combined$ids,
expect.dims=dim(combined$data[[1]]))
}
for (var in names(v$data)) {
if (var %in% names(combined$data)) {
......@@ -68,6 +70,7 @@ main <- function(raw_args) {
wsim.io::write_vars_to_cdf(combined$data,
args$output,
extent=combined$extent,
ids=combined$ids,
attrs=attrs)
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment