将 4 维 netCDF 数据导入 R
我一直在寻找解决我的问题的方法,但我仍然无法解决它.我想将 nedCDF 文件导入 R.像这样:
I've been searching quit a wile to solve my problem, but I still couldn't solve it. I want to Import a nedCDF file into R. Like this:
ncdata <- nc_open("prec_daily_2005-2005.nc")
print(ncdata)
我得到以下内容
File prec_daily_2005-2005.nc (NC_FORMAT_CLASSIC):
1 variables (excluding dimension variables):
float prec[longitude,latitude,z,time]
source: Reanalysis daily precipitation, statistically corrected for number of raindays, monthly amounts and diurnal cycle at 1.0deg; interpolated to 0.1deg; available GHCN/GSOD daily station data assimilated into gridded data
name: prec
title: Daily bias corrected precipitation
date: 01/01/05
time: 00:00
long_name: Precipitation
units: kg m-2 s-1
missing_value: 2.00000004008175e+20
_FillValue: 2.00000004008175e+20
valid_min: 0
valid_max: 0.0045476695522666
4 dimensions:
longitude Size:800
units: degrees_east
point_spacing: even
latitude Size:300
units: degrees_north
point_spacing: even
z Size:1
units: level
positive: up
time Size:365 *** is unlimited ***
units: days since 2005-01-01 00:00:00
time_origin: 01-JAN-2005:00:00:00
6 global attributes:
history: Thu May 22 10:21:12 EDT 2014: created by JS using convert2alma.sh
title: Princeton University Hydroclimatology Group Bias Corrected African (1979-2005) Meteorological Forcing Dataset V1.0
institution: Princeton University
contact: Justin Sheffield (justin@princeton.edu)
source: Forcings are a hybrid of NCEP/NCAR reanalysis and observations
comment: This dataset is described in Chaney and Sheffield (2012) (Chaney, N., and J. Sheffield, 2012: High Resolution Gridded Daily Meteorological Data for Africa: Dataset Development and Analysis of Trends in Means and Extremes, J. Climate, to be submitted) and is related to the original global version reported in Sheffield et al., J. Climate (2006). Updates/changes include: i) African continent domain; ii) extension to 2005; iii) assimilation of available GHCN/GSOD daily station observations; iv) step change detection and correction for observational datasets; v) improved sampling procedure for correction of rain day statistics; vi) use of latest versions of CRU, SRB and TRMM products; vii) improved consistency between specific and relative humidity and air temperature. See Sheffield et al., J. Climate (2006) for details of the observations used and the bias correction and downscaling methodology.
然后我想提取降水数据,例如某一天的一个网格单元:
and then I want to extract precipitation data, for example at one grid cell at one day:
n_prec <- ncvar_get(ncdata, 'prec')
print(n_prec[1, 1, 1, 1])
但我收到如下错误消息:n_prec[1, 1, 1, 1] 中的错误:维数错误
but I get en error message like: error in n_prec[1, 1, 1, 1] : wrong number of dimensions
我不明白,因为数据集有维度.但我可能误解了一些东西,因为我对 R 很陌生.
and I don't get it because the dataset has for dimensions. But I maybe misunderstood something, as I'm pretty new to R.
我很高兴得到任何帮助.曼努埃尔
I'm glad for any help. Manuel
n_prec 的维度数是 3 而不是 4.'z' 维度只有 1 个选项/级别,因此 R 在读取 precip 数组时会忽略它.
The number of dimensions for n_prec is 3 instead of 4. The 'z' dimension only has 1 option/level so R ignores it when reading in the precip array.
> library(ncdf4)
> ncdata <- nc_open("prec_daily_2005-2005.nc")
> n_prec <- ncvar_get(ncdata, 'prec')
> dim(n_prec)
[1] 800 300 365
> n_prec[1,1,1]
[1] NA
> n_prec[400,100,6]
[1] 1.13913e-05