2

我正在尝试复制以下问题的答案,但在 R Terra area 命令上出现错误:

使用立体极坐标投影从卫星数据估计网格单元面积

我正在运行的确切代码如下:

url1 <- "https://polarwatch.noaa.gov/erddap/griddap/nsidcCDRiceSQnhmday.nc?seaice_conc_monthly_cdr[(2019-12-16T00:00:00Z):1:(2019-12-16T00:00:00Z)][(5837500.0):1:(-5337500.0)][(-3837500.0):1:(3737500.0)]"
f <- 'nsidcCDRiceSQnhmday_935c_47bd_a147.nc'
download.file(url1, destfile=f, mode="wb")
library(terra)
r <- rast(f)
crs(r) <- "epsg:3976"
res(r)
a <- area(r, correct=TRUE, mask=TRUE, sum=FALSE)

打印 r 产量

class       : SpatRaster
dimensions  : 448, 304, 1  (nrow, ncol, nlyr)
resolution  : 25000, 25000  (x, y)
extent      : -3850000, 3750000, -5350000, 5850000  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=stere +lat_0=-90 +lat_ts=-70 +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 
+units=m +no_defs 
source      : nsidcCDRiceSQnhmday_935c_47bd_a147.nc 
varname     : seaice_conc_monthly_cdr (NOAA/NSIDC Climate Data Record of Passive 
Microwave Monthly Northern Hemisphere Sea Ice Concentration) 
name        : seaice_conc_monthly_cdr 
unit        :                       1 
time        : 2019-12-16 

我在使用 area() 命令时收到以下错误:

Error: [area] area(x, sum=FALSE) will be removed. Use "cellSize(x)"

我已经在我的默认 R 实例上尝试过这个,并且还从头开始设置了一个干净的实例。我在两次安装中都遇到了同样的错误。两个系统都是 macOS。如果我尝试将 area 命令更改为 cellSize 命令,R 将完全退出并重新启动。

这是每个设置的 sessionInfo():

系统 2:全新安装 MacOS Big Sur

R version 4.1.0 (2021-05-18)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 11.2.3

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] raster_3.4-12 sp_1.4-5      Rcpp_1.0.7    ncdf4_1.17    terra_1.3-13 

loaded via a namespace (and not attached):
 [1] lattice_0.20-44   codetools_0.2-18  digest_0.6.27     grid_4.1.0       
 [5] evaluate_0.14     rlang_0.4.11      rmarkdown_2.9     tools_4.1.0      
 [9] xfun_0.24         yaml_2.2.1        compiler_4.1.0    htmltools_0.5.1.1
[13] knitr_1.33

系统一:macOS Catalina

R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.7

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base    

other attached packages:
[1] terra_1.2-10   raster_3.4-5   sp_1.4-4       downloader_0.4 XML_3.99-0.5  
[6] RCurl_1.98-1.2

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5        rerddap_0.7.4     pillar_1.4.7      compiler_4.0.2  
 [5] bitops_1.0-6      tools_4.0.2       ncdf4_1.17        digest_0.6.27    
 [9] lattice_0.20-41   jsonlite_1.7.1    evaluate_0.14     lifecycle_0.2.0  
[13] tibble_3.0.4      gtable_0.3.0      pkgconfig_2.0.3   rlang_0.4.8      
[17] rstudioapi_0.13   crul_1.1.0        curl_4.3          yaml_2.2.1      
[21] xfun_0.19         dplyr_1.0.2       httr_1.4.2        knitr_1.30      
[25] xml2_1.3.2        generics_0.1.0    vctrs_0.3.5       rappdirs_0.3.3  
[29] grid_4.0.2        tidyselect_1.1.0  glue_1.4.2        httpcode_0.3.0  
[33] data.table_1.13.2 R6_2.5.0          rmarkdown_2.5     purrr_0.3.4      
[37] ggplot2_3.3.2     hoardr_0.5.2      magrittr_1.5      codetools_0.2-16
[41] scales_1.1.1      ellipsis_0.3.1    htmltools_0.5.0   colorspace_2.0-0
[45] tinytex_0.27      munsell_0.5.0     crayon_1.3.4    
4

1 回答 1

3

正如消息所说,该area方法被替换为cellSize(以避免名称冲突spatstat)。

我已经更新了原始问题的答案以反映当前版本的 terra。

于 2021-07-11T04:52:35.883 回答