代码之家  ›  专栏  ›  技术社区  ›  Recology

使用R中的stars包子集ncdf文件

  •  0
  • Recology  · 技术社区  · 2 年前

    我正试图从哥白尼中提取一个气候变量。

    devtools::install_github("r-spatial/stars")
    library(stars)
    
    library(ncdf4)
    library(RNetCDF)
    
    pp <- read_ncdf("~/climate_data/pp_ens_mean_0.1deg_reg_v25.0e.nc", proxy = TRUE)
    
    > print(pp)
    netcdf source stars proxy object from:
    [1] "[...]/pp_ens_mean_0.1deg_reg_v25.0e.nc"
    
    Available nc variables:
    pp
    
    dimension(s):
              from    to         offset  delta  refsys point values x/y
    longitude    1   705       -25.0001    0.1  WGS 84    NA   NULL [x]
    latitude     1   465        24.9999    0.1  WGS 84    NA   NULL [y]
    time         1 26298 1950-01-01 UTC 1 days POSIXct    NA   NULL      
    

    这就是我作为代理人得到的。

    我想把经度在10°E到25°E之间,纬度在55°N到70°N之间。 我试过了,但不起作用,我真的不明白为什么。

    pp <- read_ncdf(pp, 
                    var = pp, 
                    ncsub = cbind(start = c(10, 55, 1), 
                                   count = c(25, 70, 26298)))
    

    有什么想法吗?非常感谢你的宝贵帮助。

    0 回复  |  直到 2 年前
        1
  •  0
  •   Recology    2 年前

    感谢@Chris回答:

    devtools::install_github("r-spatial/stars")
    library(stars)
    
    library(ncdf4)
    library(RNetCDF)
    
    pp <- read_ncdf("C:/Users/Dell/Desktop/~/climate_data/pp_ens_mean_0.1deg_reg_v25.0e.nc", proxy = TRUE)
    
    print(pp)
    
    bb = st_bbox(c(xmin=10.00, ymin=55.00, 
                   xmax=25.00, ymax=70.00),
                   crs = st_crs(4326))
    
    pp_sub = pp[bb]
    
    > print(pp_sub)
    netcdf source stars proxy object from:
    [1] "[...]/pp_ens_mean_0.1deg_reg_v25.0e.nc"
    
    Available nc variables:
    pp
    
    dimension(s):
              from    to         offset  delta  refsys point values x/y
    longitude  351   501       -25.0001    0.1  WGS 84    NA   NULL [x]
    latitude   301   451        24.9999    0.1  WGS 84    NA   NULL [y]
    time         1 26298 1950-01-01 UTC 1 days POSIXct    NA   NULL