r语言 - 从 nc 文件中提取气候数据



我正在处理一个.nc文件。该文件可以file size: 35 M下载 这里.我以前没有在 R.I
中与ncraster合作过raster并根据其他问题的不同堆栈答案中的建议探索ncdf4包。

library(raster)
library(ncdf4)
file <- # location to  file you downloaded from the link above
rfile <- raster(file)
# this is what I got
> rfile
class       : RasterLayer 
band        : 1  (of  1128  bands)
dimensions  : 64, 128, 8192  (nrow, ncol, ncell)
resolution  : 2.8125, 2.789327  (x, y)
extent      : -1.40625, 358.5938, -89.25846, 89.25846  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 
data source : D:STUDYCMIP5_GCM_monthprrcp26pr_Amon_bcc-csm1-1_rcp26_r1i1p1_200601-209912.nc 
names       : Precipitation 
z-value     : 2006-01-16 
zvar        : pr 

我被困在这一点上。我不知道如何进一步进行。我遇到了@运算符的使用,但我无法提取有意义的东西。

> print(rfile)
File D:STUDYCMIP5_GCM_monthprrcp26pr_Amon_bcc-csm1-1_rcp26_r1i1p1_200601-209912.nc (NC_FORMAT_CLASSIC):
4 variables (excluding dimension variables):
double time_bnds[bnds,time]   
double lat_bnds[bnds,lat]   
double lon_bnds[bnds,lon]   
float pr[lon,lat,time]   
standard_name: precipitation_flux
long_name: Precipitation
comment: at surface; includes both liquid and solid phases from all types of clouds (both large-scale and convective)
units: kg m-2 s-1
original_name: PRECC+PRECL
cell_methods: time: mean (interval: 20 mintues)
cell_measures: area: areacella
missing_value: 1.00000002004088e+20
_FillValue: 1.00000002004088e+20
associated_files: baseURL: http://cmip-pcmdi.llnl.gov/CMIP5/dataLocation gridspecFile: gridspec_atmos_fx_bcc-csm1-1_rcp26_r0i0p0.nc areacella: areacella_fx_bcc-csm1-1_rcp26_r0i0p0.nc
4 dimensions:
time  Size:1128   *** is unlimited ***
bounds: time_bnds
units: days since 2006-01-01
calendar: noleap
axis: T
long_name: time
standard_name: time
lat  Size:64
bounds: lat_bnds
units: degrees_north
axis: Y
long_name: latitude
standard_name: latitude
lon  Size:128
bounds: lon_bnds
units: degrees_east
axis: X
long_name: longitude
standard_name: longitude
bnds  Size:2
27 global attributes:
institution: Beijing Climate Center(BCC),China Meteorological Administration,China
institute_id: BCC
experiment_id: rcp26
source: bcc-csm1-1:atmosphere:  BCC_AGCM2.1 (T42L26); land: BCC_AVIM1.0;ocean: MOM4_L40 (tripolar, 1 lon x (1-1/3) lat, L40);sea ice: SIS (tripolar,1 lon x (1-1/3) lat)
model_id: bcc-csm1-1
forcing: Nat Ant GHG SD Oz Sl SS Ds BC OC
parent_experiment_id: historical
parent_experiment_rip: r1i1p1
branch_time: 2006
contact: Dr. Tongwen Wu (twwu@cma.gov.cn)
history: Output from monthly mean data 2011-06-27T08:46:28Z CMOR rewrote data to comply with CF standards and CMIP5 requirements.
comment: Future projection (2006-2099) forced with prescribed concentration scenario of RCP2.6. The carbon cycle in land and ocean component model is considered, but the time-evolution of CO2 concentration in atmospheric component is prescribed.
initialization_method: 1
physics_version: 1
tracking_id: 93654a27-6561-4263-9ee4-6411ab913c62
product: output
experiment: RCP2.6
frequency: mon
creation_date: 2011-06-27T08:46:28Z
Conventions: CF-1.4
project_id: CMIP5
table_id: Table Amon (11 April 2011) 1cfdc7322cf2f4a32614826fab42c1ab
title: bcc-csm1-1 model output prepared for CMIP5 RCP2.6
parent_experiment: historical
modeling_realm: atmos
realization: 1
cmor_version: 2.5.6

输入文件是 2006 年至 2100 年的月降水量数据。
我需要一份列表,其中包含从2010 - 20202021 - 2030等每隔 10 年间隔的降水量平均值。有人可以指导我如何做到这一点以及从哪里开始吗?

您可以计算降水annual sums,然后计算every 10 years的平均值:

library(raster)
p <- stack(file.choose())
# create annual sums
id <- rep(1:1128, each = 12)
p_annual <- stackApply(p,indices = id, fun="sum" )
# use only 2010 to 2100 years
p_annual <- p_annual[[5:94]]
# compute decadal averages
id2 <- rep(1:90,each = 10)
p_decade <- stackApply(p_annual,indices = id2, fun="mean" )

最新更新