Skip to content

Commit fe5d5ed

Browse files
committed
tidy; #757
1 parent d076814 commit fe5d5ed

2 files changed

Lines changed: 15 additions & 14 deletions

File tree

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ Suggests:
6666
lwgeom,
6767
maps,
6868
mapdata,
69+
ncdfCF,
6970
ncdfgeom,
7071
ncmeta (>= 0.0.3),
7172
pbapply,
@@ -85,8 +86,7 @@ Suggests:
8586
tsibble,
8687
viridis,
8788
xts,
88-
zoo,
89-
ncdfCF
89+
zoo
9090
VignetteBuilder: knitr
9191
Encoding: UTF-8
9292
RoxygenNote: 7.3.3

R/ncdf.R

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ st_as_stars.ncdfgeom <- function(.x, ..., sf_geometry = NA) {
921921
stop("Data variable does not have X and/or Y axes")
922922

923923
crs = if (is.null(var$crs))
924-
"WGS84" # If no grid_mapping, then data is lat-long, assuming WGS84 datum here,
924+
"OGC:CRS84" # If no grid_mapping, then data is lat-long, assuming WGS84 datum here,
925925
else { # otherwise, tease the AUTHORITY out of the WKT2 string of the grid_mapping
926926
# This will often fail to identify an AUTHORITY because CF grid_mappings
927927
# are incomplete and a WKT2 thus has many "unknown"s.
@@ -936,19 +936,20 @@ st_as_stars.ncdfgeom <- function(.x, ..., sf_geometry = NA) {
936936

937937
raster = get_raster(dimensions = c(axes[[ axis_order[1] ]]$name, axes[[ axis_order[2] ]]$name))
938938
dimensions = lapply(axes, function(ax) {
939-
switch(ax$orientation,
939+
switch(ax$orientation,
940940
X = create_dimension(values = ax$coordinates, refsys = crs, is_raster = TRUE),
941941
Y = create_dimension(values = ax$coordinates, refsys = crs, is_raster = TRUE),
942-
T = {
943-
time = ax$time
944-
if (time$calendar$name %in% CF_calendar_regular)
945-
create_dimension(to = length(time$offsets), refsys = "POSIXct",
946-
values = time$as_timestamp(asPOSIX = TRUE))
947-
else
948-
create_dimension(to = length(time), refsys = "CFtime", values = time)
949-
},
950-
create_dimension(values = ax$coordinates))
951-
})
942+
T = create_dimension(to = length(time), refsys = "CFtime", values = ax$time),
943+
{
944+
v = ax$coordinates
945+
u = ax$attribute("units")
946+
if (!is.na(u))
947+
units(v) = try_as_units(u)
948+
create_dimension(values = v)
949+
}
950+
)
951+
}
952+
)
952953
create_dimensions(dimensions, raster)
953954
}
954955

0 commit comments

Comments
 (0)