Follow

Do you have an example of automating Surfer with Python?

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

 

  1. Here is an example that shows how to start Surfer:
    import win32com.client def main(): 
    app = win32com.client.Dispatch("Surfer.Application") 
    plot = app.Documents.Add(1) 
    app.Visible = True main()

  2. Here is an example that shows how to call Surfer:
    Surfer = win32com.client.Dispatch("Surfer.Application") 
    Grid = Surfer.NewGrid() 
    Grid.LoadFile("c:/test/test.grd", HeaderOnly=True) 
    print "BlankValue" + str(Grid.BlankValue) 
    print "NumCols" + str(Grid.NumCols)
    print "NumRows" + str(Grid.NumRows)

  3. Here is an example of how to create and edit a vector map:
    import constants, Dispatch, CastTo 
    import os.path def rgb(r, g, b): return b << 16 / g < 0: 
    level.ShowLabel = True 
    mapframe = plot.Shapes.AddVectorMap(GridFileName1=grid2, GridFileName2=grid3,  CoordSys=constants.srfVecPolar, AngleSys=constants.srfVecAngle) 
    vectormap = CastTo(mapframe.Overlays(1), 'IVectorMap') 
    orange = rgb(255, 102, 0) 
    vectormap.ColorMap.SetNodes(Positions=[0.0, 1.0], Colors=[orange]*2)
    vectormap.ColorScaleMethod = constants.srfVecMagnitude 
    plot.Shapes.SelectAll() 
    plot.Selection.OverlayMaps()
    plot.SaveAs(output) 
    plot.Export(exportfile)

  4. Here is a customer example of how to grid data:
    import glob 
    import datetime 
    
    #call this script like this: 
    #\programs\python25\python.exe krig_data.py 
    
    #get an instance of the Surfer application  
    #Surfer = win32com.client.Dispatch('Surfer.Application') 
    lFile = glob.glob('wl*.csv') 
    for i in range(len(lFile)): 
    
    #the min and max listed below are center coordinates while gdal_grid uses edge 
    
    #coordinates 
    sFilePrefix = lFile[i][:lFile[i].index('.')] 
    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}

     

  5. Here is an example on how to call Surfer and grid your datafile to create a contour map.
    def main():
        app = win32com.client.gencache.EnsureDispatch('Surfer.Application')
        Plot = app.Documents.Add(1)
        app.Visible = True
        DataFile = "C:\Program Files\Golden Software\Surfer 12\Samples\demogrid.dat"
        OutFile = "C:\Program Files\Golden Software\Surfer 12\Samples\outgrid.grd"
        app.GridData (DataFile=DataFile, Algorithm = win32com.client.constants.srfMinCurvature, NumRows=150, NumCols=150, ShowReport=False, OutGrid= OutFile)
            
        #Creates a contour map and assigns the map frame to the variable "MapFrame"
    
        MapFrame = Plot.Shapes.AddContourMap(GridFileName=OutFile)
    
        #Changes the limits and scale of the map
        MapFrame.SetLimits (xMin=0.5, xMax=4.5, yMin=0.5, yMax=3.5)
        MapFrame.xLength=6
        MapFrame.yLength=4
    
        #Declares ContourMap as an Object and assigns the contour map to variable "ContourMap"
        ContourMap = MapFrame.Overlays(1)
        
    main()
    

     

 Updated October 16, 2017

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.