爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 10548|回复: 17

[其他] 【提问】关于NCL数据读取

[复制链接]

新浪微博达人勋

发表于 2016-5-12 09:53:07 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
小白请教各位NCL大神,读取几个文件中的同样的几个变量,如何做到快速有效?比如:读取1.cdf、2.cdf两个文件中的同一个变量N,我以前都是
a=addfile("1.cdf","r")
b=addfile("2.cdf","r")
N1=a->N
N2=b->N
读取的变量少还好,变量多了以后非常的麻烦,所以想请教各位大神有没有类似循环或者其他NCL函数能够简化这一操作,先谢谢了!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2016-5-12 12:16:01 | 显示全部楼层
addfiles.........
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

新浪微博达人勋

发表于 2016-5-12 12:46:02 | 显示全部楼层
楼上正解,如果读取的数据文件是一个系列的话~~
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2016-5-12 13:01:37 | 显示全部楼层
fils=systemfunc("ls *.nc")
f=addfiles(fils,"r")
ListSetType(f,"join")
PREC=f[:]->PREC
printVarSummary(PREC)
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2016-5-12 14:21:27 | 显示全部楼层
xuebiz 发表于 2016-5-12 12:46
楼上正解,如果读取的数据文件是一个系列的话~~

谢谢!!!!!!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2016-5-12 14:22:02 | 显示全部楼层

有没有具体一点的例子,谢谢!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2016-5-12 14:24:02 | 显示全部楼层
1374203670 发表于 2016-5-12 13:01
fils=systemfunc("ls *.nc")
f=addfiles(fils,"r")
ListSetType(f,"join")

这样就是把所有以nc结尾的文件里的PREC全部读取了是吗?那如果我要分别用每个文件里的PREC作图该怎么操作?谢谢!!!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2016-5-12 14:43:02 | 显示全部楼层
本帖最后由 xuebiz 于 2016-5-12 14:57 编辑

http://www.ncl.ucar.edu/Document ... t-in/addfiles.shtml
---------------------------------------------------------------------------
Prototype

        function addfiles (
                file_path : string,  
                status        : string   
        )

        return_val [1] :  list

------------------------------------------------------------------------------------
Examples

Note: all examples assume NCL version 5.1.0
-----------------------------------------------------------------------------------------
Example 1

Read in a series of netCDF files (here, 5 files each with 12 time steps), and read into memory the four dimensional variable T(ntim,klvl,nlat,mlon), where ntim=12, klvl=5, nlat=48, mlon=96:

   fils = systemfunc ("ls /model/annual*.nc") ; file paths
   f    = addfiles (fils, "r")   

   ListSetType (f, "cat")        ; concatenate (=default)
   T    = f[:]->T                ; read T from all files
   printVarSummary (T)
------------------------------
The printVarSummary procedure yields:

     Variable: T
     Type: float
     Total Size: 5529600 bytes
                 1382400 values
     Number of Dimensions: 4
     Dimensions and sizes:   [time | 60] x [lev 5] x [lat | 48] x [lon | 96]
     Coordinates:
          time: [2349..4143]
          lev: [850..200]
          lat: [-87.15909..87.15909]
          lon: [ 0..356.25]
   Number Of Attributes: 2
     units :       K
     long_name :   temperature

The size of the time dimension is now 60 (=5*12), while the other dimensions remain the same.
------------------------------------------------------------------
Example 2

The "XXX" files have no record dimension. All records are 5 (levels) x 48 (latitudes) x 96 (longitudes). Here we use the "join" option. This adds an extra dimension.

   diri = "/fs/cgd/data0/casguest/CLASS/"   ; input directory
   fils = systemfunc ("ls "+diri+"XXX*.nc") ; file paths
   f    = addfiles (fils, "r")   ; note the "s" of addfile
   ListSetType (f, "join")      
   T    = f[:]->T                ; read T from all files
   printVarSummary (T)
------------------------------
The printVarSummary procedure yields:

   Variable: T
   Type: float
   Total Size:  460800 bytes
                115200 values
   Number of Dimensions: 5
   Dimensions and sizes:   [ncl_join | 5] x [lev | 5] x [lat | 48] x [lon | 96]
   Coordinates:
            lev: [850000..250.]
            lat: [-87.15909..87.15909]
            lon: [ 0..356.25]
   Number Of Attributes: 2
     units :       K
     long_name :   temperature

---------------------------------------------------------------------
Example 3

Generally, when there is a record dimension one uses the "cat" option. In this example, let's assume the five different runs were made for a particular year. Each run was done using, say, different boundary layer parameterizations. Here the time variable is the same for each file and we want to compare the five different cases. The appropriate choice for this case is "join":

   diri = "/fs/cgd/data0/casguest/CLASS/"   ; input directory
   fils = systemfunc ("ls "+diri+"Bound*.nc") ; file paths

   f    = addfiles (fils, "r")   ; note the "s" of addfile

   ListSetType (f, "join")
   T    = f[:]->T                ; read T from all files
   printVarSummary (T)
-------------------------------
The printVarSummary procedure yields:

   Variable: T
   Type: float
   Total Size: 5529600 bytes
               1382400 values
   Number of Dimensions: 5
   Dimensions and sizes:   [ncl_join | 5] x [time | 12] x [lev | 5] x [lat | 48] x [lon | 96]
   Coordinates:
            time: [2349..2683]
            lev: [850..250.]
            lat: [-87.15909..87.15909]
            lon: [ 0..356.25]
   Number Of Attributes: 2
     units :       K
     long_name :   temperature
---------------------------------------------------------------
Example 4

Read in the same series of netCDF files as in example 1, but access only each eighth step of the aggregated time dimension, and latitudes between -40 and +40. Since there are 12 timesteps in each file, two timesteps will be extracted from the first file, one from the second, two from the third, and so forth.

   fils = systemfunc ("ls /model/annual*.nc") ; file paths
   f    = addfiles (fils, "r")   

   ListSetType (f, "cat")       ; concatenate (=default)
   T    = f[:]->T(::8,:,{-40:40},:)     ; read T with a stride of 8
   printVarSummary (T)
---------------------------------------------------
The printVarSummary procedure yields:

     Variable: T
     Type: float
     Total Size: 337920 bytes
                 84480 values
     Number of Dimensions: 4
     Dimensions and sizes:   [time | 8] x [lev 5] x [lat | 22] x [lon | 96]
     Coordinates:
          time: [2349..4052]
          lev: [850..200]
          lat: [-38.94342..38.94342]
          lon: [ 0..356.25]
   Number Of Attributes: 2
     units :       K
     long_name :   temperature
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2016-5-12 14:50:09 | 显示全部楼层
xuebiz 发表于 2016-5-12 14:43
http://www.ncl.ucar.edu/Document ... t-in/addfiles.shtml
------------------------------------------ ...

十分感谢,我还想问一下,一个三维变量,能否做与它x,y轴有夹角的截面图
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2016-5-12 15:12:45 | 显示全部楼层
傻傻听不懂
经纬度+深度OR时间OR???            画非沿着某经度或维度线的截面图?
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表