zhuangwei的个人博客分享 http://blog.sciencenet.cn/u/zhuangwei

博文

USE R: netCDF格式的通量数据的读取

已有 3888 次阅读 2018-8-7 16:11 |个人分类:通量数据分析|系统分类:科研笔记| 通量, NetCDF, 数据读取

       通量(涡度相关)数据,是分析生态系统水碳过程的常用数据。在Fluxnet可以免费申请到全球公开的通量数据。这些通量数据的格式多数是NetCDF。NetCDF可以储存观测站点和各观测项的元数据,在时间序列数据的存储和传播中使用广泛。这里介绍一下R里面的一个命令,可以方便读取Fluxnet的NetCDF格式的通量数据。

     这里用到的读取命令readFLUXNETNcdf来自Jannis v. Buttlar开发的ncdf.tools包。这里用的数据DalyUncleared_2017_L3nc,是澳洲通量网的DalyRiverUncleared站点2017年的Level 3数据。感谢Jason Beringer公开了这一数据。无需注册即可下载,网址:

http://data.ozflux.org.au/portal/pub/viewColDetails.jspx?collection.id=1882715&collection.owner.id=304&viewType=anonymous

 数据中的各个变量的意义和单位在网址提供的Metadata中可以查到。


以下为读取通量数据的代码,供参考。

# install.packages("RNetCDF")
# install.packages("cli","pillar")
# install.packages('ncdf.tools', 'ggplot2')
# if not installed, install please
library(ncdf.tools)
library(ggplot2)

setwd("your working directory") # rewriten as your working directory
# read nc data
DaU2017 <- readFLUXNETNcdf(##title<< read data from FLUXNET NetCDF file.
               path = getwd()  ##<< character string: path to the input file(s)
               , sites = 'DalyUncleared_2017_L3'        ##<< character string: ids of the sites to extract
               , pars = 'all'  ##<< character string: names of the variables to extract
               , time.ends = c(as.POSIXlt('2017-01-01 00:00:00'), as.POSIXlt('2017-12-31 23:30:00'))     ##<< POSIXct object: start and end date of the period to extract.
               , dim.borders = list(1)##<< list: indices for other dimensions
              )
dim(DaU2017)
#  1  251 17520  1
rownames(DaU2017[1,,,1]) # check the names of the variables
# it will show names of 251 variables.
# For the meanings and units of the variables, check the meta file in ozflux website.  

tmp = data.frame(matrix(nrow = 17520, ncol = 251))
for (i in 1:251)
    {tmp[,i] =  as.numeric(DaU2017[1,i,,1])
    }
names(tmp) <- rownames(DaU2017[1,,,1])

DaU_2017 <- tmp
DaU_2017$DT <-  seq(as.POSIXct("2017-01-01 00:00:00", format = "%Y-%m-%d %H:%M:%S"),
                    length.out=17520, by ='30 mins')
DaU_2017$DT <- as.Date(DaU_2017$DT)
# OK! Timeseries of flux data have been input.

