请选择 进入手机版 | 继续访问电脑版
爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 6241|回复: 8

[其他] Python+Surfer自动化

[复制链接]

新浪微博达人勋

发表于 2017-12-1 23:51:06 | 显示全部楼层 |阅读模式

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

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

x
文件来自官网,仅供参考

Python Surfer.txt

3.34 KB, 下载次数: 44, 下载积分: 金钱 -5

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

新浪微博达人勋

发表于 2017-12-2 00:39:12 | 显示全部楼层
Surfer都支持python了啊,孤陋寡闻了
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2017-12-2 09:48:57 | 显示全部楼层
我也是第一次听说
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2017-12-2 19:52:17 | 显示全部楼层
多谢分享。
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

新浪微博达人勋

发表于 2017-12-8 09:38:56 | 显示全部楼层
收费不厚道

  1. Surfer can be called from a Python script. Although writing scripts in python are not officially supported, we do have some examples to share.



  2.     Here is an example that shows how to start Surfer:

  3.     import win32com.client def main():
  4.     app = win32com.client.Dispatch("Surfer.Application")
  5.     plot = app.Documents.Add(1)
  6.     app.Visible = True main()

  7.     Here is an example that shows how to call Surfer:

  8.     Surfer = win32com.client.Dispatch("Surfer.Application")
  9.     Grid = Surfer.NewGrid()
  10.     Grid.LoadFile("c:/test/test.grd", HeaderOnly=True)
  11.     print "BlankValue" + str(Grid.BlankValue)
  12.     print "NumCols" + str(Grid.NumCols)
  13.     print "NumRows" + str(Grid.NumRows)

  14.     Here is an example of how to create and edit a vector map:

  15.     import constants, Dispatch, CastTo
  16.     import os.path def rgb(r, g, b): return b << 16 / g < 0:
  17.     level.ShowLabel = True
  18.     mapframe = plot.Shapes.AddVectorMap(GridFileName1=grid2, GridFileName2=grid3,  CoordSys=constants.srfVecPolar, AngleSys=constants.srfVecAngle)
  19.     vectormap = CastTo(mapframe.Overlays(1), 'IVectorMap')
  20.     orange = rgb(255, 102, 0)
  21.     vectormap.ColorMap.SetNodes(Positions=[0.0, 1.0], Colors=[orange]*2)
  22.     vectormap.ColorScaleMethod = constants.srfVecMagnitude
  23.     plot.Shapes.SelectAll()
  24.     plot.Selection.OverlayMaps()
  25.     plot.SaveAs(output)
  26.     plot.Export(exportfile)

  27.     Here is a customer example of how to grid data:

  28.     import glob
  29.     import datetime

  30.     #call this script like this:
  31.     #\programs\python25\python.exe krig_data.py

  32.     #get an instance of the Surfer application  
  33.     #Surfer = win32com.client.Dispatch('Surfer.Application')
  34.     lFile = glob.glob('wl*.csv')
  35.     for i in range(len(lFile)):

  36.     #the min and max listed below are center coordinates while gdal_grid uses edge

  37.     #coordinates
  38.     sFilePrefix = lFile[i][:lFile[i].index('.')]
  39.     Surfer.GridData(DataFile = lFile[i], xCol = 1, yCol = 2, zCol = 3, NumCols = 4133,  NumRows = 3017, xMin = 455355, xMax = 579315, yMin = 1954585, yMax = 2045065,  ShowReport = False, DupMethod = win32com.client.constants.srfDupAvg, OutFmt = win32com.client.constants.srfGridFmtBinary, OutGrid = '%s.grd' %sFilePrefix) print 'finished kriging %s at %s' % (lFile[i], datetim{source}


  40.     Here is an example on how to call Surfer and grid your datafile to create a contour map.

  41.     def main():
  42.         app = win32com.client.gencache.EnsureDispatch('Surfer.Application')
  43.         Plot = app.Documents.Add(1)
  44.         app.Visible = True
  45.         DataFile = "C:\Program Files\Golden Software\Surfer 12\Samples\demogrid.dat"
  46.         OutFile = "C:\Program Files\Golden Software\Surfer 12\Samples\outgrid.grd"
  47.         app.GridData (DataFile=DataFile, Algorithm = win32com.client.constants.srfMinCurvature, NumRows=150, NumCols=150, ShowReport=False, OutGrid= OutFile)

  48.         #Creates a contour map and assigns the map frame to the variable "MapFrame"

  49.         MapFrame = Plot.Shapes.AddContourMap(GridFileName=OutFile)

  50.         #Changes the limits and scale of the map
  51.         MapFrame.SetLimits (xMin=0.5, xMax=4.5, yMin=0.5, yMax=3.5)
  52.         MapFrame.xLength=6
  53.         MapFrame.yLength=4

  54.         #Declares ContourMap as an Object and assigns the contour map to variable "ContourMap"
  55.         ContourMap = MapFrame.Overlays(1)

  56.     main()

复制代码

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

新浪微博达人勋

发表于 2018-1-3 08:57:57 | 显示全部楼层
本帖最后由 xyangtian 于 2018-1-8 11:17 编辑

十分感谢楼主,楼主在那个官网找的。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2018-1-3 09:07:30 | 显示全部楼层
本帖最后由 xyangtian 于 2018-1-8 11:15 编辑

我用的comtypes调用,这个GirdData方法报异常
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2018-1-3 11:59:26 | 显示全部楼层

执行这个GridData方法总是报错啊,
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2018-1-3 11:59:37 | 显示全部楼层

执行这个GridData方法总是报错啊,
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

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

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

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