爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 26099|回复: 19

[讨论] 关于如何读取某边界范围以及某段时间的NC数据的问题。

[复制链接]
回帖奖励 28 金钱 回复本帖可获得 1 金钱奖励! 每人限 3 次

新浪微博达人勋

发表于 2016-4-4 18:41:14 | 显示全部楼层 |阅读模式

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

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

x
是这样的,我又一个19750101到19991231的日平均气温NC数据,我想读取某一个流域范围的某个时间段数据,流域范围的经纬度已经知道了,但是现在不知道如何截取在读取nc数据时截取范围,以及不知道如何截取时间段。
我现在只会读取所有点的某一天的数据,或者是某一点所有天的数据,比如这是我之前读取所有点在某一天的数据代码:
ncdisp('tas_day_ACCESS1-0_historical_r1i1p1_19750101-19991231.nc')
tas=ncread('tas_day_ACCESS1-0_historical_r1i1p1_19750101-19991231.nc','tas');
lon=ncread('tas_day_ACCESS1-0_historical_r1i1p1_19750101-19991231.nc','lon');
lat=ncread('tas_day_ACCESS1-0_historical_r1i1p1_19750101-19991231.nc','lat');
[lat1 lon1]=meshgrid(lat,lon);
tas1=tas(:,:,1);

我现在想读的是黑河流域范围,并且我如果想要的是黑河流域19900101到19991231的数据改如何操作呢?
哪位大侠帮忙解解惑吧。
正在看二爷的那个汇总帖子里关于nc数据部分的帖子,感觉还是不太懂。

黑河流域

黑河流域
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2016-4-4 18:59:08 | 显示全部楼层

回帖奖励 +1 金钱

首先你确定下流域经纬度的大致范围,然后根据你读取数据的lan和lon的起止和间隔,确定读取的经纬度起始点和步数,然后你参考 http://bbs.06climate.com/forum.php?mod=viewthread&tid=27175 这个帖子的内容即可。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2016-4-4 21:59:35 | 显示全部楼层

回帖奖励 +1 金钱

确定黑河流域的经纬度,因为范围比较小,可以设置step=0.01,
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2016-4-5 08:57:42 | 显示全部楼层

回帖奖励 +1 金钱

天坑一地坑 发表于 2016-4-4 21:59
确定黑河流域的经纬度,因为范围比较小,可以设置step=0.01,

我也在处理nc数据~~~也是不知道怎么提取某个范围内的数据~~~~听不懂你说的意思~~~
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2016-4-6 10:10:59 | 显示全部楼层

回帖奖励 +1 金钱

很简单,请楼主先把ncdisp的结果发出来一下,让我看一下时间变量的定义。一般定位时间得用datenum函数
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2016-4-6 11:01:18 | 显示全部楼层
子达 发表于 2016-4-6 10:10
很简单,请楼主先把ncdisp的结果发出来一下,让我看一下时间变量的定义。一般定位时间得用datenum函数

你好,是这样的,我现在按照一个网友的思路做的,能够读出我想要的边界范围的数据了,但是在截取时间段的时候我是通过将工作表中确定了边界范围的数据复制到Excel中,然后删掉不要的年份的数据。这样感觉确实繁琐。
读取边界范围数据代码如下:
tasdata  = ncread('tas_Amon_bcc-csm1-1_historical_r1i1p1_185001-201212.nc','tas'); %读取降水资料
timedata  = ncread('tas_Amon_bcc-csm1-1_historical_r1i1p1_185001-201212.nc','time'); %读取时间
londata  = ncread('tas_Amon_bcc-csm1-1_historical_r1i1p1_185001-201212.nc','lon'); %读取经度
latdata  = ncread('tas_Amon_bcc-csm1-1_historical_r1i1p1_185001-201212.nc','lat'); %读取纬度
tasdata=permute(tasdata, [2 1 3]);
[xx,yy,zz]=meshgrid(londata,latdata,timedata);
[xi,yi,zi]=meshgrid(98:2:102,38:2:42,timedata);
vi=interp3(xx,yy,zz,tasdata,xi,yi,zi);

这个nc文件的属性信息
Source:
           E:\Work\tas_Amon_bcc-csm1-1_historical_r1i1p1_185001-201212.nc
Format:
           classic
