爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 4084|回复: 8

[脚本编辑] 如何画四个点所在经纬度的平均值

[复制链接]

新浪微博达人勋

发表于 2017-11-17 20:41:48 | 显示全部楼层 |阅读模式

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

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

x
一天四次的资料,四个时次中每个时次都可以画出一个低压中心所在位置的点,我想画这四个点的一个平均位置,
单独画四个都能画出来,平均一下位置就提示我超出了范围,下面是gs中间的部分

'set t 'n                     
'set cmax 0'
'd z'

*******计算第一个低压中心的经纬度
'define loa=minloc(min(z,lat=20,lat=70),lon=90,lon=160)'
'define lab=minloc(min(z,lon=90,lon=160),lat=20,lat=70)-90'

*******提取第一个时次低压中心的经纬度
'd loa'
a=sublin(result,1)
lo=subwrd(a,4)
'd lab'
c=sublin(result,1)
la=subwrd(c,4)

******
'q w2xy 'lo' 'la''
xx1=subwrd(result,3)
yy1=subwrd(result,6)
***转换到图中的xy坐标           
**下一个时次                     
'set t 'n+1
'set cmax 0'
'd z'
'define loa2=minloc(min(z,lat=20,lat=70),lon=90,lon=160)'
'define lab2=minloc(min(z,lon=90,lon=160),lat=20,lat=70)-90'
***提取最低气压的经纬度

'd loa2'
a2=sublin(result,1)
lo2=subwrd(a2,4)
'd lab2'
***下一个时次的提取经度
c2=sublin(result,1)
la2=subwrd(c2,4)
***下一个时次的提取纬度

'q w2xy 'lo2' 'la2''
xx2=subwrd(result,3)
yy2=subwrd(result,6)
***转换到图中的xy坐标           

**下一个时次                     
'set t 'n+2
'set cmax 0'
'd z'
'define loa3=minloc(min(z,lat=20,lat=70),lon=90,lon=160)'
'define lab3=minloc(min(z,lon=90,lon=160),lat=20,lat=70)-90'
***提取最低气压的经纬度

'd loa3'
a3=sublin(result,1)
lo3=subwrd(a3,4)
'd lab3'
***下一个时次的提取经度
c3=sublin(result,1)
la3=subwrd(c3,4)
***下一个时次的提取纬度

'q w2xy 'lo3' 'la3''
xx3=subwrd(result,3)
yy3=subwrd(result,6)
***转换到图中的xy坐标                 

**下一个时次                     
'set t 'n+3
'set cmax 0'
'd z'
'define loa4=minloc(min(z,lat=20,lat=70),lon=90,lon=160)'
'define lab4=minloc(min(z,lon=90,lon=160),lat=20,lat=70)-90'
***提取最低气压的经纬度

'd loa4'
a4=sublin(result,1)
lo4=subwrd(a4,4)
'd lab4'
***下一个时次的提取经度
c4=sublin(result,1)
la4=subwrd(c4,4)
***下一个时次的提取纬度

'q w2xy 'lo4' 'la4''
xx4=subwrd(result,3)
yy4=subwrd(result,6)
***转换到图中的xy坐标               

***************
xx11=(xx1+xx2+xx3+xx4)/4
yy11=(yy1+yy2+yy3+yy4)/4
********第一天四个时次的平均坐标

我不知道最后那个求四个点的平均坐标对不对,那个是我自己写的,
是不是这个不对,导致我画的点超出了正常的范围

请各位路过的大神指教!!



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

新浪微博达人勋

发表于 2017-11-17 23:48:18 | 显示全部楼层
aminlocx()

This function returns the X location of minimum grid value over a spatial domain. The syntax is:

aminlocx(expr, xdim1, xdim2, ydim1, ydim2)

where:

expr    any valid GrADS grid expression
xdim1   starting X or LON dimension expression
xdim2   ending X or LON dimension expression
ydim1   starting Y or LAT dimension expression
ydim2   ending Y or LAT dimension expression
For the X location of the global minimum, a shorthand may be used:

aminlocx(expr, global) or
aminlocx(expr, g)
is the same as
aminlocx(expr, lon=0, lon=360, lat=-90, lat=90)
Usage Notes

This function will only work with GrADS version 2.0.2 or later.
This function is more efficient that using nested minloc and min functions.
Related function aminlocy will return the Y location of the minimum grid value.
Use the amin function to retrieve the minimum value over the grid.
If more than one grid box contains the minimum value, the location returned will be the first one encountered as the grid is scanned. The grid is scanned by rows from south to north, and each row is scanned from west to east.
A similar set of functions exists for finding the maximum over an area: amax, amaxlocx, and amaxlocy.
Examples

Please see the documentation page for amin.


aminlocy()

