diff --git a/bin/postprocessing/extractLineData.py b/bin/postprocessing/extractLineData.py new file mode 100644 index 0000000000000000000000000000000000000000..57f6fc4f8c45635ef8d7e34db9c33fa885c11cb9 --- /dev/null +++ b/bin/postprocessing/extractLineData.py @@ -0,0 +1,67 @@ +import argparse +import csv +import sys +import os + +# parse arguments +parser = argparse.ArgumentParser( + prog='pvpython ' + sys.argv[0], + description='Extract data from the paraview plotOverLine filter.' +) +parser = argparse.ArgumentParser() +parser.add_argument('-i', '--inputDirectory', help="Directory in which the .vtu are located") +parser.add_argument('-f', '--files', nargs='+', required=True, help="vtu files to be processed") +parser.add_argument('-o', '--outputDirectory', help="Directory to which the data files are written") +parser.add_argument('-p1', '--point1', type=float, nargs=3, required=True, help='Coordinates of the first point (in 3D)') +parser.add_argument('-p2', '--point2', type=float, nargs=3, required=True, help='Coordinates of the second point (in 3D)') +parser.add_argument('-r', '--resolution', type=int, default=1000, help='Resolution of the line (number of data points written to data file)') +parser.add_argument('-v', '--verbosity', type=int, default=2, help='Verbosity of the output. 1 = print progress. 2 = print data columns') +args = vars(parser.parse_args()) + +from paraview.simple import * + +# import locations +inDirectory = args['inputDirectory'] +outDirectory = args['outputDirectory'] +if not inDirectory == '': + inDirectory += '/' +if not outDirectory == '': + outDirectory += '/' + if not os.path.exists(outDirectory): + os.makedirs(outDirectory) + +# loop over all vtk files +counter = 1 +for curFile in args['files']: + # print progress to command line + fileWithoutPath = os.path.basename(curFile) + basename = os.path.splitext(fileWithoutPath)[0] + if args['verbosity'] == 1: + print("Processing file ({}/{}): {}".format(counter, len(args['files']), fileWithoutPath)) + counter += 1 + + # load vtk file + vtkFile = XMLUnstructuredGridReader(FileName=inDirectory+curFile) + SetActiveSource(vtkFile) + + # apply and configure PlotOverLine filter + plotOverLine = PlotOverLine(Source="High Resolution Line Source") + plotOverLine.Source.Resolution = args['resolution'] + plotOverLine.Source.Point1 = args['point1'] + plotOverLine.Source.Point2 = args['point2'] + + # write output to csv writer + csvFile = outDirectory + basename + '.csv' + writer = CreateWriter(csvFile, plotOverLine) + writer.UpdatePipeline() + + # print the parameters and the column numbers + if args['verbosity'] == 2: + with open(csvFile) as f: + print csvFile + reader = csv.reader(f) + paramList = list(reader) + paramCounter=1 + for param in paramList[0]: + print "%-2i %s" % (paramCounter, param) + paramCounter += 1 diff --git a/bin/postprocessing/extractPointDataOverTime.py b/bin/postprocessing/extractPointDataOverTime.py new file mode 100644 index 0000000000000000000000000000000000000000..1acd1043d06ad3eba67da021be58ee66874ff450 --- /dev/null +++ b/bin/postprocessing/extractPointDataOverTime.py @@ -0,0 +1,86 @@ +import argparse +import csv +import fileinput +import os +import sys + +# parse arguments +parser = argparse.ArgumentParser( + prog='pvpython ' + sys.argv[0], + description='Extract data from the paraview probeLocation and plotOverTime filters.' +) +parser.add_argument('-i', '--inputDirectory', help="Directory in which the pvd file is located") +parser.add_argument('-f', '--files', nargs='+', required=True, help="pvd files to be processed") +parser.add_argument('-o', '--outputDirectory', help="Directory to which the .csv files are written") +parser.add_argument('-p', '--point', type=float, nargs=3, required=True, help='Coordinates of the probed point (in 3D)') +parser.add_argument('-v', '--verbosity', type=int, default=2, help='Verbosity of the output. 1 = print progress. 2 = print data columns') +args = vars(parser.parse_args()) + +from paraview.simple import * + +# import locations +inDirectory = args['inputDirectory'] +outDirectory = args['outputDirectory'] +if not inDirectory == '': + inDirectory += '/' +if not outDirectory == '': + outDirectory += '/' + if not os.path.exists(outDirectory): + os.makedirs(outDirectory) + +# loop over all pvd files +counter = 1 +for curFile in args['files']: + # print progress to command line + fileWithoutPath = os.path.basename(curFile) + basename = os.path.splitext(fileWithoutPath)[0] + if args['verbosity'] == 1: + print("Processing file ({}/{}): {}".format(counter, len(args['files']), inDirectory+curFile)) + counter += 1 + + # load pvd file + pvdFile = PVDReader(FileName=inDirectory+curFile) + + # Extract Point and Probe at a location + selectionSource = IDSelectionSource( ContainingCells=0, InsideOut=False, FieldType='POINT', IDs=0 ) + ExtractSelection = ExtractSelection(Selection=selectionSource, Input=pvdFile) + ExtractSelection.UpdatePipeline() + selectionData = servermanager.Fetch(ExtractSelection) + + probeLocation = ProbeLocation() + probeLocation.Input = pvdFile + pointSource = probeLocation.ProbeType + pointSource.Center.SetData(args['point']) + probeLocation.UpdatePipeline() + + # Parse the extracted source and plot over time + selectionSourceprobeLocationation = IDSelectionSource( ContainingCells=0, InsideOut=False, FieldType='POINT', IDs=[0, 0] ) + plotSelectionOverTime = PlotSelectionOverTime(OnlyReportSelectionStatistics=False) + plotSelectionOverTime.Selection = selectionSourceprobeLocationation + plotSelectionOverTime.Input = probeLocation + + # write output to csv writer + csvFile = outDirectory + basename + '.csv' + writer = CreateWriter(csvFile, plotSelectionOverTime) + writer.UpdatePipeline() + + # print the parameters and the column numbers + if args['verbosity'] == 2: + with open(outDirectory + basename + '0.csv') as file: + print outDirectory + basename + '.csv' + reader = csv.reader(file) + paramList = list(reader) + paramCounter=1 + for param in paramList[0]: + print "%-2i %s" % (paramCounter, param) + paramCounter += 1 + + # create a proper csv file with semicolons as separators + f = open(outDirectory + basename + '0.csv', 'r') + filedata = f.read() + f.close() + os.remove(outDirectory + basename + '0.csv') + newdata = filedata.replace(',', ';') + f = open(csvFile,'w') + f.write(newdata) + f.close()