Global Attributes:
           institution           = 'Beijing Climate Center(BCC),China Meteorological Administration,China'
           institute_id          = 'BCC'
           experiment_id         = 'historical'
           source                = 'bcc-csm1-1:atmosphere:  BCC_AGCM2.1 (T42L26); land: BCC_AVIM1.0;ocean: MOM4_L40 (tripolar, 1 lon x (1-1/3) lat, L40);sea ice: SIS (tripolar,1 lon x (1-1/3) lat)'
           model_id              = 'bcc-csm1-1'
           forcing               = 'Nat Ant GHG SD Oz Sl Vl SS Ds BC OC'
           parent_experiment_id  = 'piControl'
           parent_experiment_rip = 'r1i1p1'
           branch_time           = 470
           contact               = 'Dr. Tongwen Wu (twwu@cma.gov.cn)'
           history               = 'Output from monthly mean data 2011-06-15T08:55:23Z CMOR rewrote data to comply with CF standards and CMIP5 requirements.'
           comment               = 'The experiment starts from piControl run at year 470. RCP8.5 scenario forcing data are used beyond year 2005.'
           initialization_method = 1
           physics_version       = 1
           tracking_id           = '2ccf4c16-f21b-42f4-80d1-0dd0f131e922'
           product               = 'output'
           experiment            = 'historical'
           frequency             = 'mon'
           creation_date         = '2011-06-15T08:55:23Z'
           Conventions           = 'CF-1.4'
           project_id            = 'CMIP5'
           table_id              = 'Table Amon (11 April 2011) 1cfdc7322cf2f4a32614826fab42c1ab'
           title                 = 'bcc-csm1-1 model output prepared for CMIP5 historical'
           parent_experiment     = 'pre-industrial control'
           modeling_realm        = 'atmos'
           realization           = 1
           cmor_version          = '2.5.6'
Dimensions:
           time = 1956  (UNLIMITED)
           lat  = 64
           lon  = 128
           bnds = 2
Variables:
    time     
           Size:       1956x1
           Dimensions: time
           Datatype:   double
           Attributes:
                       bounds        = 'time_bnds'
                       units         = 'days since 1850-01-01'
                       calendar      = 'noleap'
                       axis          = 'T'
                       long_name     = 'time'
                       standard_name = 'time'
    time_bnds
           Size:       2x1956
           Dimensions: bnds,time
           Datatype:   double
    lat      
           Size:       64x1
           Dimensions: lat
           Datatype:   double
           Attributes:
                       bounds        = 'lat_bnds'
                       units         = 'degrees_north'
                       axis          = 'Y'
                       long_name     = 'latitude'
                       standard_name = 'latitude'
    lat_bnds
           Size:       2x64
           Dimensions: bnds,lat
           Datatype:   double
    lon      
           Size:       128x1
           Dimensions: lon
           Datatype:   double
           Attributes:
                       bounds        = 'lon_bnds'
                       units         = 'degrees_east'
                       axis          = 'X'
                       long_name     = 'longitude'
                       standard_name = 'longitude'
    lon_bnds
           Size:       2x128
           Dimensions: bnds,lon
           Datatype:   double
    height   
           Size:       1x1
           Dimensions:
           Datatype:   double
           Attributes:
                       units         = 'm'
                       axis          = 'Z'
                       positive      = 'up'
                       long_name     = 'height'
                       standard_name = 'height'
    tas      
           Size:       128x64x1956
           Dimensions: lon,lat,time
           Datatype:   single
           Attributes:
                       standard_name    = 'air_temperature'
                       long_name        = 'Near-Surface Air Temperature'
                       units            = 'K'
                       original_name    = 'TREFHT'
                       cell_methods     = 'time: mean (interval: 20 mintues)'
                       cell_measures    = 'area: areacella'
                       history          = '2011-06-15T08:55:23Z altered by CMOR: Treated scalar dimension: 'height'.'
                       coordinates      = 'height'
                       missing_value    = 1.000000020040877e+20
                       _FillValue       = 1.000000020040877e+20
                       associated_files = 'baseURL: http://cmip-pcmdi.llnl.gov/CMIP5/dataLocation gridspecFile: gridspec_atmos_fx_bcc-csm1-1_historical_r0i0p0.nc areacella: areacella_fx_bcc-csm1-1_historical_r0i0p0.nc'

我现在想的是截取1960年1月到2012年12月的数据。
麻烦你给看一下
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2016-4-6 11:02:38 | 显示全部楼层
子达 发表于 2016-4-6 10:10
很简单,请楼主先把ncdisp的结果发出来一下,让我看一下时间变量的定义。一般定位时间得用datenum函数

