From 84f1639e59bfea015b40bab6d9c89716dd25e02c Mon Sep 17 00:00:00 2001 From: Marcel Paffrath Date: Fri, 30 Oct 2015 11:56:45 +0100 Subject: [PATCH] added transformation to vgrids vtk with relative values using vgrids.in and vgridsref.in from FMTOMO --- pylot/core/active/fmtomo2vtk.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/pylot/core/active/fmtomo2vtk.py b/pylot/core/active/fmtomo2vtk.py index 95b90705..63990852 100644 --- a/pylot/core/active/fmtomo2vtk.py +++ b/pylot/core/active/fmtomo2vtk.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- import numpy as np -def vgrids2VTK(inputfile = 'vgrids.in', outputfile = 'vgrids.vtk'): +def vgrids2VTK(inputfile = 'vgrids.in', outputfile = 'vgrids.vtk', absOrRel = 'abs', inputfileref = 'vgridsref.in'): ''' Generate a vtk-file readable by e.g. paraview from FMTOMO output vgrids.in ''' @@ -19,6 +19,8 @@ def vgrids2VTK(inputfile = 'vgrids.in', outputfile = 'vgrids.vtk'): nTheta = int(vglines[1].split()[1]) nPhi = int(vglines[1].split()[2]) + print('readNumberOf Points: Awaiting %d grid points in %s' + %(nR*nTheta*nPhi, filename)) fin.close() return nR, nTheta, nPhi @@ -95,9 +97,24 @@ def vgrids2VTK(inputfile = 'vgrids.in', outputfile = 'vgrids.vtk'): outfile.writelines('LOOKUP_TABLE default\n') # write velocity - print("Writing velocity values to VTK file...") - for velocity in vel: - outfile.writelines('%10f\n' %velocity) + if absOrRel == 'abs': + print("Writing velocity values to VTK file...") + for velocity in vel: + outfile.writelines('%10f\n' %velocity) + elif absOrRel == 'rel': + velref = readVelocity(inputfileref) + if not len(velref) == len(vel): + print('ERROR: Number of gridpoints mismatch for %s and %s'%(inputfile, inputfileref)) + return + velrel = [vel - velref for vel, velref in zip(vel, velref)] + nR_ref, nTheta_ref, nPhi_ref = readNumberOfPoints(inputfileref) + if not nR_ref == nR and nTheta_ref == nTheta and nPhi_ref == nPhi: + print('ERROR: Dimension mismatch of grids %s and %s'%(inputfile, inputfileref)) + return + print("Writing velocity values to VTK file...") + for velocity in velrel: + outfile.writelines('%10f\n' %velocity) + print('Pertubations: min: %s, max: %s'%(min(velrel), max(velrel))) outfile.close() print("Wrote velocity grid for %d points to file: %s" %(nPoints, outputfile))