Author Topic: Batch data export  (Read 843 times)

florian

  • Posts: 7
    • View Profile
Batch data export
« on: May 08, 2014, 10:32:05 am »
A batch export option would be very nice. If one could select the timesteps 1,5,10 etc and then export heads of the first slice as shp.
An input window "Go to timestep xy" would be nice as well.

Björn Kaiser

  • Posts: 435
    • View Profile
Re: Batch data export
« Reply #1 on: June 12, 2015, 04:56:25 pm »
Sorry to open up an old thread once again. The capability of using Python has been introduced with the recent FEFLOW patch. You may use Python scripting to do exactly the task you are looking for.

I made a quick example (without exception handling etc.) which nicely illustrates a similar workflow. The script does the following:
  • Simulate all fem files sequentially, which are stored within the folder femdata and write results into corresponding dac files within the folder results.
  • Create a point shape file for each simulation run within the folder import+export. The number of point features corresponds to the number of points per slice.
  • After each time-step, a column in the attribute table is created. The name of the column is the respective time-step. The added column is filled with computed heads of the first slice.
Only few modifications are required to have the features you are looking for. Here is the example, which also highlights the coupling with GIS:


import sys, os

sys.path.append('c:\\program files\\wasy\\feflow 6.2\\bin32')

import ifm, arcpy

# Get current working directory
dir=os.getcwd()

# pick fem-files and give names for the dac-files and shp-files
for file in os.listdir(dir+'\\femdata'):
    if file.endswith(".fem"):
        FEM_FILE=dir+'\\femdata\\'+file
        DAC_FILE=dir+'\\results\\'+file.replace('.fem', '.dac')
        SHP_FILE=dir+'\\import+export\\'+file.replace('.fem', '.shp')

        doc = ifm.loadDocument(FEM_FILE)

        ndm = doc.getNumberOfDimensions()
        if ndm==2:
            print 'Script works for 3D models only! Skip 2D model.'
            continue

        print "Run " + FEM_FILE

# Get XY-values from FE-mesh and create point-shp
        pt = arcpy.Point()
        ptGeoms = []

        for node in range(0, doc.getNumberOfNodesPerSlice()):
            pt.X = (doc.getOriginX(node)+doc.getX_d(node))
            pt.Y = (doc.getOriginY(node)+doc.getY_d(node))
            ptGeoms.append(arcpy.PointGeometry(pt))

        arcpy.CopyFeatures_management(ptGeoms, SHP_FILE)

# Make columns in attribute table and fill columns with heads computed at the 1st slice
        def postTimeStep(doc):
            col_name = "t_"+str(round(doc.getAbsoluteSimulationTime(),6))
            print >> sys.stderr, doc.getAbsoluteSimulationTime()
            arcpy.AddField_management(SHP_FILE, col_name, "DOUBLE", "", "", "", "", "")

            heads=[]
            for node in range(0, doc.getNumberOfNodesPerSlice()):
                heads.append(doc.getResultsFlowHeadValue(node))

            const_head = []
            i=0
            cur = arcpy.UpdateCursor(SHP_FILE)
            for row in cur:
                const_col_name = col_name.replace('.', '_')
                const_head=heads
                i = i + 1
                row.setValue(const_col_name, const_head)
                cur.updateRow(row)

        doc = ifm.loadDocument(FEM_FILE)
        if (not(isinstance(doc, ifm.IfmPyWrapper))):
            print >> sys.stderr, 'Failed to load FEM:' + FEM_FILE, sys.exit(-1)

        doc.startSimulator(DAC_FILE, 0)
        doc.stopSimulator()

Björn Kaiser

  • Posts: 435
    • View Profile
Re: Batch data export
« Reply #2 on: June 12, 2015, 05:00:58 pm »
The script uses arcpy. Accordingly, an ArcGIS license is required. If ArcGIS is not available the script can be adjusted according to free products (e.g. QGIS).

Carlos Rivera

  • Administrator
  • Posts: 84
    • View Profile
Re: Batch data export
« Reply #3 on: June 17, 2015, 12:40:24 pm »
You could simply make right-click on Hydraulic Head and then choose Export Data -> Multiple Time Steps. This option will pop up a list, where you can select the times to export.

Regards,
Carlos
Dr. Carlos A. Rivera Villarreyes
Director Sales Service & Support
DHI WASY

Björn Kaiser

  • Posts: 435
    • View Profile
Re: Batch data export
« Reply #4 on: June 17, 2015, 04:34:12 pm »
Sorry, obviously I misunderstood you. The script is intended to export time-varying data while you compute multiple models sequentially in batch mode. If you refer with batch to the export of time-varying data from a single file use the workflow suggested by Carlos.