你好,是这样的,我现在按照一个网友的思路做的,能够读出我想要的边界范围的数据了,但是在截取时间段的时候我是通过将工作表中确定了边界范围的数据复制到Excel中,然后删掉不要的年份的数据。这样感觉确实繁琐。
读取边界范围数据代码如下:
tasdata  = ncread('tas_Amon_bcc-csm1-1_historical_r1i1p1_185001-201212.nc','tas'); %读取降水资料
timedata  = ncread('tas_Amon_bcc-csm1-1_historical_r1i1p1_185001-201212.nc','time'); %读取时间
londata  = ncread('tas_Amon_bcc-csm1-1_historical_r1i1p1_185001-201212.nc','lon'); %读取经度
latdata  = ncread('tas_Amon_bcc-csm1-1_historical_r1i1p1_185001-201212.nc','lat'); %读取纬度
tasdata=permute(tasdata, [2 1 3]);
[xx,yy,zz]=meshgrid(londata,latdata,timedata);
[xi,yi,zi]=meshgrid(98:2:102,38:2:42,timedata);
vi=interp3(xx,yy,zz,tasdata,xi,yi,zi);

这个nc文件的时间变量属性信息:
Variables:
    time     
           Size:       1956x1
           Dimensions: time
           Datatype:   double
           Attributes:
                       bounds        = 'time_bnds'
                       units         = 'days since 1850-01-01'
                       calendar      = 'noleap'
                       axis          = 'T'
                       long_name     = 'time'
                       standard_name = 'time'
    time_bnds
           Size:       2x1956
           Dimensions: bnds,time
           Datatype:   double

我现在想的是截取1960年1月到2012年12月的数据。
麻烦你给看一下
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2016-4-6 11:02:53 | 显示全部楼层
子达 发表于 2016-4-6 10:10
很简单,请楼主先把ncdisp的结果发出来一下,让我看一下时间变量的定义。一般定位时间得用datenum函数

你好,是这样的,我现在按照一个网友的思路做的,能够读出我想要的边界范围的数据了,但是在截取时间段的时候我是通过将工作表中确定了边界范围的数据复制到Excel中,然后删掉不要的年份的数据。这样感觉确实繁琐。
读取边界范围数据代码如下:
tasdata  = ncread('tas_Amon_bcc-csm1-1_historical_r1i1p1_185001-201212.nc','tas'); %读取降水资料
timedata  = ncread('tas_Amon_bcc-csm1-1_historical_r1i1p1_185001-201212.nc','time'); %读取时间
londata  = ncread('tas_Amon_bcc-csm1-1_historical_r1i1p1_185001-201212.nc','lon'); %读取经度
latdata  = ncread('tas_Amon_bcc-csm1-1_historical_r1i1p1_185001-201212.nc','lat'); %读取纬度
tasdata=permute(tasdata, [2 1 3]);
[xx,yy,zz]=meshgrid(londata,latdata,timedata);
[xi,yi,zi]=meshgrid(98:2:102,38:2:42,timedata);
vi=interp3(xx,yy,zz,tasdata,xi,yi,zi);

这个nc文件的时间变量属性信息:
Variables:
    time     
           Size:       1956x1
           Dimensions: time
           Datatype:   double
           Attributes:
                       bounds        = 'time_bnds'
                       units         = 'days since 1850-01-01'
                       calendar      = 'noleap'
                       axis          = 'T'
                       long_name     = 'time'
                       standard_name = 'time'
    time_bnds
           Size:       2x1956
           Dimensions: bnds,time
           Datatype:   double

我现在想的是截取1960年1月到2012年12月的数据。
麻烦你给看一下
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2016-4-6 18:41:01 | 显示全部楼层

回帖奖励 +1 金钱

本帖最后由 子达 于 2016-4-6 18:47 编辑

air_temperature= ncread('tas_Amon_bcc-csm1-1_historical_r1i1p1_185001-201212.nc','tas',[1,1,1321],[128,64,636]);因为我不知道你这个地图范围是怎么定义的,所以我把整个地图区域的1960.1—2012.12的气温都给你读出来。1321即为起始月份1960.1的位置,636为1960.1-2012.12的月份总数,也就是说从1960.1开始之后到2012.12这636个月的数据全部都读出来。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2016-8-12 13:21:32 | 显示全部楼层

回帖奖励 +1 金钱

根据楼上的方法成功得到所需数据 感谢感谢
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

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

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

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