This function returns the Y location of minimum grid value over a spatial domain. The syntax is:

aminlocy(expr, xdim1, xdim2, ydim1, ydim2)

where:

expr    any valid GrADS grid expression
xdim1   starting X or LON dimension expression
xdim2   ending X or LON dimension expression
ydim1   starting Y or LAT dimension expression
ydim2   ending Y or LAT dimension expression
For the Y location of the global minimum, a shorthand may be used:

aminlocy(expr, global) or
aminlocy(expr, g)
is the same as
aminlocy(expr, lon=0, lon=360, lat=-90, lat=90)
Usage Notes

This function will only work with GrADS version 2.0.2 or later.
This function is more efficient that using nested minloc and min functions.
Related function aminlocx will return the X location of the minimum grid value.
Use the amin function to retrieve the minimum value over the grid.
If more than one grid box contains the minimum value, the location returned will be the first one encountered as the grid is scanned. The grid is scanned by rows from south to north, and each row is scanned from west to east.
A similar set of functions exists for finding the maximum over an area: amax, amaxlocx, and amaxlocy.
Examples

Please see the documentation page for amin.
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2017-11-18 17:32:58 | 显示全部楼层
本帖最后由 爱喝柠檬汁 于 2017-11-18 18:35 编辑

{:eb511:}我知道了!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2017-11-18 17:36:46 | 显示全部楼层
本帖最后由 爱喝柠檬汁 于 2017-11-18 18:54 编辑

改好了!
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

新浪微博达人勋

 楼主| 发表于 2017-11-18 17:38:43 | 显示全部楼层
本帖最后由 爱喝柠檬汁 于 2017-11-18 18:32 编辑

{:eb511:}
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

新浪微博达人勋

 楼主| 发表于 2017-11-18 17:40:13 | 显示全部楼层
本帖最后由 爱喝柠檬汁 于 2017-11-18 18:32 编辑

{:eb511:}
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

新浪微博达人勋

发表于 2017-11-18 23:03:45 | 显示全部楼层

可以上脚本,上图,让大家都学习一下啊
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2017-11-19 16:16:55 | 显示全部楼层
本帖最后由 爱喝柠檬汁 于 2017-11-19 16:29 编辑

'reinit'
'sdfopen E:\grads\era.nc'
'set grads off'
'set mpdset hires'
'set map 15 1 1'
'set lev 500'
'set lat 0 30'
'set lon 10 40'
k=5
while(k<18)
n=k

'set t 'n                     
'set cmax 0'
'd z'

*******计算第一个低压中心的经纬度
'define loa=minloc(min(z,lat=10,lat=20),lon=20,lon=30)'
'define lab=minloc(min(z,lon=20,lon=30),lat=10,lat=20)-90'

*******提取第一个时次低压中心的经纬度

'd loa'
a=sublin(result,1)
lo=subwrd(a,4)
'd lab'
c=sublin(result,1)
la=subwrd(c,4)

******
'q w2xy 'lo' 'la''
xx1=subwrd(result,3)
yy1=subwrd(result,6)
***转换到图中的xy坐标           
**下一个时次                     
'set t 'n+1
'set cmax 0'
'd z'
'define loa2=minloc(min(z,lat=10,lat=20),lon=20,lon=30)'
'define lab2=minloc(min(z,lon=20,lon=30),lat=10,lat=20)-90'***提取最低气压的经纬度

'd loa2'
a2=sublin(result,1)
lo2=subwrd(a2,4)
'd lab2'
***下一个时次的提取经度
c2=sublin(result,1)
la2=subwrd(c2,4)
***下一个时次的提取纬度

'q w2xy 'lo2' 'la2''
xx2=subwrd(result,3)
yy2=subwrd(result,6)
***转换到图中的xy坐标           

**下一个时次                     
'set t 'n+2
'set cmax 0'
'd z'
'define loa3=minloc(min(z,lat=10,lat=20),lon=20,lon=30)'
'define lab3=minloc(min(z,lon=20,lon=30),lat=10,lat=20)-90'
***提取最低气压的经纬度

'd loa3'
a3=sublin(result,1)
lo3=subwrd(a3,4)
'd lab3'
***下一个时次的提取经度
c3=sublin(result,1)
la3=subwrd(c3,4)
***下一个时次的提取纬度

'q w2xy 'lo3' 'la3''
xx3=subwrd(result,3)
yy3=subwrd(result,6)
***转换到图中的xy坐标                 

**下一个时次                     
'set t 'n+3
'set cmax 0'
'd z'
'define loa4=minloc(min(z,lat=10,lat=20),lon=20,lon=30)'
'define lab4=minloc(min(z,lon=20,lon=30),lat=10,lat=20)-90'
***提取最低气压的经纬度

