我一直在寻找一个诡计来解决我的问题,但我仍然无法解决它。我想将一个nedCDF文件导入R.像这样:
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.
然后我想提取降水数据,例如在一天的一个网格单元中提取:
n_prec <- ncvar_get(ncdata, 'prec')
print(n_prec[1, 1, 1, 1])
但我收到如下错误消息: n_prec [1,1,1,1]中的错误:维数错误
并且我没有得到它,因为数据集具有维度。但我可能误解了一些事情,因为我对R.很新。
我很高兴得到任何帮助。 曼努埃尔
答案 0 :(得分:1)
n_prec的维数为3而不是4.“z”维度只有1个选项/级别,因此当在沉降数组中读取时,R忽略它。
> 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