【发布时间】:2021-06-21 14:40:57
【问题描述】:
我正在使用 R 中的 stars 包对 netcdf 栅格执行时间聚合。通常对象具有 (X, Y, Time) 维度,并且在进行时间平均后,得到一个维度排序为 (Time, X , Y)。如何将维度的顺序改回原来的顺序(X、Y、T)?
我一直在搜索包 vignettes 和可能的函数示例以查找方法,但没有任何运气。我觉得我可能遗漏了一些简单而明显的东西......
这是一个代表:
library(stars)
#> Loading required package: abind
#> Warning: package 'abind' was built under R version 4.0.3
#> Loading required package: sf
#> Warning: package 'sf' was built under R version 4.0.4
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
tif = system.file("tif/L7_ETMs.tif", package = "stars")
x = read_stars(c(tif, tif, tif), along = "band")
x
#> stars object with 3 dimensions and 1 attribute
#> attribute(s), summary of first 1e+05 cells:
#> L7_ETMs.tif
#> Min. : 47.00
#> 1st Qu.: 65.00
#> Median : 76.00
#> Mean : 77.34
#> 3rd Qu.: 87.00
#> Max. :255.00
#> dimension(s):
#> from to offset delta refsys point values x/y
#> x 1 349 288776 28.5 UTM Zone 25, Southern Hem... FALSE NULL [x]
#> y 1 352 9120761 -28.5 UTM Zone 25, Southern Hem... FALSE NULL [y]
#> band 1 18 NA NA NA NA NULL
time = as.Date("2021-03-24") + 1:18
x = st_set_dimensions(x, "band", values = time)
y = aggregate(x, by = "3 days", "mean")
y
#> stars object with 3 dimensions and 1 attribute
#> attribute(s):
#> L7_ETMs.tif
#> Min. : 5.00
#> 1st Qu.: 56.67
#> Median : 71.67
#> Mean : 68.91
#> 3rd Qu.: 84.00
#> Max. :255.00
#> dimension(s):
#> from to offset delta refsys point values x/y
#> time 1 6 2021-03-25 3 days Date NA NULL
#> x 1 349 288776 28.5 UTM Zone 25, Southern Hem... FALSE NULL [x]
#> y 1 352 9120761 -28.5 UTM Zone 25, Southern Hem... FALSE NULL [y]
由reprex package (v0.3.0) 于 2021 年 3 月 24 日创建
【问题讨论】: