【问题标题】:Import 4 dimensional netCDF data into R将 4 维 netCDF 数据导入 R
【发布时间】:2016-09-01 03:05:08
【问题描述】:

我一直在寻找解决问题的方法,但仍然无法解决。我想将 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 很陌生。

我很高兴得到任何帮助。 曼努埃尔

【问题讨论】:

  • 您没有提及(除其他外)您正在使用哪个版本的 R,您安装了哪个 netcdf(和版本),您遵循了哪些说明。此外,我尝试安装 RnetCDF 并出现错误 - 你检查是否有任何弹出?你从哪里得到的数据文件。你检查NASA's install instructions了吗?他们看起来很清楚,并且也参考了OSU的说明。
  • 请提供一个可重现的例子
  • 我使用的是 R 版本 3.3.0 (2016-05-03)。数据来自普林斯顿大学:hydrology.princeton.edu/getdata.php?dataid=6。这里是数据文件的保管箱链接:dropbox.com/sh/cf9y591hmlga69r/AAA8qnL0dM6EAwePehiXyA8Va?dl=0@jcoppens:感谢您的链接,还没有看到那个页面,我会按照这个说明再试一次。但我仍然不明白,为什么它不像我尝试的那样工作。

标签: r netcdf


【解决方案1】:

n_prec 的维数是 3 而不是 4。“z”维只有 1 个选项/级别,因此 R 在读取 precip 数组时会忽略它。

> 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

【讨论】:

    猜你喜欢
    • 2020-10-04
    • 1970-01-01
    • 1970-01-01
    • 2013-05-02
    • 2012-12-11
    • 2017-01-03
    • 2015-05-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多