From 4d85e21a5a44832886135ffeed048b2076aa3ab0 Mon Sep 17 00:00:00 2001 From: Craig Warren Date: Wed, 14 Jun 2023 12:08:50 +0100 Subject: [PATCH] Removed .pvd wrapper creation and reading --- gprMax/geometry_outputs.py | 25 ---- toolboxes/Utilities/Paraview/gprMax.py | 175 +++++++++++-------------- 2 files changed, 74 insertions(+), 126 deletions(-) diff --git a/gprMax/geometry_outputs.py b/gprMax/geometry_outputs.py index 11827401..8c2447a4 100644 --- a/gprMax/geometry_outputs.py +++ b/gprMax/geometry_outputs.py @@ -39,27 +39,6 @@ from .utilities.utilities import (get_terminal_width, logger = logging.getLogger(__name__) -def write_vtk_pvd(gvs): - """Writes Paraview data file (.pvd) - provides pointers to a collection of - data files, i.e. GeometryViews. - - Args: - gvs: list of all GeometryViews. - """ - - filename = config.get_model_config().output_file_path - pvd = VtkGroup(str(filename)) - - # Add filenames of all GeometryViews to group - for gv in gvs: - sim_time = 0 - pvd.addFile(str(gv.filename) + gv.vtkfiletype.ext, sim_time, - group = "", part = "0") - pvd.save() - - logger.info(f'Written wrapper for geometry files: {filename.name}.pvd') - - def save_geometry_views(gvs): """Creates and saves geometryviews. @@ -79,10 +58,6 @@ def save_geometry_views(gvs): gv.write_vtk(vtk_data) pbar.update(gv.nbytes) pbar.close() - - # Write a Paraview data file (.pvd) if there is more than one GeometryView - if len(gvs) > 1: - write_vtk_pvd(gvs) logger.info('') diff --git a/toolboxes/Utilities/Paraview/gprMax.py b/toolboxes/Utilities/Paraview/gprMax.py index 3180b332..a72017d4 100644 --- a/toolboxes/Utilities/Paraview/gprMax.py +++ b/toolboxes/Utilities/Paraview/gprMax.py @@ -17,11 +17,9 @@ # along with gprMax. If not, see . import json -import mmap import os -from xml.etree import ElementTree as ET -from paraview.simple import (AppendDatasets, Box, ColorBy, GetActiveSource, +from paraview.simple import (AppendDatasets, Box, GetActiveSource, GetActiveView, GetParaViewVersion, Hide, OpenDataFile, RenameSource, RenderAllViews, SetActiveSource, Show, Threshold) @@ -145,116 +143,91 @@ data = GetActiveSource() Hide(data) -##################################### -# Get filename or list of filenames # -##################################### - # Single .vti or .vtu file -if len(data.FileName) == 1: - files = data.FileName - dirname = os.path.dirname(files[0]) +file = data.FileName +dirname = os.path.dirname(file[0]) -# Multiple .vti or .vtu files referenced in a .pvd file -else: - files = [] - dirname = os.path.dirname(data.FileName) - tree = ET.parse(data.FileName) - root = tree.getroot() - for elem in root: - for subelem in elem.findall('DataSet'): - tmp = os.path.join(dirname, subelem.get('file')) - files.append(tmp) +# Read and display data from file, i.e. materials, sources, receivers, and PMLs +with open(file, 'rb') as f: + # Comments () embedded in line 3 of file + f.readline() + f.readline() + c = f.readline().decode() + # Strip comment tags + c = c[5:-5] + # Model information + c = json.loads(c) + print('\ngprMax version: ' + c['gprMax_version']) + print(file) +################ +# Display data # +################ +pv_view = GetActiveView() +pv_view.AxesGrid.Visibility = 1 # Show Data Axes Grid +pv_data = OpenDataFile(file) +pv_disp = Show(pv_data, pv_view) +pv_src = GetActiveSource() +Hide(pv_src) +src_name = os.path.split(file) +RenameSource(src_name[1]) -################################################################# -# Read and display data from file(s), i.e. materials, sources, # -# receivers, and PMLs # -################################################################# +# Discretisation +dl = c['dx_dy_dz'] +# Number of voxels +nl = c['nx_ny_nz'] -for file in files: - with open(file, 'rb') as f: - # Comments () embedded in line 3 of file - f.readline() - f.readline() - c = f.readline().decode() - # Strip comment tags - c = c[5:-5] - # Model information - c = json.loads(c) - print('\ngprMax version: ' + c['gprMax_version']) - print(file) +# Materials +try: + for i, mat in enumerate(c['Materials']): + threshold = threshold_filt(pv_src, i, i, ['CELLS', 'Material']) + RenameSource(mat, threshold) - ################ - # Display data # - ################ - pv_view = GetActiveView() - pv_view.AxesGrid.Visibility = 1 # Show Data Axes Grid - pv_data = OpenDataFile(file) - pv_disp = Show(pv_data, pv_view) - pv_src = GetActiveSource() - Hide(pv_src) - src_name = os.path.split(file) - RenameSource(src_name[1]) + # Show data in view, except for free_space + if i != 1: + thresholddisplay = Show(threshold, pv_view) + thresholddisplay.ColorArrayName = ['CELLS', 'Material'] + threshold.UpdatePipeline() +except KeyError: + print('No materials to load') - # Discretisation - dl = c['dx_dy_dz'] - # Number of voxels - nl = c['nx_ny_nz'] +# Display any sources +try: + for item in c['Sources']: + pos = item['position'] + name = item['name'] + src = Box(Center=[pos[0] + dl[0]/2, + pos[1] + dl[1]/2, + pos[2] + dl[2]/2], + XLength=dl[0], YLength=dl[1], ZLength=dl[2]) + RenameSource(name, src) + Show(src) +except KeyError: + print('No sources to load') - # Materials - try: - for i, mat in enumerate(c['Materials']): - threshold = threshold_filt(pv_src, i, i, ['CELLS', 'Material']) - RenameSource(mat, threshold) +# Display any receivers +try: + for item in c['Receivers']: + pos = item['position'] + name = item['name'] + rx = Box(Center=[pos[0] + dl[0]/2, + pos[1] + dl[1]/2, + pos[2] + dl[2]/2], + XLength=dl[0], YLength=dl[1], ZLength=dl[2]) + RenameSource(name, rx) + Show(rx) +except KeyError: + print('No receivers to load') - # Show data in view, except for free_space - if i != 1: - thresholddisplay = Show(threshold, pv_view) - thresholddisplay.ColorArrayName = ['CELLS', 'Material'] - threshold.UpdatePipeline() - except KeyError: - print('No materials to load') - - # Display any sources - try: - for item in c['Sources']: - pos = item['position'] - name = item['name'] - src = Box(Center=[pos[0] + dl[0]/2, - pos[1] + dl[1]/2, - pos[2] + dl[2]/2], - XLength=dl[0], YLength=dl[1], ZLength=dl[2]) - RenameSource(name, src) - Show(src) - except KeyError: - print('No sources to load') - - # Display any receivers - try: - for item in c['Receivers']: - pos = item['position'] - name = item['name'] - rx = Box(Center=[pos[0] + dl[0]/2, - pos[1] + dl[1]/2, - pos[2] + dl[2]/2], - XLength=dl[0], YLength=dl[1], ZLength=dl[2]) - RenameSource(name, rx) - Show(rx) - except KeyError: - print('No receivers to load') - - # Display any PMLs - try: - pt = c['PMLthickness'] - display_pmls(pt, dl, nl) - except KeyError: - print('No PMLs to load') +# Display any PMLs +try: + pt = c['PMLthickness'] + display_pmls(pt, dl, nl) +except KeyError: + print('No PMLs to load') RenderAllViews() # Reset view to fit data pv_view.ResetCamera() - -# Show color bar/color legend -# thresholdDisplay.SetScalarBarVisibility(renderview, False)