爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 10996|回复: 17

[分享资料] 【请教】如何在grads中对格点数据四点求平均

[复制链接]
发表于 2013-5-12 23:01:24 | 显示全部楼层 |阅读模式

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

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

x
dset d:\20u.nc
title
undef -9999
dtype netcdf
xdef 140 linear 110.125 0.25
ydef 100 linear 5.125 0.25
zdef 1 linear 0 1
tdef 1 linear 00Z20JUL2006 1mn
vars 1
ua  0  t,y,x  u wind component m/s ascending pass
endvars
这是数据的ctl文件,想针对经纬度4个点求一个平均值。将经纬度放在整数的格点上。不知用循环求平均可不可以。
之前在论坛上搜到了针对经纬度做循环的帖子,说是先循环时间t,然后z,但这个t和z都只有一层,具体到x和y方向上就不知怎么做了。还请教各位前辈,多谢。
用以下类似这种的循环,将循环转到x,y方向上,再用aave求个平均值可以实现吗?
t=1
while(t<=1911)
'set t 't
'set z 1'
'd sst'
t=t+1
endwhile
密码修改失败请联系微信:mofangbao
发表于 2013-5-13 07:18:50 | 显示全部楼层
你是说你要做很多个不同的四个经纬之间的平均?如果是固定的一个经纬度范围,直接用aave就可以,不需要循环
密码修改失败请联系微信:mofangbao
 楼主| 发表于 2013-5-13 11:21:19 | 显示全部楼层

对的,就是把所有数据都4个求平均。本来是0.25*0.25的转成1*1的。帮帮我吧~多谢多谢~
密码修改失败请联系微信:mofangbao
发表于 2013-5-13 12:35:53 | 显示全部楼层
水印嘉薇 发表于 2013-5-13 11:21
对的,就是把所有数据都4个求平均。本来是0.25*0.25的转成1*1的。帮帮我吧~多谢多谢~

该资料的分辨率啊,那你直接用grads的自带函数re()就行了啊。不太清楚怎么用的话,去看官方文档
密码修改失败请联系微信:mofangbao
 楼主| 发表于 2013-5-13 15:49:01 | 显示全部楼层
river 发表于 2013-5-13 12:35
该资料的分辨率啊,那你直接用grads的自带函数re()就行了啊。不太清楚怎么用的话,去看官方文档

请问你说的re()函数指的是reset吗?还是oacres这个函数?我看了下官方文档,没有一个叫re()的函数。还请明示。。。谢谢。
密码修改失败请联系微信:mofangbao
发表于 2013-5-13 16:31:11 | 显示全部楼层
水印嘉薇 发表于 2013-5-13 15:49
请问你说的re()函数指的是reset吗?还是oacres这个函数?我看了下官方文档,没有一个叫re()的函数。还请明 ...

reset是一个命令啊,怎么能说函数。oacres是站点插值函数。我说的是可以改变格点资料分辨率的re()函数。它的具体解释在grads安装完的OpenGrADS\Contents\Resources\Documentation\opengrads\doc\udxt文件夹里
NAME

re.gex - A 2D regridding function for GrADS

SYNOPSIS

Short-hand

re(expr,dlon), while dlon=dlat

