Skip to content

Commit

Permalink
Fixing some errors
Browse files Browse the repository at this point in the history
  • Loading branch information
pvanlaake committed Oct 17, 2024
1 parent 8c69a1a commit 16635f7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions R/aggregate.R
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,14 @@ aggregate.stars = function(x, by, FUN, ..., drop = FALSE, join = st_intersects,
# reconstruct dimensions table:
if (!is.null(values) && methods::is(values, "CFtime")) {
d[[1]] = create_dimension(refsys = "CFtime", values = new_time)
names(d)[1] <- "time"
} else {
d[[1]] = create_dimension(values = by)
}
names(d)[1] = if (###is.function(by) || FIXME: 'by' can also apply to sf or sfc
inherits(values, c("POSIXct", "Date", "CFtime")))
names(d)[1] = if (is.function(by) || inherits(by, c("POSIXct", "Date", "function")))
"time"
else
geom
}
if (drop_y)
d = d[-2] # y

Expand Down
9 changes: 6 additions & 3 deletions R/dimensions.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,10 @@ st_set_dimensions = function(.x, which, values = NULL, point = NULL, names = NUL
}
if (is.null(values))
d[[which]]["values"] = list(NULL) # avoid removing element values
else if (methods::is(values, "CFtime"))
d[[which]]["values"] = values
else
else if (methods::is(values, "CFtime")) {
d[[which]]$values <- values
d[[which]]$refsys <- "CFtime"
} else
d[[which]] = create_dimension(values = values, point = point %||% d[[which]]$point, ...)
r = attr(d, "raster")
if (isTRUE(r$curvilinear)) {
Expand Down Expand Up @@ -494,6 +495,8 @@ parse_netcdf_meta = function(pr, name) {
u = get_val(paste0(v, "#units"), meta)
if (!is.na(u)) {
cal = get_val(paste0(v, "#calendar"), meta)
if (is.null(cal) || is.na(cal))
cal = "standard"
time = try(CFtime::CFtime(u, cal), silent = TRUE)
if (methods::is(time, "CFtime"))
pr$dim_extra[[v]] = time + pr$dim_extra[[v]]
Expand Down

0 comments on commit 16635f7

Please sign in to comment.