rownames(DaU2017[1,,,1])
# view the names of variables
#   [1] "AGC_7500"              "AGC_7500_QCFlag"       "Ah"                    "Ah_7500_Av"           
#   [5] "Ah_7500_Av_QCFlag"     "Ah_7500_Sd"            "Ah_7500_Sd_QCFlag"     "Ah_HMP_21m"           
#   [9] "Ah_HMP_21m_QCFlag"     "Ah_HMP_2m"             "Ah_HMP_2m_QCFlag"      "Ah_QCFlag"            
#  [13] "AhAh"                  "AhAh_QCFlag"           "Cc"                    "Cc_7500_Av"           
#  [17] "Cc_7500_Av_QCFlag"     "Cc_7500_Sd"            "Cc_7500_Sd_QCFlag"     "Cc_QCFlag"            
#  [21] "CcCc"                  "CcCc_QCFlag"           "co2_wpl_Fe"            "co2_wpl_Fe_QCFlag"    
#  [25] "co2_wpl_Fh"            "co2_wpl_Fh_QCFlag"     "Cpd"                   "Cpd_QCFlag"           
#  [29] "Cpm"                   "Cpm_QCFlag"            "Cpw"                   "Cpw_QCFlag"           
#  [33] "crs"                   "Cs"                    "Cs_QCFlag"             "Day"                  
#  [37] "Day_QCFlag"            "Ddd"                   "Ddd_QCFlag"            "Diag_7500"            
#  [41] "Diag_7500_QCFlag"      "Diag_CSAT"             "Diag_CSAT_QCFlag"      "Diag_IRGA"            
#  [45] "Diag_IRGA_QCFlag"      "Diag_SONIC"            "Diag_SONIC_QCFlag"     "dTs"                  
#  [49] "dTs_QCFlag"            "e"                     "e_QCFlag"              "esat"                 
#  [53] "esat_QCFlag"           "eta"                   "eta_QCFlag"            "Fa"                   
#  [57] "Fa_QCFlag"             "Fc"                    "Fc_PFP"                "Fc_PFP_QCFlag"        
#  [61] "Fc_QCFlag"             "Fc_single"             "Fc_single_QCFlag"      "Fe"                   
#  [65] "Fe_PFP"                "Fe_PFP_QCFlag"         "Fe_QCFlag"             "Fe_raw"               
#  [69] "Fe_raw_QCFlag"         "Fg"                    "Fg_8cma"               "Fg_8cma_QCFlag"       
#  [73] "Fg_8cmb"               "Fg_8cmb_QCFlag"        "Fg_Av"                 "Fg_Av_QCFlag"         
#  [77] "Fg_QCFlag"             "Fh"                    "Fh_PFP"                "Fh_PFP_QCFlag"        
#  [81] "Fh_QCFlag"             "Fhv"                   "Fhv_QCFlag"            "Fld"                  
#  [85] "Fld_QCFlag"            "Flu"                   "Flu_QCFlag"            "Fm"                   
#  [89] "Fm_PFP"                "Fm_PFP_QCFlag"         "Fm_QCFlag"             "Fn"                   
#  [93] "Fn_KZ"                 "Fn_KZ_QCFlag"          "Fn_NR"                 "Fn_NR_QCFlag"         
#  [97] "Fn_QCFlag"             "Fsd"                   "Fsd_QCFlag"            "Fsd_syn"              
# [101] "Fsd_syn_QCFlag"        "Fsu"                   "Fsu_QCFlag"            "H2O"                  
# [105] "H2O_QCFlag"            "Hdh"                   "Hdh_QCFlag"            "Hour"                 
# [109] "Hour_QCFlag"           "L"                     "L_QCFlag"              "Lv"                   
# [113] "Lv_QCFlag"             "Minute"                "Minute_QCFlag"         "Month"                
# [117] "Month_QCFlag"          "Precip"                "Precip_QCFlag"         "ps"                   
# [121] "ps_QCFlag"             "q"                     "q_QCFlag"              "RH"                   
# [125] "RH_QCFlag"             "RhoCp"                 "RhoCp_QCFlag"          "rhod"                 
# [129] "rhod_QCFlag"           "rhom"                  "rhom_QCFlag"           "rhow"                 
# [133] "rhow_QCFlag"           "S"                     "S_QCFlag"              "Second"               
# [137] "Second_QCFlag"         "SHD"                   "SHD_QCFlag"            "solar_altitude"       
# [141] "solar_altitude_QCFlag" "Sws"                   "Sws_50cm"              "Sws_50cm_QCFlag"      
# [145] "Sws_5cm"               "Sws_5cm_QCFlag"        "Sws_QCFlag"            "Ta"                   
# [149] "Ta_CSAT"               "Ta_CSAT_QCFlag"        "Ta_HMP_21m"            "Ta_HMP_21m_QCFlag"    
# [153] "Ta_HMP_2m"             "Ta_HMP_2m_QCFlag"      "Ta_QCFlag"             "theta"                
# [157] "theta_QCFlag"          "Tpanel"                "Tpanel_QCFlag"         "Ts"                   
# [161] "Ts_8cma"               "Ts_8cma_QCFlag"        "Ts_QCFlag"             "Tv_CSAT"              
# [165] "Tv_CSAT_QCFlag"        "u"                     "u_QCFlag"              "ustar"                
# [169] "ustar_PFP"             "ustar_PFP_QCFlag"      "ustar_QCFlag"          "uu"                   
# [173] "uu_QCFlag"             "uv"                    "uv_QCFlag"             "uw"                   
# [177] "uw_QCFlag"             "Ux"                    "Ux_QCFlag"             "Ux_Sd"                
# [181] "Ux_Sd_QCFlag"          "UxA"                   "UxA_QCFlag"            "UxC"                  
# [185] "UxC_QCFlag"            "UxT"                   "UxT_QCFlag"            "UxUx"                 
# [189] "UxUx_QCFlag"           "UxUy"                  "UxUy_QCFlag"           "UxUz"                 
# [193] "UxUz_QCFlag"           "Uy"                    "Uy_QCFlag"             "Uy_Sd"                
# [197] "Uy_Sd_QCFlag"          "UyA"                   "UyA_QCFlag"            "UyC"                  
# [201] "UyC_QCFlag"            "UyT"                   "UyT_QCFlag"            "UyUy"                 
# [205] "UyUy_QCFlag"           "UyUz"                  "UyUz_QCFlag"           "Uz"                   
# [209] "Uz_QCFlag"             "Uz_Sd"                 "Uz_Sd_QCFlag"          "UzA"                  
# [213] "UzA_QCFlag"            "UzC"                   "UzC_QCFlag"            "UzT"                  
# [217] "UzT_QCFlag"            "UzUz"                  "UzUz_QCFlag"           "v"                    
# [221] "v_QCFlag"              "Vbat"                  "Vbat_QCFlag"           "VPD"                  
# [225] "VPD_QCFlag"            "vv"                    "vv_QCFlag"             "vw"                   
# [229] "vw_QCFlag"             "w"                     "w_QCFlag"              "wA"                   
# [233] "wA_QCFlag"             "wC"                    "wC_QCFlag"             "Wd"                   
# [237] "Wd_CSAT"               "Wd_CSAT_QCFlag"        "Wd_QCFlag"             "Ws"                   
# [241] "Ws_CSAT"               "Ws_CSAT_QCFlag"        "Ws_QCFlag"             "wT"                   
# [245] "wT_QCFlag"             "ww"                    "ww_QCFlag"             "xlDateTime"           
# [249] "xlDateTime_QCFlag"     "Year"                  "Year_QCFlag"


这里读取的是未经过插值的L3通量数据,有缺值。如果要分析水碳通量的年月日变化特征,需要进行插值。

插值的方法可以参考,澳洲通量数据的处理方法简介:

http://ozewex.org/ozfluxqc-flux-data-processing-tool/


代码原文下载链接:

read_nc.R




https://blog.sciencenet.cn/blog-526092-1128042.html

上一篇:叶子飘光合光响应新方程资料分享
下一篇:USE R: 使用MODIStsp程序包下载MODIS产品
收藏 IP: 219.128.110.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-11-23 13:11

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部