re(expr,dlon,dlat,['ig',nyig],['ba'|'bl'|'bs'|'vt',vtmax,vtmin|'ma',min]

re(expr,dlon,gYY,['ig',nyig],['ba'|'bl'|'bs'|'vt',vtmax,vtmin|'ma',min]

Linear Y-mapping

re(expr,nx,'linear',lon,dlon,ny,'linear',lat,dlat, ['ig',nyig],['ba'|'bl'|'bs'|'vt',vtmax,vtmin|'ma',min]

Gaussian Y-mapping

re(expr,nx,'linear',lon,dlon,ny,'gaus',gstart,njog, ['ig',nyig],['ba'|'bl'|'bs'|'vt',vtmax,vtmin|'ma',min]

DESCRIPTION

The regrid function re solves a common problem of transforming horizontal 2-D gridded fields from/to different resolutions/grid types for quantitative intercomparison. For example, a model monthly mean precipitation field on a T126 gaussian grid can be compared to an observed climatology on a 2.5x2.5 grid using re. The function re offers many transform options ranging from simple bilinear interpolation to box averaging with voting. Additional methods can be added to re as needed.

re transforms two-dimensional (2-D) lat/lon GrADS grids from one grid type/resolution to another. The input is any 2-D lat/lon grid defined by the current GrADS lat/lon dimension environment. re handles input grids which are cyclically continuous in longitude and excludes undefined input grid values from participation in the transform. If a valid transform cannot be made (i.e., insufficient defined data points), the output grid is set to undefined. re supports two output grid types: 1) lat/lon with fixed increments; and 2) gaussian. Four transforms are available: 1) box averaging for regridding fine to coarse grids; 2) box averaging with ``voting'' for noncontinuous/index data such, as soil type; 3) bilinear interpolation; and 4) 4-point bessel interpolation.

REQUIRED PARAMETERS

expr:
Any valid GrADS grid expression (e.g., z or ave(z.3(t+0,t=120,1yr)), real number, 'undef' or '-u'.

nx:
The number of points in longitude (integer)

lon:
Beginning longitude (center of the lower left hand corner grid or the grid (1,1)) of the output domain (float)

dlon:
Delta longitude (dlon) or number of gaussian longitudes on the GLOBE (float)

ny:
The number of points in latitude (integer)

lat:
Beginning latitude (center of the lower left hand corner grid or the grid (1,1)) of the output domain (float)

dlat:
Delta latitude (dlat) or the number of gaussian latitudes on the GLOBE (float)

gstart:
The first gaussian grid number. If the data span all latitudes, start would be 1, indicating the southernmost gaussian grid latitude (integer)

njog:
The number of GLOBAL gaussian latitudes on the output grid. (integer)

'linear':
Linear mapping (string)

'gaus':
Gaussian latitide mapping (string)

Note:
All strings are CASE INSENSITIVE.

OPTIONAL PARAMETERS

Input Gaussian Grid:

'ig', nyig:
Input grid is gaussian with nyig being the number of gaussian latitudes (e.g., ig92 for the NMC T62 grid). nyig must be >= 8 and a multiple of four. This parameter is used to invoke a more precise calculation of the boundary between gaussian grid boxes.

Interpolation Method:

'ba'
Box averaging (the default, while regrids to coarse resoultion)

'bl':
Bi-linear interpolation (the default, when regridding to a finer resolution)

'bs':
3rd order Bessel interpolation

'vt', vtmax, vtmin:
Vote interpolation or box averaging with voting. The parameters (vtmax,vtmin) (range: [0-1]) set the fraction of an output grid box that must be covered by defined input grid data for a ``winner'' to be chosen in the election. The default is vtmax=vtmin=1/2.

The parameter vtmin must be the same as vtmax except for three or more candidates. The fraction for two candidates is midway between vtmax and vtmin.

When there is only one candidate, vtmax is the minimum fraction of an output grid point hat must be covered by defined input grid data for a ``winner'' to be chosen in the election.

Specifying vtmax = vtmin = 1 would require that 100% of the output grid box must be covered by a single, unique value from the input grid whereas vtmax = vtmin = 0 would allow a winner to be chosen if ANY candidates where running. The default value of 0.5 means that a simple majority is required to have a winner.

'ma', fraction:
This option applies ONLY to box averaging without voting when the input grid has undefined points. The parameter fraction (range: [0-1]) specifies the minimum area which must be covered with DEFINED data boxes to be considered a valid interpolation. The old regrid v1.0 assumed fraction was 0 or that if ANY input grid boxes contained defined data which intersected the output grid produced a box average. This was clearly too liberal and fraction is now set by default to 50% or that half the output grid box must be covered with defined data to produced a defined output grid point.

EXAMPLES

)
Regrid a global T62 gaussian grid (192x94) to a 2.5 deg lat/lon by box averaging,

   open /reanl1/pilot20/fluxgrb8508.ctl
   set x 1 192
   set y 1 94
   define p25=re(p,144,linear,0,2.5,72,linear,-88.75,2.5,ba)
