diff --git a/R/aggregate.R b/R/aggregate.R index dca97504..3cb1a191 100644 --- a/R/aggregate.R +++ b/R/aggregate.R @@ -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 diff --git a/R/dimensions.R b/R/dimensions.R index 933b240f..708eaec0 100644 --- a/R/dimensions.R +++ b/R/dimensions.R @@ -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)) { @@ -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]]