爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 5900|回复: 10

ave函数设置

[复制链接]

新浪微博达人勋

发表于 2015-4-2 16:20:12 | 显示全部楼层 |阅读模式
GrADS
系统平台:
问题截图: -
问题概况: 关于ave函数参数设定
我看过提问的智慧: 看过
自己思考时长(天): 2

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

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

x
例如ave(h,t=1,t=10),能否求时间段内任意几个时刻的平均值?不太明白啊
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2015-4-2 17:18:09 | 显示全部楼层
{:eb302:}求帮助,求解答
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-4-2 20:13:36 | 显示全部楼层
ave()

ave(expr, dim1, dim2 <,tinc> <,-b>)

Averages the result of expr over the specified dimension range. If the averaging dimension is time, an optional time increment tincr may be specified.

expr    - any valid GrADS expression
dim1    - the start point for the average
dim2    - the end point for the average
tinc    - optional increment for time averaging
-b      - use exact boundaries
dim1 and dim2 are standard GrADS dimension expressions whose dimensions must match.

Usage Notes

The limits and intervals of the averaging are set according to the grid coordinates of the default file. If dim1 and dim2 are specified in world coordinates, the coordinates are converted to the nearest integer grid coordinates based on the scaling of the default file. See the examples below for further illustration.
The end points are given normal weighting, unless the -b boundary flag is specified. The boundry flag indicates that the average should be taken to the exact boundaries specified by dim1 and dim2, rather than the nearest grid points.
The average is weighted by grid interval to account for non-linear grid spacing. Averages in the latitude dimension are weighted by the difference between the sines of the latitude at the northern and southern edges of the grid box. The edges of the grid box are always defined as being the midpoint between adjacent grid points. To calculate an average without using the latitude weighting, use the mean function.
Examples

For the following examples, the dimension environment is X-Y varying; Z-T are fixed.

Consider the following average, when the default file is file #1:
ave(z.2,t=1,t=10)
We are averaging a variable from file #2, but using the scaling from file #1. File #1 has a time interval of 6 hours, but file #2 has a time interval of 12 hours. The average will thus attempt to access data from file #2 for times that are not available, and an error will ocurr. To avoid this, the default file should be set to file #2: set dfile 2

The average:
ave(z,t=1,t=120,4)
will average only 00Z reports from file #1, since the time increment is 4, which for this file is 24 hours.

If you attempt to take a zonal average as follows:
ave(z,lon=0,lon=360)
the world coordinates will be converted to grid coordinates, here X varying from 1 to 181, and the grid point at longitude 0 (and 360) will be used twice in the average. To have the end points of this average weighted properly, use the -b flag:

ave(z,lon=0,lon=360,-b)
or average using the grid coordinates directly:

ave(z,x=1,x=180)
You can nest averaging operations:
ave(ave(z,x=1,x=180),y=1,y=46)
In this case, to take an areal average. Note that for areal averaging, the aave function is better. See the aave function description.

When nesting averages, the order of the nesting can have a dramatic affect on performance. Keep in mind the ordering of the data in a GrADS file: X varies the fastest, then Y, then Z, then T. When nesting averages, put the faster varying dimension within the inner average:

set lon -90
set lat -90 90
set lev 1000 100
d ave(ave(t,x=1,x=180),t=1,t=20)
This average would be more efficient than, for example:

ave(ave(t,t=1,t=20),x=1,x=180)
although the final numerical result would be the same.

The use of the define command can make certain operations much more efficient. If you want to calculate standard deviation, for example:
sqrt(ave(pow(ave(z,t=1,t=20)-z,2),t=1,t=20))
would be correct, but the inside average would be calculated 20 times. Defining the inside average in advance will be substantially faster:

define zave = ave(z,t=1,t=20)
d sqrt(ave(pow(zave-z,2),t=1,t=20))
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2015-4-2 22:03:39 | 显示全部楼层
river 发表于 2015-4-2 20:13
ave()

ave(expr, dim1, dim2  )

就是初始和结束时刻,不能随意选择一些时刻吗?
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-4-3 15:06:34 | 显示全部楼层
红黑火 发表于 2015-4-2 22:03
就是初始和结束时刻,不能随意选择一些时刻吗?

你说的随意的怎么个随意?求从1时刻到100时刻的平均可以,求从3时刻到100时刻的平均也可以,求从1时刻到50时刻的平均也可以······你想怎么随便?
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2015-4-3 16:15:22 | 显示全部楼层
不好意思,可能我表述的不清楚。我就想问例如求t=2,t=7,t=15,t=27,t=46这几个时刻的平均值能否做到。谢谢
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-4-6 10:13:52 | 显示全部楼层
红黑火 发表于 2015-4-3 16:15
不好意思,可能我表述的不清楚。我就想问例如求t=2,t=7,t=15,t=27,t=46这几个时刻的平均值能否做到。谢 ...

我觉得你就把这几年的数据抠出来,放在另一个数据文件中,然后就可以直接求平均了,不要嫌麻烦嘛
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2015-4-6 14:34:43 | 显示全部楼层
谢谢,之前就是这么做的。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-4-8 08:41:49 | 显示全部楼层
用define命令啊,把想要的时刻抠出来,然后手动平均不久ok了,ave函数没那么强大
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2015-4-8 12:24:24 | 显示全部楼层
星雨 发表于 2015-4-8 08:41
用define命令啊,把想要的时刻抠出来,然后手动平均不久ok了,ave函数没那么强大

谢谢,就这样做的,已解决
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

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

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

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