'd loa4'
a4=sublin(result,1)
lo4=subwrd(a4,4)
'd lab4'
***下一个时次的提取经度
c4=sublin(result,1)
la4=subwrd(c4,4)
***下一个时次的提取纬度

'q w2xy 'lo4' 'la4''
xx4=subwrd(result,3)
yy4=subwrd(result,6)
***转换到图中的xy坐标               

***************
xx11=(xx1+xx2+xx3+xx4)/4
yy11=(yy1+yy2+yy3+yy4)/4
********第一天四个时次的平均坐标

***********************************第二天                     
'set t 'n+4                     
'set cmax 0'
'd z'

*******计算第一个低压中心的经纬度
'define loa5=minloc(min(z,lat=10,lat=20),lon=20,lon=30)'
'define lab5=minloc(min(z,lon=20,lon=30),lat=10,lat=20)-90'

*******提取第一个时次低压中心的经纬度

'd loa5'
a5=sublin(result,1)
lo5=subwrd(a5,4)
'd lab5'
c5=sublin(result,1)
la5=subwrd(c5,4)

******
'q w2xy 'lo5' 'la5''
xx5=subwrd(result,3)
yy5=subwrd(result,6)
***转换到图中的xy坐标           
**下一个时次                     
'set t 'n+5
'set cmax 0'
'd z'
'define loa6=minloc(min(z,lat=10,lat=20),lon=20,lon=30)'
'define lab6=minloc(min(z,lon=20,lon=30),lat=10,lat=20)-90'
***提取最低气压的经纬度

'd loa6'
a6=sublin(result,1)
lo6=subwrd(a6,4)
'd lab6'
***下一个时次的提取经度
c6=sublin(result,1)
la6=subwrd(c6,4)
***下一个时次的提取纬度

'q w2xy 'lo6' 'la6''
xx6=subwrd(result,3)
yy6=subwrd(result,6)
***转换到图中的xy坐标           

**下一个时次                     
'set t 'n+6
'set cmax 0'
'd z'
'define loa7=minloc(min(z,lat=10,lat=20),lon=20,lon=30)'
'define lab7=minloc(min(z,lon=20,lon=30),lat=10,lat=20)-90'
***提取最低气压的经纬度

'd loa7'
a7=sublin(result,1)
lo7=subwrd(a7,4)
'd lab7'
***下一个时次的提取经度
c7=sublin(result,1)
la7=subwrd(c7,4)
***下一个时次的提取纬度

'q w2xy 'lo7' 'la7''
xx7=subwrd(result,3)
yy7=subwrd(result,6)
***转换到图中的xy坐标                 

**下一个时次                     
'set t 'n+7
'set cmax 0'
'd z'
'define loa8=minloc(min(z,lat=10,lat=20),lon=20,lon=30)'
'define lab8=minloc(min(z,lon=20,lon=30),lat=10,lat=20)-90'
***提取最低气压的经纬度

'd loa8'
a8=sublin(result,1)
lo8=subwrd(a8,4)
'd lab8'
***下一个时次的提取经度
c8=sublin(result,1)
la8=subwrd(c8,4)
***下一个时次的提取纬度

'q w2xy 'lo8' 'la8''
xx8=subwrd(result,3)
yy8=subwrd(result,6)
***转换到图中的xy坐标               

***************
xx22=(xx5+xx6+xx7+xx8)/4
yy22=(yy5+yy6+yy7+yy8)/4
********第二天四个时次的平均坐标

'draw line 'xx11' 'yy11' 'xx22' 'yy22''
***两个低压中心的连线
'draw mark 3 'xx11' 'yy11' 0.1'
***在每个低压中心标点
'q dim'
ti=sublin(result,5)
time=subwrd(ti,6)
'draw string 'xx11' 'yy11' D'
'draw string 'xx11' 'yy11' 'time''
****标注低压中心时间
k=k+4
endwhile

****最后一个点标注
'draw mark 3 'xx22' 'yy22' 0.1'
'draw string 'xx22' 'yy22' D'
'q dim'
ti=sublin(result,5)
time=subwrd(ti,6)
'draw string 'xx22' 'yy22' 'time''

say over
'printim E:\grads\lujing.png white'
;
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2017-11-19 16:29:14 | 显示全部楼层
楼上是完整的gs,我只改了时间和经纬度,其他没变,大家可以根据需要,改成自己的时间和经纬度
我是根据这个帖子里的gs改的,原版本的在这里
http://bbs.06climate.com/forum.php?mod=viewthread&tid=40365
这个帖子里的是每一个时间出一个点,我的版本是每四个点求一个平均位置,因为我用的是一天四次的资料,我想画出这一天的四个时次的平均位置,然后将连续几天,每天的一个点连接起来
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

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

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

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