извлечение климатических данных из файла nc в R - PullRequest
0 голосов
/ 14 мая 2018

Я работаю над файлом .nc.Файл можно скачать file size: 35 M здесь .Я не так много раньше работал с nc или raster в R.
Я исследовал пакет 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:\STUDY\CMIP5_GCM_month\pr\rcp26\pr_Amon_bcc-csm1-1_rcp26_r1i1p1_200601-209912.nc 
names       : Precipitation 
z-value     : 2006-01-16 
zvar        : pr 

И я застрял в этом.Я понятия не имею, как действовать дальше.Я сталкивался с использованием оператора @, но не смог извлечь что-то значимое.

> print(rfile)

File D:\STUDY\CMIP5_GCM_month\pr\rcp26\pr_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 год.
Мне нужен список, содержащий среднее значениеосадки за каждые 10 лет от 2010 - 2020, 2021 - 2030 и т. д.Кто-нибудь может подсказать мне, как это сделать и с чего начать?

1 Ответ

0 голосов
/ 14 мая 2018

Вы можете вычислить 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" )
...