【问题标题】:Plotting netcdf file with levels in R在 R 中绘制带有级别的 netcdf 文件
【发布时间】:2018-05-12 07:46:16
【问题描述】:

我最近开始在 R 中使用 netcdf。示例数据在这里:

http://www.earthstat.org/data-download/ > 175 种作物的收获面积和产量 > 单个作物 > 大豆_HarvAreaYield2000_NetCDF

在这个文件夹中,有一个名为soybean_AreaYieldProduction.nc的netcdf文件

这就是我打开 netcdf 的方式

 library(ncdf4)

 dat <- nc_open("soybean_AreaYieldProduction.nc")
 print(soy)

1 variables (excluding dimension variables):
    float soybeanData[longitude,latitude,level,time]  
LayerDescriptions: struct(5).Data(:,:,1/2/3/4/5/6) to access data layer: 1=Harvested Area fraction, 2=Yield 3=Harvested Area data quality, 4=Yield data quality, 5=Harvested Area in hectares, 6= Production
        Units: Harvested Area Fraction(1)=percent of gridcell that was harvested, Yield(2)=metric tons per hectare, Harvested Area Hectares(5)=total hectares harvested per gridcell, Production(6)=Metric Tons
        DataQuality: In levels 3 and 4, a value of 1 = county; .75 = state; .5 = interpolated from within 2 degrees lat/long; .25 = country; 0 = missing.
4 dimensions:
        longitude  Size:4320
        units: longitude
        latitude  Size:2160
        units: latitude
        level  Size:6
        time  Size:1

我想绘制每个级别,但不知道如何提取每个级别的数据。

这就是我提取经纬度数据的方式:

lon <- ncvar_get(dat,"longitude") # extract long

lat <- ncvar_get(dat,"latitude") # extract lat

但是如何提取单个关卡?

level.1 <- ncvar_get(dat, ????) 

最终目标是可视化每个级别 我想使用以下命令进行可视化:

image(lon,lat, level)

【问题讨论】:

    标签: r raster netcdf netcdf4


    【解决方案1】:

    使用raster 包可能是最简单的:

    library(raster)
    r1 <- raster("soybean_AreaYieldProduction.nc", level=1)
    r2 <- raster("soybean_AreaYieldProduction.nc", level=2)
    
    plot(r1)
    image(r1) 
    s <- stack(r1, r2)
    plot(s)
    

    其他绘图方法

    spplot(s)
    
    library(rasterVis)
    levelplot(r1) 
    levelplot(s)
    

    并查看 CRAN 上的其他映射包

    【讨论】:

    • 是否有自动从 ncdf 文件堆叠或关卡的功能?
    猜你喜欢
    • 2016-10-28
    • 2018-07-05
    • 2020-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-29
    • 1970-01-01
    • 2015-11-17
    相关资源
    最近更新 更多