or set lon 0 360 set lat -90 90 define p25=re(p,2.5,2.5,ba)

or more simply,

   define p25=re(p,2.5)
Note: The lat/lon dimension environment is set using grid coordinates (x,y) to make the input and output grids global. To minimize future graphics/analysis calculations with the regridded field, we use the GrADS define function to store the grid in memory where it can be referenced as any other GrADS grid.

)
Regrid a 4x5 SiB vegetation type to a R15 (48x40) gaussian grid using box averaging with ``voting.'' Require that at least 60% of the output grid box must be covered with a single candidate value from the input grid for an election to occur. Otherwise the output grid box is set to undefined. Relax the one-candidate election requirement to 20% when there are three or more candidates,

  open /export/sgi18/fiorino/data/sib/sib.param.annual.ctl
  set lon 0 360
  set lat -90 90
  define i21=re(index,48,linear,0,7.5,40,gaus,1,40,vt,0.60,0.20)
  set gxout grfill
  d index
  d i21
Note : During candidate selection, undefined input grid points do not contribute to the fraction of the output grid box covered with input grid boxes. The best way to display index type data in GrADS is to use the ``grid fill'' display option (set gxout grfill). GrADS will draw the grid box and color it according to the grid value.

)
Regrid 1x1 Aviation run 500 mb z to 2.5x2.5 grid for the region (-140, 20) to (-40, 70) using bessel interpolation,

  open /export/sgi39/wd22sl/grads/avn/avn.93092800.fcst.ctl
  set lev 500
  set lat -180 180
  set lon -90 90
  d re(z,40,linear,-138.75,2.5,20,linear,21.25,2.5,bs)
or

  set lat 20 70
  set lon -140 -40
  d re(z,40,linear,-138.75,2.5,20,linear,21.25,2.5,bs)
or

  d re(z,2.5,2.5,bs)
Note: The above three regrid commands produce exactly the same results. Box averaging would be more appropriate when regridding to a coarser grid.

)
Regrid 1x1 Aviation run 500 mb z to 2.5x2.5 grid using box averaging and setting the grid to start at a specific lat/lon,

  open /export/sgi39/wd22sl/grads/avn/avn.93092800.fcst.ctl
  set lev 500
  set lat -20 70
  set lon -140 -40
  d re(z,40,linear,-138.75,2.5,20,linear,21.25,2.5,ba)
  set lat 30 50
  set lon -50 50
  d re(z,40,linear,-138.75,2.5,20,linear,21.25,2.5,ba)
Note: The above two regrids produce DIFFERENT results since the input domain does not cover the entire output domain. Missing values will be filled for the uncovered regions.
密码修改失败请联系微信:mofangbao
 楼主| 发表于 2013-5-13 19:21:57 | 显示全部楼层
river 发表于 2013-5-13 16:31
reset是一个命令啊,怎么能说函数。oacres是站点插值函数。我说的是可以改变格点资料分辨率的re()函数。 ...

多谢前辈啊~这么详细。 我试了一下午,又给生成的dat文件写了ctl,可在grads中打开ctl的时候总是说unknown file format,打不开写出来的dat文件,也不知道哪里出问题了哎~我明天再试试吧~
密码修改失败请联系微信:mofangbao
发表于 2013-5-13 19:52:49 | 显示全部楼层
水印嘉薇 发表于 2013-5-13 19:21
多谢前辈啊~这么详细。 我试了一下午,又给生成的dat文件写了ctl,可在grads中打开ctl的时候总是说unknow ...

ctl一定要能如实的描述你生成的数据,不然的话肯定会出错。你再试试吧,我没用过这个函数
密码修改失败请联系微信:mofangbao
 楼主| 发表于 2013-5-14 12:06:59 | 显示全部楼层
river 发表于 2013-5-13 19:52
ctl一定要能如实的描述你生成的数据,不然的话肯定会出错。你再试试吧,我没用过这个函数

恩啊 好的~多谢~
密码修改失败请联系微信:mofangbao
发表于 2013-8-29 16:42:06 | 显示全部楼层
学习了
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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